Top Post from Category Plugin

This is a plugin for WordPress 2.7.  It was developed initially for and has been bundled up and released on

It is basically a sidebar widget that shows the top post from a particular category plus its thumbnail.  The excerpt from the post can be overridden.



  1. Download the plugin from
  2. Unzip the plugin into the /wp-content/plugins directory on your webserver.
  3. Activate the plugin.
  4. In your sidebar, add the ‘Top Post from Category’ widget. You can also add several instances of this widget if you want.
  5. Open the widget options and specify what category ID to pull the top post from.
  6. You can leave the Excerpt blank for the default post excerpt or you can enter text to override that value.


v. 0.3

  • changes the category selector to a drop-down list in the admin
  • is now a multi-widget—allows for multiple instance of the widget in a sidebar showing top posts from different categories

v. 0.2

  • removes the dependency on the excerpt reloaded plugin
  • fixes the “more” tag which used to disappear when you overrode the excerpt

v. 0.1

  • initial release

Please add any questions or suggestions using the comments form below.

73 Responses to “Top Post from Category Plugin”

  1. Anil Says:

    Great plugin!

  2. baron Says:

    hi. Thanks for plugin



  3. Le Favà Says:

    Hi, i like this plugin But i have a problem.
    when i activate the widget on sidebar, it make an error because said that not there are the call of the fuction.

    I have to add some in sidebar.php? Thx

  4. Le Favà Says:

    oh, sorry. I’m Italian so my english isn’t so good. I hope u can understand me.

  5. cjyabraham Says:

    @LeFava: what is the exact error message? And what version of WP are you using?

  6. Le Favà Says:

    I using 2.7 version. Maybe is only my theme that is a little old.

    The error is this:

    Fatal error: Call to undefined function the_excerpt_reloaded() in /home/user2427/public_html/wp-content/plugins/top-post-from-category-widget/top-post-from-category.php on line 60

    I thin that i have only to add on sidebar.php the function that call plugin, but, and this is the really prblem for me php is like a sky without stars.

  7. cjyabraham Says:

    @LeFava: Ah, this is my fault. Right now this plugin uses the excerpt reloaded plugin:

    You’ll need to download that one too and activate it. Then the top post widget should work.

    I should really upload a version of this plugin that doesn’t use the excerpt reloaded. I’ll put it on my list :)

  8. Le Favà Says:

    Perfect, now work. Really thx. I have another question. For add a thumbnail with the plugin, i have to insert that manually? or i need something?

  9. cjyabraham Says:

    @LeFava: the plugin should search your post for an image. If one exists, it will grab the thumbnail version and display it.

  10. Ed Penano Says:

    Great plugin! I wanted to know, does it show only the most recent post published? That seems to be the case for me. Or does it show the top post for any category I choose?

  11. cjyabraham Says:

    @Ed It should show the most recent post from the category you choose. Is this not how it’s working for you?

  12. Ed Penano Says:

    Well, say I change the category to another. It still displays the most recent post. Should I delete and re-install?

  13. cjyabraham Says:

    @Ed: If you change the category to another, it should grab the most recent post from that category. Make sure you click “Save Changes” etc.

    One thing that might be causing a problem, is that the if you explicitly set the excerpt text for the widget, it doesn’t automatically get erased when the category is changed or a new post is posted. So make sure that you erase it. Does this help?

  14. Ed Penano Says:

    I found a solution. Instead of the category name, I put in the numerical category ID.

    I’m glad its workin now! Great Plug-In!

  15. cjyabraham Says:

    @Ed: Cool. I’ve made a note to install a category drop-down picker when I get around to it.

  16. iKeg Says:

    Hi! How can i make this show the three latest posts instead of only one?

  17. cjyabraham Says:

    @iKeg: if you edit this file:

    query for 3 posts instead of 1 and put a loop around the post output that would show you the top three I think.

  18. gourme Says:


    i’m looking for this kind of plugin for over 6 months.

    but i got a problem. can you find a sollution to let widget on sidebar for a more instances ?

    thanks , man !

  19. cjyabraham Says:

    @gourme: I think what you mean is how do you have multiple instances of this sidebar widget. Is that right?

    To do this you’ll need to edit top-post-from-category/top-post-from-category.php around line 138, try adding the lines:
    register_sidebar_widget(array(“Top Post from Category 2″, ‘widgets’), ‘widget_toppostfromcategory’);
    register_widget_control(array(“Top Post from Category 2″, ‘widgets’), ‘widget_toppostfromcategory_control’);

    And now you should have two copies of this widget.

  20. gourme Says:

    Thanks for your answer.

    But there’s a problem. When i try to change the id category of first instance widget, automaticaly is change the id categ. at the second instance. What shoud i do ?

  21. Alex Says:

    Hi Thanx for plugin! wanna ask you – can i use it not only in side bar? for example in main page? i mean use som code?

  22. cjyabraham Says:

    @gourme: I see. Well, I think you could find some sort of hack solution by making two copies of top-post-from-category. Then in top-post-from-category1.php, you’ll have to change all references to toppostfromcategory. So on line 31, instead of this:
    $options = get_option(‘toppostfromcategory’);
    change it to this:
    $options = get_option(‘toppostfromcategory1′);
    Same with lines 91, 95, etc.

    If you just do a find/replace command through the file it should then create a duplicate widget with “1″ appended to all instances of toppostfromcategory. This should then work independently of the other widget instance.

  23. cjyabraham Says:

    @Alex: Sure you could grab some code to show a top post in your main template. If you grab these lines:
    $my_query = new WP_Query(“cat=$category&showposts=1″);

    You’ll be able to show the top post from $category in your main page with:
    < ?php the_title(); ?>

  24. gourme Says:

    hello. i’ve changed all instances of “toppostfromcategory” with “toppostfromcategory1″ . When i try to activate the seccond php file, i get this: ” Cannot redeclare get_the_thumb()
    (previously declared in /home/…/public_html/wp-content/plugins/top-post-from-category1.php:73) in /home/…/public_html/wp-content/plugins/top-post-from-category.php on line 86 ”

    any solutinon?

  25. cjyabraham Says:

    @gourme: delete the whole get_the_thumb() function in the second file

  26. Richard Says:

    Hello, I can’t see any output from this plugin, either on the page or source. It installed ok and I’ve selected a category in the widget, but nothing shows, not even the widgtet title. WP-2.71 default theme

    Any advice please?

  27. Richard Says:

    After some more testing it seems to be a theme related problem. It would be easier if I could hard code the widget into my sidebar ibstad of using a widget. What code can I use for this please?

  28. cjyabraham Says:

    @Richard, I’m not sure what the problem is and why it doesn’t work in your theme. Maybe your theme does not have a widgetized sidebar. You can widgetize your sidebar by following these instructions:

    Alternatively, you can just strip out the code you need and hardcode it into your sidebar. You’ll need the code in the widget_toppostfromcategory() function from top-post-from-category.php. You’ll need to put in values for the options.

  29. Richard Says:

    Thanks for the reply CJ. My theme is a 2.7 widgetised theme and other widgets run
    ok. It’s not a plugin issues as I now have it working when |I use the default theme. I’ll try the hard coding option as you suggest and hope I can get it to work . Thanks.

  30. cjyabraham Says:

    @Richard: Another thing you might want to try is to play around with the order of the widgets in your sidebar. Maybe one of the other widgets is conflicting with it. If you only have this Top Post widget in your sidebar, does it work then?

  31. Richard Says:

    Thanks for the tip CJ. I’ll play around with this today and let you know how I fare

  32. Alex Says:

    Hi, СJ. thanks for an answer. Have another one question. i`m not a guru in php:)) so, wanna ask you. how i can make to show top post from each category, i mean for example, on the mainpage i have to show 3 top post from 3 category:
    Top Post from cat 1 Top Post from cat 2 Top Post from cat 3.
    How i can do it? thanks a lot.

  33. cjyabraham Says:

    Hi @Alex, I gave @gourme some advice on how to do this type of thing (see above). It’s kind of messy but I think you’ll need to make three copies of the plugin and change some of the var names in each. That would be the quickest way.

  34. Alex Says:

    CJ@But the category have some ID, isnt easy to write some code to get the id of cateogory and show the post?

  35. cjyabraham Says:

    @Alex: I’m not sure I understand what you mean.

  36. Lariza Says:

    Hi, thanks for great plugin! I wonder if I can customize it so that it shows, say, 3 most recent posts in some category? And another question, how does it decide the size of the thumbnail, could I modify it somehow?

  37. Chris Abraham Says:

    @Lariza, see above for an answer to your first question.

    You could probably modify the size of the thumbnail in css working with the class “thumbnail”. Otherwise you could edit the markup in top-post-from-category.php:70.

    BTW, I just released a new and improved version of this plugin :)

  38. Lariza Says:

    thanks! sorry to bother you, but my php skills are really lousy – how do I “put a loop around the post output”? I have now put it like this in top-post-from-category.php:

    <a href=”">

    But it’s now showing ALL the posts in every category. I have modified line 46 like this: $my_query = new WP_Query(“cat=$category&showposts=3″);

    What did I do wrong? :P
    :P thanks in advance!

  39. Lariza Says:

    oops, the code vanished. Anyway, I put the beginning of the loop just before div class=post and the ending after

  40. Lariza Says:

    …ahem, after the div closing tag.

  41. Chris Abraham Says:

    @Lariza: I think you’re on the right track. You’ll probably need to put the loop before this line:

    Post your code to and I’ll take a look.

  42. Lariza Says:

    Ok – I did what you suggested and now it’s showing 3 last posts but strangely, after them three times the thumbnail of the latest post (without texts, just the thumbnail and More..-link). I posted the code to Thanks alot, you’re really helpful! :)

  43. Chris Abraham Says:

    @Lariza: I got it working for myself. Copy the following code:

  44. Lariza Says:

    … in here:

  45. Lariza Says:

    THANKS!!! Works perfectly now! :)

  46. Lariza Says:

    Hi again – I might just celebrated to early! :( The problem is now that the widget is somehow conflicting with the other sidebar items, which are not widgets in the dynamic sidebar but hard coded in the home.php. If I put the code calling for the dynamic sidebar right in the beginning of the sidebar, it works fine, but as soon as I put it somewhere else, TPFC disappears. Other widgets (for example basic text widget) don’t behave like this, they show up wherever I have put the dynamic sidebar. Do you have some idea what’s causing this? Sorry to bother you again…

  47. Chris Abraham Says:

    @Lariza: I’m not sure what the problem is here. I’d need to take a look at your code. Post it to pastbin if you want.

  48. Lariza Says:

    Hi Chris, I put the code of my home.php here: Thanks!

  49. Lariza Says:

    ok – I solved it with my non-existent php-skills! :) The problem was somehow caused by the if (is_home()) -condition. I removed it because I’m anyway using this sidebar only in my home page so the plugin doesn’t need to detect where it is… I don’t know exactly why it was like this, but now it’s working for me!

  50. Chris Abraham Says:

    @Lariza: Hmm, ok. Glad that you solved the problem. I’ll keep an eye out for other complications of this is_home() clause next time I’m in the code.

  51. Gert Says:

    I wonder why I only get the plugin to work at my homepage – it won’t show up in the sidebar of a page. ?

  52. Gert Says:

    ok – I removed the if (is_home())


  53. ricland Says:

    Great plugin but,

    The text it displaces runs off the screen as if it it’s not recognizing the width of the sidebar.


    check out my site.

  54. Darco ( Says:

    Great plugin, just what I was looking for! Does any1 know where can I edit the length of the preview text and is it possible not to display one, but two or more latest posts from certain category!

    BTW, the Gert for your post, it helped me alot!

  55. Chris Abraham Says:

    @ricland: is this still an issue for you? I couldn’t find anything about it on your site. Try using for a screenshot.

  56. Chris Abraham Says:

    @Darco: you’d need to edit top-post-from-category.php around line 77 to limit the size of the excerpt that is generated. And for displaying two or more posts, see the comment thread above ending with:

  57. Gina Says:


    I hope you can help. When I add the top post widget to my sidebar and select edit, the widget is deleted from sidebar instead of opening the pop-up box to select the settings.

    The widget remains listed as an “available widget” but does not allow me to “edit.” I’ve tried several times, refreshed the page and logged in and back out again.

    Thank you.

    Best regards,

  58. Chris Abraham Says:

    @Gina: are you using WP2.8? I’m not sure it works in 2.8.

  59. Gina Says:

    Hi Chris,

    No, I’m using 2.7.1.


  60. Chris Abraham Says:

    @Gina: Hmm. That’s weird. I’m not sure what the problem is. Maybe it is conflicting with another widget in your sidebar. As an experiment you could try removing all other widgets and seeing if you still have a problem.

  61. Gina Says:

    I tried but it didn’t fix the problem. Do I need to add code to the sidebar template?

  62. Chris Abraham Says:

    @Gina: Well you need to have a widgetized sidebar. Do other widgets work in your sidebar? Maybe this widget doesn’t work with wp2.7.1. I’ve only ever tested it up to wp 2.7.

  63. Gina Says:

    Yes, I have a widgetized sidebar and the other widgets work. Not sure what the problem is but I thank you for trying to help.

  64. Art Studios Says:

    I really love this plugin

  65. Dennis Says:

    Hi Chris,
    is there a chance or the possibility that the widget shows 5 or more random posts of the whole blog instead the top one of a category and in my wished case only as thumbnails without any text or something?

    Thx in advance and greetings from germany

    Dennis from the Babbel-Net Team

  66. Chris Abraham Says:

    @Dennis: Showing five random posts isn’t how this widget works but it would be easy enough to design a widget that does that.

  67. Dennis Says:

    Hi Chris,
    would you be please so kind and design something like this? Because your widget is the only plugin I found that is very close to the idea I have in mind and I have no clue how to code such widgets.

    Thx in advance

    Dennis from the Babbel-Net Team

  68. Chris Abraham Says:

    @Dennis: I don’t have time at the moment for any freelance work but another WP developer should be able to do this without much trouble.

  69. Thomas Wood Says:

    Great little plugin. It’s interesting because I’ve been looking for a highly customizable plugin that will put a single category feed on the side. There seem to be four of them out there, but none of them are just right. The simplicity of yours makes it close. Thanks for that.

  70. Elias Says:

    Boa tarde, achei esse plugin na internet e eu gostei, achei que seria a solução dos meus problemas, e quase foi, no meu ele pega o post corretamente porém da categoria selecionada, mas não mostra a imagem inserida no post porque será ?

    Eu sou brasileiro, não repara no meu inglês, risos.

    Grato pela atenção

  71. Elias Says:

    Sorry for previous comment in Portuguese …. lol.

    Good afternoon, I found this plugin on the Internet and I liked it, thought it would be the solution to my problems, and almost was, he picks up on my post correctly but the selected category, but does not show the image because it will be inserted in the post?

    I am Brazilian, do not look at my English, lol.

    Thank you for your attention

  72. Paige Says:

    Hi – when I installed this, I thought it would pull up the most popular post in a category, which is what I want, but instead it pulls up the most recent post in a category. Is there a way to tweak this to show the most popular post in a category?

  73. Chris Abraham Says:

    @Paige. How do you define the most popular post? Is it the one with the most comments or views? It’s possible that you could modify this plugin to query for that.

Leave a Reply