Conditional Tags

I took this post from my Frosty Web Designs Blog which I am not posting to anymore. I will be using it strictly as my portfolio site.

So I was browsing around online for some new code. I wanted to change the rollover state of the navigation menu depending on which page you were on. So I did a search for Wordress dynamic class. That let me to Elliot Jay Stocks, where he had an article about dynamic body classes. I wasn’t wanting to change the body class or id of my site, but it was in the right direction.

After reading the article and browsing the comments I saw a link to Conditional Tags on WordPress’ Codex. After searching for the terms I was going to use I had to write the PHP code. I went over to php.net to visit the code for if statements.

I used the following php structured code:

 $b) {
    echo "a is bigger than b";
    $b = $a;
}
?>

To apply the code to my page I inserted;

if (is_page('about')) {

Now where is_page asks the web site if the page that is loaded is the page titled about, then do what ever code it followed, such as:

if (is_page('about')) {
echo "page_item_current";

Now if the page about is loaded inside the browser, echo (write)

class="page_item_current"

So lets see what comes next.

if (is_page('about')) {
echo "page_item_current";
} else {
echo "page_item";
}

So in the final code you will see the first line asking if the current page loaded it about, and telling the page to write (echo) the class page_item_currentBut, if the current page you are on is not the page about, then just write page_item.

The final code will be placed in between the class quotes where ever you need to use Conditional Tags.

my final code:

	
  • ">about me
  • The next step is changing you CSS in your stylesheet to display your current page.

    My CSS code looked like this:

    #menu a:hover {
    background-position: left bottom;
    }
    #menu .page_item_current a {
    background-position: left bottom;
    }