Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

10 Most Wanted Category Hacks and Plugins for WordPress

Last updated on by
Elegant Themes
10 Most Wanted Category Hacks and Plugins for WordPress

In this article we will share the most wanted category hacks and plugins for WordPress which you can use in your themes. These snippets of codes are a lifesaver in many situations when it comes to modifying a theme.

1. Display Certain Categories in a Menu

Display Certain Categories in a Menu

In many cases, users only want to display certain categories in their navigation menu at the top of the page. There are limited spots, that can only be filled by top categories, but if you use the default wp_list_categories code, it will show all categories. This is why this hack below comes in very handy when you want to create a navigation menu and only display certain categories.

<ul class="navmenubar" style="float:left; width:730px;">
<?php wp_list_categories('orderby=name&include=7,9,19,16,1,5,17,23'); ?>
</ul>

Note, you can also change the ‘include’ text to ‘exclude’ and show all categories and exclude those that you don’t want displayed. The numbers displayed in the code are the category IDs. Remember since WordPress shows categories in a list format, you will need to edit the CSS in order to make it work.

2. Display Category in a Dropdown Menu

Display Certain Categories in a Dropdown Menu

Some blogs have a lot of categories which they can’t display in their sidebar. Or some bloggers do not want to take up a lot of space displaying categories. This option allows them to have a select menu, dropdown menu, for categories. See WordPress Codex for details.

<form action="<?php bloginfo('url'); ?>/" method="get">
<?php
$select = wp_dropdown_categories('show_option_none=Select Category&show_count=1&orderby=name&echo=0&selected=6');
$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
echo $select;
?>
<noscript><input type="submit" value="View" /></noscript>
</form>

3. Exclude Certain Categories from Being Displayed in a Loop

Your blog page shows recent posts from all categories. If you want to have a separate page for some reason, or do not want to display certain categories, you can use the following code, and it will exclude a certain category from being displayed in a Loop. Just change the category IDs.

<?php if ( have_posts() ) : query_posts($query_string .'&cat=-13,-26'); while ( have_posts() ) : the_post(); ?>

4. Display the Most Recent Posts from a Specific Category

Display the Most Recent Posts from a Specific Category

This code comes in handy when you want to display posts from a specific category on your homepage, or in your sidebar. A live example of this code can be seen at Balkhis.com. The code below will show 1 post with the excerpt from category 3. You can modify the numbers as you desire.

<?php
query_posts('showposts=1&cat=3');
while(have_posts()) : the_post();
?>
<ul>
<li><h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>

<ul><li><?php the_excerpt(); ?></li>
</ul>
</li>
</ul>
<?php endwhile; ?>

To only show links from the category use the code below:

<?php
query_posts('showposts=1&cat=3');
while(have_posts()) : the_post();
?>
<ul>
<li><h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
</li>
</ul>
<?php endwhile; ?>

5. Exclude a Specific Category from RSS Feeds

Exclude a Specific Category from RSS Feeds

There are certain categories that contain maybe link love and others which most of your users are not interested in. This is the option to satisfy those users. You can exclude a specific category by using a plugin called Advanced Category Excluder, or you can do it manually by using the code below:

http://example.com/feed?cat=-5

To exclude multiple cateogries, just use the ampersand symbol:

http://example.com/feed?cat=-4&cat=-5

If you don’t want to use the plugin and don’t want to do it manually with the link. There is another way which you can use by editing your function.php. Paste the following code in it:

function myFilter($query) {
if ($query-&gt;is_feed) {
$query-&gt;set('cat','-5'); //Don't forget to change the category ID =^o^=
}
return $query;
}

add_filter('pre_get_posts','myFilter');

6. Make a Separate RSS Feed for Each Category

Often times bloggers wonder how to make separate RSS feed for their category. Because sometimes your user only visits your website for the design category, but you have ten other categories that the user is not interested in. This hack will take care of this issue. (Source)

http://www.wpbeginner.com/category/showcase/feed/

All you have to do is add the word feed in front of the category URL, and it will take you to the feed for that specific category.

If you want to display a RSS icon in front of category listings then use the code below:

<?php wp_list_categories('feed_image=http://www.wpbeginner.com/image.gif&feed=XML Feed&optioncount=1&children=0'); ?>

You must make sure to change the URL of the image because this will display RSS icon in front of each category.

7. Assign an Author to a Specific Category

On Blogs that have multiple authors, it is wise to assign authors to specific categories to avoid confusion. This plugin limits the user to publishing into the categories he/she is assigned.

Check out the plugin Userextra

8. Show Post Excerpts on Category Pages

Sometimes in order to prevent duplicate content, and make your category pages easy to browse, it is recommended that you use excerpts instead of displaying full posts. Category pages are indexed like normal blogs are in chronological order, so if you have a post that is 1000 words and 25 images, and you are displaying 5 posts on each page. It will be a hassle for your user to go through category archives. Therefore we suggest you show excerpts instead of full posts on category pages. Then you just direct them to the single post page where full text is written. It also helps pageviews for those who are addicted with stats.

First you would need to open index.php and locate this code:

<?php the_content() ?>

and replace it with:

<?php the_excerpt() ?>

Now when you write posts, just write a custom excerpt to make it more interesting.

9. Show Category Icons

Show Category Icons

Pictures make a site more lively which is a given which is why blogger might want to associate pictures with their category. This plugin lets you associate a specific icon of your choice to a designated category. You can use this plugin to list categories by icon with or without names, and much more.

Download this Plugin

10. Display Category Description in Template

Displaying category description on category pages are considered to be more SEO Friendly. But this is often used when running a modified theme in which you have subcategories within a category. When you have separate category pages customized displaying category description is always a good edition.

This is the description that you type when creating a category in your WordPress admin panel.

Add the following code in your archive.php / category.php whichever one is more appropriate for you:

<?php echo category_description(); ?>


Editorial Staff at WPBeginner is a team of WordPress lovers led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »
  • RW

    Great post. I’m using the code to display recent posts from a specific category. How can I trim the excerpt length and switch from ‘…’ to ‘Read More’ with your code example?

    Thanks,
    Bob

  • RyanSinha

    How to display Posts of a certain category on a Certain page with excerpts.And instead of [...] . the post should display a Continue reading –> . On clicking the continue reading..The post opens and shows the whole content.

  • JulienCsf

    Ho, how to display the categories of an article/post lisiting in a plugin/extension??? not in a theme!!! Please it is very important ;-)

  • http://www.realfreshcreative.com Kayle Simon

    I’m trying to use the show 1 post from a specific category code (though I will want to change it to show 1 excerpt, instead, but I haven’t gotten that far yet..) and I keep getting a parse error that says in the first line of the code, there is an “unexpected ‘%’, expecting ‘)’”.

    I am changing nothing but the category number, so I can’t figure out what is wrong there; are you sure your syntax is correct? I admit I know very little about php, but was SO excited to find this info since it gets close to what I need….

    • http://www.wpbeginner.com Editorial Staff

      We fixed the code, so it should work now.

  • http://www.gfxpark.de Patrick Offczorz

    Thanks for this tips!

  • http://www.niche-blogging-profits.info Rick

    Very useful list. I have bookmarked it and will be referring to it regularly.

  • marujo

    hi. hopw i can show each category in sidebar as a select/dropdown? i have multi categories and subcats in this cats. so, i want to show each cat as a select. and when click on the select/cat open the subcats. when click on subct automatically goes to the page with subcats. it is possible? an e.g:
    category x (select)
    - subcat x1
    - subcat x2 (if i click here, goes to x2 page)
    - subcat x3
    cat y
    - y1
    - y2
    - y3
    can anyone help me? thanks and sorry for my english.

    • http://www.wpbeginner.com Editorial Staff

      You will need an Ajax Category Drop Down

  • http://www.bluecow.se N!cklas

    Show Category Icons – option #2

    Add the below to your themes functions.php
    Edit img/url to your needs

    function add_image($content) {
    $img = “”;
    $searchimages = ‘~]* />~’;
    preg_match_all( $searchimages, $content, $pics );
    $NumberOfPics = count($pics[0]);
    if ( $NumberOfPics == 0 ) {
    if ( in_category(1)) {
    $img = ‘‘;
    }
    if ( in_category(2)) {
    $img = ”;
    }
    }
    $content = $img . $content;
    return $content;
    }
    add_filter(‘the_content’, ‘add_image’);

    There’s also a function in WP to do the check, but it failed for me. Try if you want:

    $attachments = get_children(“post_parent=$post->id&post_type=attachment&post_mime_type=image”);
    if ( empty($attachments) ) { return false;}
    else {
    // you have at least 1 image
    }

  • http://www.designstrike.net Alex

    Very nice list, will be using some of them in my future projects

  • http://stephenpickering.com Stephen Pickering

    Is there a way that I one can create a page that links to a category search. It seems only when I create a page does a new menu tab get created. For instance I want to create a tab called “Poems” and have that link to …../categories/poems, so that everything I’ve categorized as poems shows up.

    • http://www.wpbeginner.com Editorial Staff

      Why create a page to do this? Just make a hyperlink to link to this. Use a design aspect like WPBeginner is using at the top bar and use navigation buttons to link to the categories. If we get what you are saying right. Please correct us, if we don’t, so we can help you in the best way we know.

      • http://stephenpickering.com Stephen Pickering

        But the theme I’m using only has categories listed in a widget. The tabs, other than Home, are all only generated, it seems, when I create a new page and title it, like “About” “Contact” etc. You may see my page: http://stephenpickering.com . I just sort of wish I could label one of those tabs “Poems” and then when someone clicks the tab it would link to http://stephenpickering.com/categories/poems instead of having to create a page and enter links to all those posts.

        • http://www.wpbeginner.com Editorial Staff

          http://txfx.net/code/wordpress/page-links-to/ << Use this plugin to redirect your page to the category URL

        • http://stephenpickering.com Stephen Pickering

          Oh, that is so great. Thank you so much! This is incredibly useful because one could link to a flickr account for example instead of creating your own photo gallery, or if you link to a category it helps bring those posts back to life instead of kind of being buried there in the sidebar. I really appreciate it. How did you find it? Was it hard?

          My best,
          Stephen Pickering
          Little Rock, AR

  • Adam

    Sorry, I’m using 2.8.2

    Any advice much appreciated!

  • Adam

    in regards to point 7, has anybody tried using Userextra? I can’t seem to get it to work, using 2.8. Does anybody know of any other plugins, that auto matically select the category for a user, when they create a post??

    Thanks in advance!!!! Adam

  • http://elegentdesigns.com Ahsan

    Great category hacks. WordPress really gives endless possibilities for theme customization. Listing categories in two columns is another interesting category hack, in addition to the above.

  • http://toscho.de Thomas Scholz

    For tip 2: Don’t submit the form onchange! This breaks your navigation for keyboard users. They’ll never get to the third point.

  • http://www.fazreen.com fazreen

    great hacks.. especially to show the certain category

  • http://www.whitehottruth.com Danielle LaPorte

    hey hey…what about the semi-automation “similar” or “you might also enjoy” type of function for selecting previous posts to link to. it was there in an old version of WP and went away with upgrades. I miss it.

    Great post. Thanks so much.

  • http://clutterlovers.countzeero.eu countzeero

    Great Stuff! I will be referring to this while redesigning my clutterlovers blog… thanks!

  • http://twitter.com/ngassmann ngassmann

    How about when displaying in breadcrumbs a list of categories, excluding the parent category when listing children.

    • http://www.wpbeginner.com Editorial Staff

      You would have to modify the plugin you are using for that.