WordPress Hack | Set Class for Home Page Link

Posted by admin | Filed Under Blog, Cool Stuff  | August 19, 2008

Array

The Problem:

Needed the home page button status to appear active, or in WP terms, as the “current_page_item”. So I need to determine if the page I was on was the home page or not, and if it was, I needed to add a class to it of “current_page_item”.

Solution:

Just a little PHP script does the trick- added into the LI element.

<ul>
<li <?php if (is_home())
echo ‘class=”current_page_item”‘;?>
><a href=”<?php echo get_settings(‘home’); ?>/”>Home</a></li>
<?php wp_list_pages(’sort_column=menu_order&depth=1&title_li=’);?>
</ul>

That’s it!

NOTE: Here is a useful plugin to check out and that I am using with the code above: Current-Page-Bugfix

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Facebook
  • Google
  • BlinkList
  • Blogosphere News
  • E-mail this story to a friend!
  • Fark
  • Furl
  • Reddit
  • StumbleUpon
  • Technorati
  • TwitThis
  • YahooMyWeb

Feedback

0 Votes - Vote Now!!

Trackback URL

Got something to say?