Results 1 to 10 of 27

Threaded View

  1. #11
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Highlight Currently Selected Category Background

    $current_page_base is not an array but a variable holding a string. It doesn't have the full address, only the value of main_page= from the URL. In a category page, $cPath will hold the value of cPath=. You would do a two-stage test, like

    if ($current_page_base == 'index' and $cPath == '18_56')

    Rather than duplicate the whole assignment statement for the current or not-current state, I would use a variable to assign a class tag where appropriate.
    Rearrange the test and assignment using a "ternary operator" to make it compact:
    if a is true? then do b: otherwise do c;

    $current_class = ($current_page_base == 'index' and $cPath == '18_56')? ' class="current"': '';

    Then insert the variable which will be blank unless the cPath matches the current page. Put it right in the <a> for conciseness:

    $define_sidebox_ref[] = '<a href="index.php?main_page=index&amp;cPath=18_56"' . $current_class . '>2011 Code Books & Tabs</a>';
    PHP Code:
        $current_class = ($current_page_base == 'index' and $cPath == '18_56')? ' class="current"''';
        
    $define_sidebox_ref[] = '<a href="index.php?main_page=index&amp;cPath=18_56"' $current_class '>2011 Code Books & Tabs</a>'
    Or compact it even more:
    PHP Code:
        $define_sidebox_ref[] = '<a href="index.php?main_page=index&amp;cPath=18_56"' . (($current_page_base == 'index' and $cPath == '18_56')? ' class="current"''') . '>2011 Code Books & Tabs</a>';
        
    $define_sidebox_ref[] = '<a href="index.php?main_page=index&amp;cPath=18_57"' . (($current_page_base == 'index' and $cPath == '18_57')? ' class="current"''') . '>Solar Photovoltaic Sys.</a>';
        
    $define_sidebox_ref[] = '<a href="index.php?main_page=index&amp;cPath=18_58"' . (($current_page_base == 'index' and $cPath == '18_58')? ' class="current"''') . '>NEC Code Changes Books</a>'
    Last edited by gjh42; 1 Feb 2011 at 05:47 PM.

 

 

Similar Threads

  1. Flyout Menu highlight current category
    By scott_ease in forum Templates, Stylesheets, Page Layout
    Replies: 5
    Last Post: 28 Jul 2012, 06:06 PM
  2. Trying to make new sub category, currently unable.
    By Tamuren in forum Setting Up Categories, Products, Attributes
    Replies: 2
    Last Post: 29 Jul 2011, 06:57 PM
  3. How to add background highlight for product listing?
    By time111 in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 15 Sep 2010, 10:16 PM
  4. how to insert a background colour for a selected category
    By jon22 in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 7 Dec 2009, 04:21 PM
  5. BetterCategories, Selected category
    By esoin in forum All Other Contributions/Addons
    Replies: 1
    Last Post: 7 May 2008, 12:36 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR