+ Reply to Thread
Results 1 to 2 of 2

Thread: Controlling when nav blocks appear based on URL

  1. #1
    Squirrelcart Staff Jamie's Avatar
    Join Date
    May 2002
    Posts
    6,719
    Squirrelcart version
    v3.3.7

    Controlling when nav blocks appear based on URL

    Someone suggested I post some info on this, so here goes.

    Navigation Block records have a Show When field on them. That field can be used to control when the nav block appears. Leave it blank, and it appears on all pages. If you enter a PHP statement that can evaluate to true or false, the nav block only appears when that statement is true. So, if you entered this in that field:

    5 + 5 == 10

    The nav block will always appear. If you enter this:

    5 + 5 == 2

    It will never appear.

    If you have SEO URLs enabled, suppose you have a page setup in Squirrelcart (via these instructions), and the URL to that page is something like this:
    http://www.example.com/content/my-dog-has-fleas

    If you have a navigation block that you want ONLY to appear on that page, put this in the Show When field:
    PHP Code:
    $GLOBALS['path_pieces'][1] == 'my-dog-has-fleas' 
    Now, suppose you have a lot of pages all about dogs on your site and you want the nav block to appear only on those pages. URLs are like this:

    http://www.example.com/content/my-dog-has-fleas
    http://www.example.com/content/your-dog-has-fleas
    http://www.example.com/content/dogs-are-wonderful

    For the above URLs, you could use something like this in the Show When field instead:
    PHP Code:
    preg_match('/dog/',$GLOBALS['path_pieces'][1]) 

    The first parameter passed to the preg_match function is a string containing a regular expression. For more information on how those work, search Google for "regular expressions" and you'll find lots of info.

  2. #2
    Squirrelcart Staff Jamie's Avatar
    Join Date
    May 2002
    Posts
    6,719
    Squirrelcart version
    v3.3.7
    To add to the above....

    If you want to display a navigation block only when a particular category page is being viewed:

    1. Locate the category's record number in the control panel

    2. Put this in the Show When field for the navigation block:
    PHP Code:
    $_GET['crn'] == 180 
    3. Change 180 to the record number of the category

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts