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?

Social Networking

Keep an eye out for me on Twitter

About the Author

Steven Clark Steven Clark - the stand up guy on this site

My name is Steven Clark (aka nortypig) and my passions are business, web development, photography and writing. I have an MBA (Specialisation) and a Bachelor of Computing from the University of Tasmania. I am working as a business management consultant.

Photography

My photography is at Steven Clark Studio and my regular photo blog presents an ongoing stream of latest images at Walk a Mile in my Shoes and I'm working on a long-term photography project called the King Island Project.

Recently Reviewed Books

Site Supporters

Hosted by Brett Drinkwater at Tashosting who is always there at the other end of my every inconvenient question and technical crisis. Brett's local community support for us over the last five years is greatly appreciated.

skip to top of page

Currently Reading

Ansel Adams: The Camera

As the first of three parts of Ansel Adams Photography Series, Ansel Adams: The Camera begins by discussing the idea of visualisation in relation to photography. Ansel Adams is a master of his craft; this series has sat on my backburner for some time. Book 2 in this series is The Negative and it's followed up by The Print. In them Ansel outlines his philosophy of photography rather than trying to lay down a set of rules. This first instalment is a technical book that explains the good old fashion film camera.