skip to content rich footer

stevenclark.com.au

subscibe to the StevenClark.com.au rss feed

Archive for February, 2008

Dynamic Body ID in Wordpress

Sunday, February 24th, 2008

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?

skip to top of page

Currently Reading

Andy Clarke's Transcending CSS: the fine art of web design has been sitting on my bookshelf for several months and I've finally made the time to read it from end to end. My favourite thing about this book from the outset is that it's a designer's book, rather than a technician's manual, for web designers. The artwork and direction in Transcending CSS is enhanced by the attention to detail in the feel and texture of the book itself, the size of it's pages and the feel of the cover in your hands. It's definately a book that affords the act of being read. Looking forward to it.