Free Wordpress Blog Setup

10 Most Wanted Category Hacks and Plugins for WordPress

By Editorial Staff in Tutorials
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(); ?>

Free Wordpress Blog Setup

Comments

22 Responses to “10 Most Wanted Category Hacks and Plugins for WordPress”
  1. ngassmann says:

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

  2. countzeero says:

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

  3. 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.

  4. fazreen says:

    great hacks.. especially to show the certain category

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

  6. Ahsan says:

    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.

  7. Adam says:

    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

  8. Adam says:

    Sorry, I’m using 2.8.2

    Any advice much appreciated!

  9. 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.

    • 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.

  10. Alex says:

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

  11. N!cklas says:

    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
    }

  12. marujo says:

    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.

  13. Rick says:

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

  14. Thanks for this tips!

  15. Kayle Simon says:

    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….

Share Your Opinions

Tell us what you're thinking...
and if you want a pic to show with your comment, then get gravatar!

Please make sure that you have read our Comment Policy.

Due to high volume of request from our readers, we are adding this feature that allows you to stay updated with this post's comments without having to participate in the discussion even though we would love your input as always. Don't worry we hate SPAM just as much as you do, so you will never receive any SPAM messages from our site and that's our promise to you.

Subscribe without commenting

Close Bar