Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 27
  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.

  2. #12
    Join Date
    Jan 2011
    Location
    Ohio
    Posts
    111
    Plugin Contributions
    0

    Default Re: Highlight Currently Selected Category Background

    Quote Originally Posted by gjh42 View Post
    $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>'
    Thank you so much for this! I was able to get it to work using the conditional "if" and duplicating the statements, but I could not get the other methods to work with the class within the variable!

    The class assigned to the main category box is SPAN.box-body, but even created a class called .current to match your example! Still didn't work that way!

    Of course it is more code, but guess I can do it with the conditional "if", as that seems to do the trick!

    Is there another way that I should include class="current"': '' ? I didn't understand the value of the ":" in that statement!

    You've really helped me understand this much better, so thank you very much for that! :)

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

    Default Re: Highlight Currently Selected Category Background

    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"': '';

    This says
    if ($current_page_base == 'index' and $cPath == '18_56') is true, then execute ' class="current"', otherwise execute '' and assign whichever one executes to $current_class.
    If you used the compact form exactly as shown, only changing the cPaths and text, it should give the "current" class where appropriate.


    "I could not get the other methods to work with the class within the variable!"
    How did it not work? Did you get an error or blank screen, or just not a "current" class?

  4. #14
    Join Date
    Jan 2011
    Location
    Ohio
    Posts
    111
    Plugin Contributions
    0

    Default Re: Highlight Currently Selected Category Background

    Ok, makes more sense now, thanks for the details!

    Quote Originally Posted by gjh42 View Post
    How did it not work? Did you get an error or blank screen, or just not a "current" class?
    No error or blank screen. Just did not change to the "current class"!

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

    Default Re: Highlight Currently Selected Category Background

    I am currently seeing your page output cutting off immediately after the categories sidebox. This indicates that there is a PHP error in the ref sidebox file.

  6. #16
    Join Date
    Jan 2011
    Location
    Ohio
    Posts
    111
    Plugin Contributions
    0

    Default Re: Highlight Currently Selected Category Background

    Quote Originally Posted by gjh42 View Post
    I am currently seeing your page output cutting off immediately after the categories sidebox. This indicates that there is a PHP error in the ref sidebox file.
    Should be there now, just trying some variations that didn't work!

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

    Default Re: Highlight Currently Selected Category Background

    I see you getting a .box-body class for the current link now. What rule are you using to try to style it? Which PHP code are you now using?

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

    Default Re: Highlight Currently Selected Category Background

    You're getting a span="" inside the <a class="box-body" tag. That should not be there.

  9. #19
    Join Date
    Jan 2011
    Location
    Ohio
    Posts
    111
    Plugin Contributions
    0

    Default Re: Highlight Currently Selected Category Background

    Quote Originally Posted by gjh42 View Post
    You're getting a span="" inside the <a class="box-body" tag. That should not be there.
    I have the class style set like this...

    SPAN.box-body {
    font-weight: bold;
    background:#a19161;
    color:#413521;
    }

    Using the SPAN tags seems to be the only way to get it to work, but could also be my coding "inexperience"!

    Also, using the span tags seemed to slightly "enlarge" the highlight around the text, and made it look a little better.

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

    Default Re: Highlight Currently Selected Category Background

    You have no spans named .box-body, so that style rule can do nothing. The <a> is named .box-body, so any rules for .box-body{} or a.box-body{} will apply, e.g.

    stylesheet_boxes.css, line 10:
    .box-body {
    padding: 0 6px;
    }

    although that padding is overridden by the padding in

    .box-body ul a {
    background: none repeat scroll 0 0 #413521;
    color: #A19161;
    display: block;
    padding: 8px 3px 6px 35px;
    text-decoration: none;
    text-transform: uppercase;
    }

    which applies to all sidebox list links.

 

 
Page 2 of 3 FirstFirst 123 LastLast

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