Design Shard Now has a Flickr group Join Here to show off your inspirations and work
New Site: Texture Lovers - Free Textures - Inspiration and Tutorials

Highlight Wordpress Category when on a Single Post: Tutorial

@designshard

While making the redesign for this blog I wanted to highlight the category in the navigation when browsing the specified category as well as keeping it highlighted when on the a single post added to that category ( you’ll notice that the navigation is highlighted if your on this page ).

I searched high and low and eventually found a simple plug-in, by adding a small piece of code to the plug-in I could achieve this, follow the steps below and you should beable to get your categories highlighted too when on a single post.

What we want to Achieve:

Add a Home page link to the navigation and highlight current page.

Highlight the current category

Highlight the current category even when on single post

Step 1: Download The Plug-in

Download the plug-in: Here (zip) From: Screenshine

Step 2: Uploading and Editing the Plug-in

1. Upload the plug-in to your Wordpress plug-ins folder.

2. Go to your Wordpress admin panel “Plugins” and “Activate” the plug-in

3. Look at your “Currently Active plugins” and click “Edit” for the “Show Active Category plugin”

4. Scroll down past the copyright information until you find this line of code


if( is_single()) {

change that line of code to look like this

if( is_single() || is_category() ) {

Click “Update file” to save the changes

Step 3: CSS for Highlighting Current Category

Go to your theme CSS file normally called “style.css” and add this line of code below.


.active_category{background-color:#66FF00;}

NOTE: you can style this how you want it will style the current category and the category when on a single post using the plug-in.

Step 4: CSS for Highlighting Current Page

To highlight your “pages” all you have to do is add this line of code to your CSS file, This css class is actually built in to Wordpress


.current_page_item{background-color:#66FF00;}

NOTE: you can style this how you want it will style the current page

Step 5: Add a Home Page Link

You can have a home page link in your navigation take a look at what i have, This hard codes a “Home” link in to your navigation and adds the class “current_page_item” when on your index page, this is styled with css as in Step 4


All Code For The Navigation

So this is a summary of what we’ve done, if you’ve uploaded the plug-in, activated it and edited the code, you can test the code below, copy and paste

Put this in your style.css

.active_category{background-color:#66FF00;}
.current_page_item{background-color:#66FF00;}

Put this in your header.php


All this code adds the home page link, all your pages and then all your categories to your navigation, if you’ve added the CSS styles to you Style sheet these things should be highlighted when on the current page, category and single category post.

Questions

So hopefully you’ll find this useful, let me know if you get it working or get stuck in the comments below ill try my best to help you but obviously i cant help you with the plug-in as I did not make it.

Related Articles

34 Comments

  1. Posted October 12, 2008 |Permalink

    Nice tutorial. I could have used this a couple weeks ago :) Definitely getting stumbled and delicious tagged.

    Mike

  2. Posted October 12, 2008 |Permalink

    STUMBLED!

    Nice navigation effect.

    Geoserv´s lastest blog post..Looking for cheap hosting?

  3. Posted October 12, 2008 |Permalink

    Thanks for tutorial. nice to meet you !

    Danh ba web 2.0´s lastest blog post..Những trang web có trang lỗi 404 (Error 404 Page) thú vị và đẹp mắt nhất !

  4. Posted October 12, 2008 |Permalink

    Thanks for the walk-through for another very handy tool in the Wordpress ensemble.

    Tracey Grady´s lastest blog post..Design checklist: What clients should provide their designer

  5. Posted October 12, 2008 |Permalink

    very nice tutorial:) nice work Max!!!!!!your really doing great.

    Ronald

    NaldzGraphics´s lastest blog post..30 Free High Quality .PSD Files to Grab Part:2

  6. Posted October 13, 2008 |Permalink

    Sorry - why to use a plugin? WordPress give the class current-cat for a active category and this is easy to format with css.
    I think, it is better to use the standard-class of wordpress. This makes easy to share Themes and ideas.
    West regards

    Frank´s lastest blog post..Secure Include Plugin In WordPress

  7. Posted October 13, 2008 |Permalink

    @ Frank - current-cat would only work when you are browsing the actual category, not when you are on the single post page, that is why i could not highlight the category using the built in class, even though it shows when on the category page.

  8. Posted October 13, 2008 |Permalink

    This is a handy snippet, thank you!

  9. Posted October 13, 2008 |Permalink

    Best advice…..on wordpress
    thank you for sharing it with us

  10. Posted October 14, 2008 |Permalink

    Nice work, this is definitely a great enhancement for usability & accessibility.

    Matt´s lastest blog post..Which Layout is for me?

  11. Posted October 14, 2008 |Permalink

    Nice Post. im thinking of doing this in my blog also. thank for sharing

    insic´s lastest blog post..Zend Framework Blog Application Tutorial - Part 6: Introduction to Zend_Form and Authentication with Zend_Auth

  12. Posted October 15, 2008 |Permalink

    Nice post.Thanks..

    iddaa´s lastest blog post..DALE CAVESE

  13. cmsme
    Posted October 22, 2008 |Permalink

    hi, great plugin, and this *almost* fixes a problem i have. however, i need a way to include categorys/posts into a page, so it appears in the admin side site tree. i see your navigation menu lists all the static pages, then follows with category links, which makes me assume you are unable to reorder your navigation in the admin. what i need to do is have menu items in this order PAGE | PAGE | CATEGORY | PAGE . is this possible with your plugin? many thanks

  14. Posted October 29, 2008 |Permalink

    Great tutorial and it works brilliantly.

    Amanda Evans´s latest blog post..Some Excellent Freelance Writing Posts

  15. Posted November 5, 2008 |Permalink

    very interesting, thanks

  16. Posted November 6, 2008 |Permalink

    categorized bloggs makes archiving highly organized. visual details will make it even more organized. when we do blogging for our customers, we always emphasized on categories so our customer can easily appreciate our works.thanks.

  17. Posted November 9, 2008 |Permalink

    Great info - thank you.

  18. Posted November 10, 2008 |Permalink

    Thank you very much… this is what i’ve been looking for

  19. Julia
    Posted November 14, 2008 |Permalink

    Hi
    This is fantastic - thanks. Do you know how this could work so that the single post ancestor category (eg category “news” where a single post in category “press releases” with a parent category of “news”) picks up an active class - this way it would keep my expanding lists expanded when in a single post. Thanks!

  20. Posted November 17, 2008 |Permalink

    This post thanks

    povilli´s latest blog post..Msn Polat Alemdar Avatarları

  21. Posted December 16, 2008 |Permalink

    Thanks for the good tutorial.

  22. kmedia
    Posted February 5, 2009 |Permalink

    I can’t get it to work and desperately would like this feature for a website I’m currently working on (and on future websites).. I can’t imagine that I’m doing anything wrong - does anyone know if this works with WP 2.7? Does anyone know how to fix it for 2.7? It seems like it should already built into WordPress… an essential feature for me. (Using the SuckerFish menu.)
    Thanks!

  23. Posted February 6, 2009 |Permalink

    @Kmedia - i would suspect that suckerfish already has this but im not sure you may want to look on there web site for support, and im not sure if this plugin runs well on wp2.7 either.

  24. kmedia
    Posted February 8, 2009 |Permalink

    Thanks for the reply Design Shard.
    The Suckerfish CSS does define the active state but for some reason WordPress isn’t reading and/or displaying it. The menu works perfectly with my non-WordPress pages.

    Since I’ve seen throughout my exhaustive searches that highlighting the current category was capable up through version 2.6, I have to think that it’s a bug with 2.7.

    I’d also think there needs to be a PHP if statement somewhere around the wp_list_categories HTML checking whether that category is actually active in order to trigger the css change. I just don’t know much about how WordPress works (or PHP programming for that matter).

    This is killing me.. :/

  25. kmedia
    Posted February 9, 2009 |Permalink

    Nevermind.. As stated before, I’m using the SuckerFish menu and WP’s /%category% permalink structure setting.

    For anyone who has struggled with highlighting WordPress’ current category link as much as I have, below is what worked for me (I had to abandon the “wp_list_categories” function in my navigation and use the following instead):

    [sourcecode language='css']
    <a href=”http://www.website.com/category/blog-page”>
    [/sourcecode]

    Repeat the above for each category. It took about 2 days to figure it out.. but I’m now one of the happiest people in the world! And no plugin needed! :)
    Cheers!

  26. kmedia
    Posted February 9, 2009 |Permalink

    Sorry.. the code was stripped from my post.. I thought [sourcecode language='css'] would keep it. :/

  27. Posted February 26, 2009 |Permalink

    Thanks,
    i’m in the middle of redesigning my site and this article helped me in the menu design

  28. Josie
    Posted March 16, 2009 |Permalink

    kmedia, can you figure out a way to share your solution? I’m trying to do this in Wordpress 2.7 and it’s killing me too…

  29. Posted March 23, 2009 |Permalink

    Hey, this is a great post. Now I know how to optimize my site. Thanks for sharing how to find dofollow blogs! :D Greatly appreciated. In return, if you need any assistance in article submission, let me know! I do not want to spam my url here, so contact me personal at my personal email: josephwhenry@gmail.com

  30. ed
    Posted March 31, 2009 |Permalink

    Fantastic, very useful, thanks a lot

  31. Posted May 21, 2009 |Permalink

    How can I add the class to the li instead of the a?

  32. Posted May 29, 2009 |Permalink

    Just to bump this topic up to the author, how can I add the class to the li instead of the a?

  33. Posted May 29, 2009 |Permalink

    @Russel - you should have a class current-cat on the li ? you may not need the plugin, check your source code when on a category page etc, you may want to ask at http://wordpress.org/support/ the support forums , as i wont have time to look in to this at the moment, sorry.

  34. Posted June 1, 2009 |Permalink

    Fair enough, thanks for getting back to me! I did just style the a in the end, it was just to keep all my styling the same :)

    No problem though, thanks very much!

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*
Psd to Xhtml & Css

Print Sponsors


  • Discount printing company, printing service in australia

Comments