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&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&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&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&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&cPath=18_58"' . (($current_page_base == 'index' and $cPath == '18_58')? ' class="current"': '') . '>NEC Code Changes Books</a>';
Re: Highlight Currently Selected Category Background
Quote:
Originally Posted by
gjh42
$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&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&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&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&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&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! :)
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?
Re: Highlight Currently Selected Category Background
Ok, makes more sense now, thanks for the details!
Quote:
Originally Posted by
gjh42
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"!
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.
Re: Highlight Currently Selected Category Background
Quote:
Originally Posted by
gjh42
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! :unsure:
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?
Re: Highlight Currently Selected Category Background
You're getting a span="" inside the <a class="box-body" tag. That should not be there.
Re: Highlight Currently Selected Category Background
Quote:
Originally Posted by
gjh42
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"! :blush:
Also, using the span tags seemed to slightly "enlarge" the highlight around the text, and made it look a little better.
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.