Dynamic Body ID in Wordpress
As Elliot Jay Stocks is throwing a tidbit of Wordpress tutorial out there today on creating dynamic body IDs and Classes it seems appropriate to follow the bandwagon. In short it depends a little on what you are out to achieve I suppose. My example is the recent Hunter Island Press redesign.
<?php if ((!is_page())) { ?>
<body id=”News”>
<?php } elseif ((is_page(’Home’)) || (is_page(’Studio’)) || (is_page(’Support’)) || (is_page(’About’)) || (is_page(’Contact’)))
{ ?>
<body id=”<?php the_title(); ?>”>
<?php } else { ?>
<body>
<?php } ?>
What this snippet does in English is it says - if this isn’t a page (which would mean its a part of the news section - blog, archive, single, search) then the body id will always be News. This allows for me to keep the News tab highlighted in the horizontal navigation bar. Else if the page is Home, Studio, Support, About or Contact (which are other members of the horizontal navigation bar) then the body id will use the page title and that tab remains highlighted on the navigation bar. Otherwise if its any of the other pages (like the ones in the content rich footer) just use a plain old body element.
One thing about using PHP in your WordPress templates is the power of skinning a cat whichever way you need to on the day. Simply understanding the available Wordpress Conditionals puts some gusto into your possiblities. What was the last way you skun that dynamic body id in Wordpress?






