skip to content rich footer

stevenclark.com.au

subscibe to the StevenClark.com.au rss feed

Archive for the 'wordpress' Category

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

Mental Models by Indi Young (cover)Developing software from the user's perspective as opposed the organisational one is a critical area we need to work on as designers. I'm reading Mental Models by Indi Young, a book about understanding users' reasons for doing things and one system for understanding and designing for those reasons.

It's important to understand that when people visit your website they bring with them their own world view, motivations, experience and expectations. And, by working with those factors, we can improve our game significantly by providing them with what they want and need.