Posts by Tag WordPress Plugin, provides sidebar widgets which can be used to display posts from a specific set of tags in the sidebar.
The Plugin caches the posts of each widget separately, and issues database queries only when needed. This will reduce the amount of database queries involved for each page load and will therefore be light on your server.
Download
You can download the Plugin as a zip file from the WordPress Plugin repository.
Installation
Extract the zip file and just drop the contents in the wp-content/plugins/ directory of your WordPress installation and then activate the Plugin from Plugins page. You should see a new widget called “Tag Posts” in the widgets pages, which you can drag and drop in the sidebar of your theme.
Features
Posts By Tag Plugin provides a sidebar widget which can be configured to display posts from a set of tags in the sidebar. You can have multiple widgets with different set of tags configured for each one of them.
Each widget allows you to choose
- The set of tags whose posts should be displayed
- The number of posts to be displayed.
- Option to enable post excerpts to be displayed with post titles.
- Option to display post thumbnail if present.
- Option to specify the sort order for posts
Screenshot

Template Tag
The Plugin also supports the following template tag which can be used to display the posts in any part of the theme.
posts_by_tag($tags, $number, $excerpt = false, $thumbnail = false, $order_by = “date”, $order = “desc”, $author = false);
- $tags (string) – set of comma seperated tags
- $number (number) – number of posts to display
- $excerpt (bool) – To display post excerpts or not
- $thumbnail (bool) – To display post thumbnails or not
- $order_by (date,title) – Whether to order by date or by title.
- $order (asc,desc) – To change the order in which the posts are displayed.
- $author(bool) – To display author name or not
Shortcode
You can also include the shortcode, to display the posts from the set of tags
[posts-by-tag tags = "tag1, tag2" number = "5" excerpt = "true" thumbnail = "false" order_by = "date" order = "desc" author = "false"][/posts-by-tag]
All the parameters that are accepted by the template tag can also be used in the shortcode
Translation
- Swedish (Thanks Gunnar Lindberg Årneby)
- Turkish (Thanks Yakup Gövler)
- Belorussian (Thanks FatCow)
- German (Thanks Renate)
- Dutch (Thanks Rene)
The pot file is available with the Plugin. If you are willing to do translation for the Plugin, use the pot file to create the .po files for your language and let me know. I will add it to the Plugin after giving credit to you.
Feedback
If you have any comments or if you want to report any bugs, please leave a comment below or contact me.
Stay updated
I would be posting updates about this Plugin in my blog and in Twitter. If you want to be informed when new version of this Plugin is released, then you can either subscribe to this blog’s RSS feed or follow me in Twitter.
Changelog
- 2009-07-26 – v0.1 – Initial Release
- 2009-08-02 – v0.2 – Added Template function and Swedish translation.
- 2009-08-14 – v0.3 – Improved cache performance and added Turkish translation.
- 2009-09-16 – v0.4 – Added support for sorting the posts (Thanks to Michael http://mfields.org/).
- 2010-01-02 – v0.5 – Removed JavaScript from unwanted admin pages and added Belorussian translation.
- 2010-03-18 – v0.6 – Added an option to hide author name.
- 2010-04-16 – v0.7 – Fixed an issue in showing the number of posts.
- 2010-05-08 – v0.8 – Added support for shortcode and sorting by title.
- 2010-06-18 – v0.9 – Fixed an issue with the order by option.
- 2010-06-19 – v1.0 – Fixed issue with shortcode.
- 2010-06-23 – v1.1 – Fixed issue with shortcode, which was not fixed properly in 1.0.
- 2010-06-25 – v1.2 – Fixed issue with shortcode, which was not fixed properly in 1.0 and 1.1.
- 2010-07-12 – v1.3 – Fixed some inconsistency in documentation and code.
- 2010-08-02 – v1.4 – Added German translations.
- 2010-08-26 – v1.5 – Added Dutch translations and fixed typos.
Works great, thank you…
@Baron,
Nice to know that you like the Pluign
This is real nice but do you think you could do one for categories too?
@Yuna,
There is a Plugin called Category Posts which does the same for categories.
Does it support custom taxonomies too? It would be nice if this plugin can also support template code too so that we can show the posts whereever we want.
@Navjot,
The Plugin don’t support custom taxonomies (yet
). I have added support for template tags in the latest version of the Plugin.
hey, firstly, great work on the plugin! I am just wondering if there is a php template for the widget, thanks.
@Hercules,
I have added a template tag in the latest version of the Plugin. Check out the readme file to find out how to use it.
Hey, there’s a slight bug (or maybe it’s my version of WP), but i keep getting this when I try to activate the plugin:
Fatal error: Class ‘WP_Widget’ not found in /home/content/j/a/w/jawatech001/html/LIQUIDASSETSTV/wp-content/plugins/posts-by-tag/posts-by-tag.php on line 69
@DrDrinx,
What is the version of WordPress you are using? The Plugin works in WordPress 2.8+ only.
nice plugin. i am sure a lot of wordpress user is waiting a plugin like that.
but… in wordpress 2.8.3. it doesnt show thumbnail. And it is very important.
and there should be also someting: we could make excerpt word limit .-) why Not:-)
@Şahin Çimi, the plugin uses ‘post_thumbnail’ special fields of your posts. So if you add thumbnails has different names to your posts, the plugin won’t display it. Edit the plugin’s file, find ‘post_thumbnail’ and change as you use, for example ‘thumbnail’.
Dear Sudar,
I translated your plugin to Turkish. You can download here and you can read my post about your plugin here.
Thanks for your plugin.
@Yakup,
Thanks for the translation. I will include it in the next update.
Yakup Kardes olmadi..
bak calisan bir ornek var:
<div class="post “>
<a hr
bunu bu eklentiye nasil entegre edicez. seninkinide indirdim. olmadi.
tesekkurler.
Cool plugin! I have been wanting to add a ‘featured posts’ menu to my site for a while now.
@Richard,
Nice to know that my Plugin was useful to you.
Hello… Love your widget. I use it twice in my right hand sidebar and it seems to work fine except that the Title on the second occurrence is different than the first occurrence.
The first one is: Recent Family Related
The second one is: Recent Dance Related Posts <!– the font is always smaller that the first
I moved them around and it seems that the first occurrence leaves the system in a state that forces the change in the title?
The page source llooks like this:
Recent Family Related
Recent Dance Related Posts
Hello… Love your widget. I use it twice in my right hand sidebar and it seems to work fine except that the Title on the second occurrence is different than the first occurrence.
The first one is: Recent Family Related
The second one is: Recent Dance Related Posts <!– the font is always smaller that the first
I moved them around and it seems that the first occurrence leaves the system in a state that forces the change in the title?
The page source llooks like this:
Recent Family RelatedRecent Dance Related Posts
Hello… Love your widget. I use it twice in my right hand sidebar and it seems to work fine except that the Title on the second occurrence is different than the first occurrence.
The first one is: Recent Family Related
The second one is: Recent Dance Related Posts <!– the font is always smaller that the first
I moved them around and it seems that the first occurrence leaves the system in a state that forces the change in the title?
@Paul,
I assume, you are using my Post By Tag WordPress Plugin. Let me know the url of your blog and I will have a look at it. I guess it is mostly a theme issue.
Hey! thanks for adding the template stuff! Only problem is the plugin doesn’t work on my wordpress 2.6.3 lol….. any chance it get it to work somehow? it triggers a fatal error when I try to activate it. thx again!
@Hercules,
The Plugin is compatible only from 2.7. If it’s possible try to upgrade WordPress. The older version has some security issues also.
@Sudar
Unfortunately, my theme only supports up to 2.6.3 I believe, I just tried to install 2.7 locally but the theme is all broken…..any chance I can get this plugin to work on 2.6.3? Thanks a lot for your help!!!
nevermind
i think i might be able to get it to work on 2.7 – thx
sorry, just another question…..
Is it possible to display posts in a list by using the template? for some reason i’m not able to do this on single pages (where I’m hoping to display the links)…. any ideas? thanks again!!
@Hercules,
Right now it is not possible
Hi – fabulous plugin. One question: I see the code that calls for the author of the post. I’d like to remove that since not necessary for our blog. But, don’t know code well enough to know how to extract it. Would appreciate your help. Thanks.
Right now the only way to remove author name is to change the code. Give me a day or two, I will release an update to the Plugin with an option to remove the author name.
I have released version 0.6 of the Plugin which has an option to hide the author name.
Installing this on WP 2.9.2 triggers Fatal error: Call to undefined function. Had to uninstall via FTP just to get back into WP dashboard.
What version of PHP are you using?
Is it possible to use as shortcode in posts or pages?
@Bob,
Right now it is not possible to use shortcodes. But if you have a real need for it, then let me know and I may be able to add this feature to the Plugin for you.
For my blog I need just that, a list of post of a certain tag within an page.
Tried to embed your php code using phpexec plugin but does not show any results.
Could you create the shortcodes function for us ? Or perhaps guide me thru my installation ?
Thanks,
Karsten
Working on adding the support for shortcode. Will release it in a couple of days. Stay tuned
Thanks
Found solution to my initial problem: use lower case variable names (which let variable values to pass to the embedded function) and use return in stead of echo for the output (echo executes to early and output is written before the contend of the post. Return put the output inline with the shortcodes).
Well, got two new issue now: need to add the post’s date to the list of posts found (similar to author’s name), and the [...] should have a link to the post, too.
And one last idea: pass “*” as tag name to get a list like
Tag1
List of posts
Tag2
List of other posts
Just released v0.8 of the Plugin which has the support for shortcode. Enjoy
Thankyou Very usefull, just what I needed and it installed in a breeze.
Now, you are so clever that maybe even this is possible with your plugin: could it be made so that it shows the posts in alphabetic order??
Somehow, this next line makes me think it would, but I don’t know enough code to know for sure.
Thank you so much, and go on with your interesting stuff!
regards, Robert
/* $order (asc,desc) – To change the order in which the posts are displayed. */
Working on it. Will release an update to the Plugin in a couple of days with this feature. Stay tuned
Just released v0.8 of the Plugin with the ability to sort by title. Enjoy
Thanks for the wonderful plugin, like someone else who commented the option to use a shortcode would make this plug-in a must for any WordPress installation. It would really be great, I’d be willing to pay for a feature like that. Email me if possible. Thanks.
Just released v0.8 of the Plugin with shortcode support. Enjoy
This plug-in is what I have been looking for!
I just want to ask you regarding how to use “Template Tag” as I know nothing about php and can’t get the plug-in working on my site.
The above code is correct? I’m not sure how to insert a name of a tag (e.g. perth) and number (e.g. 3). If incorrect, can you please advise the correct way to writing a tag name and a number?
Thanks!
Just use the following code
< ? php
postsbytag("perth", 3);
? >
The other parameters are optional.
sorry, the code was missing in my previous post…
oh, apparently, php code I wrote won’t be shown in the comment… Then, I’ll remove those first and last parts. Sorry I’ve messed up your comment section.
($tags = ‘perth’, $num = ’3′, $excerpt = false, $thumbnail = false, $order = ‘desc’, $author = false)
Hello,
I was thinking – since wordpress 2.9 already has a “post_thumbnail” feature included, could we use this insted of the custom field for the image thumbnail to ease posting to the tag widget?
Also, i noticed the bullets in the lists have different classes like:
I don’t know how they are generated, but i’m wondering if there’s a way to add a custom style to each one (via css). Say for example if i have 7 posts tagged in the widget, one color style for each day of the week?
Thanks a lot for this very useful plugin!
Is exactly what I was looking for; one less thing I need to create on my own now.
One minor flaw with the shortcode implementation, though. You’re using “echo $output;” at the end of the posts_by_tag function instead of “return $output;”. That might be because you’re reusing the same method for both widgets and shortcode, but when I add the shortcode in the middle of a new page on my site, it echoes the output right at the top of the page content instead of inline where I placed the shortcode.
I was able to update that line and then return the result in shortcode_handler function and now it works for me the way I need it. Not sure if that breaks the widget code (which I’m not using), but maybe something to look at for the next bug-fix release.
Feel free to hit me up with any questions.
- Kris
Sorry, one more minor bug.
I tried the order_by arg for the shortcode as ‘title’ and it didn’t work.
I checked the code where you’re using the get_posts() function, and the parameter you have as ‘order_by’ is actually ‘orderby’. I made that change on my install and it worked fine.
I hope this helps. This plugin is actually perfect for what I need, so I really appreciate you putting this all together.
- Kris
Thanks for reporting this bug. I am currently making the code change and will release an update (with the fix for shortcode) tomorrow.
Kris,
I have fixed both the issues in v1.0 of the Plugin. Please update the Plugin and let me know if you still face these issues.
Sudar,
Thanks for the update. I installed a new version of the plugin (v1.0) on a second blog and still came up with the same result. It looks like line 259 still has ‘echo’ instead of ‘return’ and that’s throwing it off. When I change that to ‘return’, the shortcode works fine, but I haven’t tested to see if that breaks the widget (which I’m not using).
- Kris
The template tag as shown on this page is actually not correct, it should say “posts_by_tag” instead of “postsbytag”. It’s correct on the official WordPress plugin page.
Thanks for pointing it out. Fixed now.
While using the shortcode on a page, I’ve discovered that the plugin inserts the articles at the very top of the page, right after the heading. I am not sure if that is intentional or not.
I’d much rather have it insert the articles at a position of my choosing. That way I could write “Here are the relevant posts: [posts-by-tag tags = "tag1, tag2"][/posts-by-tag]” and have the articles shown AFTER my text. Am I making any sense to you?
Oh, and by the way, the closing tag ([/posts-by-tag]) does not seem to work for me. It is displayed as text on my page and does not seem to serve a function.
See those comments above.
Misplacement happens because the plugin uses “echo” instead of “return”. There will be an updated version that fixes this soon. If you can’t way, search the code of the plugin for “echo” and replace it with “return” and it should work for you.
I have fixed the issue with shortcode on v1.0 of the Plugin. Please upgrade to v1.0 and let me know if you still face this issue.
Thanks for the great plugin !
Short code works now. Passing of arguments thru PHP more reliable now. No need for closing shortcode tag.
The misplacement still happens with me. Replaceing “echo” in line 259 with “return” made it working for me.
Oops!! missed it. Fixed it in v1.1.
Hello Sudar,
The latest update for Posts By Tags has killed the plugin – I mean it just doesn’t display the posts anymore. Before I applied the update it was working beautifully.
I have used the sidebar widget and tried using different tags since the previous ones were not working – but even after changing the tags noting comes up. I’ve tried single and multiple tag combinations.
I don’t want to use the template tag / shortcode as the widget gives much more flexibility. Could you tell my what might be the reason that the posts for selected tags aren’t showing up.
Viki,
That’s strange. Is it showing atleast the widget title?
Also what version of the Plugin you are using?
Thanks for this great plugin, it’s really useful!
Would it be possible for you to update this post with a sample of the shortcode with all the parameters included? It’s not always clear how they should be formatted.
Jean,
I have shortcode code sample in this post to include all possible parameters. Hope it is clear now.
I seem to have some trouble getting the thumbnails to show up with the post to tags plugin. It’s really too bad because I am currently using a category based widget to display posts in the sidebar but I noticed that in conjunction with WP e-commerce, whenever I look at one of the product pages, all of the titles from the posts displayed in the sidebar are changed to whatever category name the products page has. If I use your plugin, I don’t seem to have that problem, but like I said the thumbnails don’t show up.
Ray,
How are the thumbnails stored with each post?
Hi thank you very much for this great plugin.
I wander if it will be possible to set the post order by meta_key and meta_value. I’m using the plugin to display further events and this will help a lot to have them at the right dates.
Marcelo,
Right now it is not possible to sort based on meta_key or meta_value. I might add it in future versions.
Hi sudar! I am using your plugin and I find it great.
I only have problems on it when I install another plugin called WPML. I use this to translate my friend’s existing website from english to chinese but I can’t translate the post-by-tags’ title and its contents.
I already checked the WPML’s configuration settings and their website and found no problem. The WPML can display the title that I put to post-by-tags and typed the right translation but when I check it to my browser it only displays the english one.
Please give me idea how to fix it.
You may check the WPML’s plugin and try it.
Thanks!
Redmike,
I am just displaying whatever text the user has entered as widget title. Since it is a user input I am not doing any translation.
I am not sure how WPML, can hook into user input. If you know that code change to make then let me know or point me to WPML documentation and I can do the needed code change.
There are only two features your plugin is missing to make it the defacto standard “recent post” plugin.
1. Display posts from current tag. If your on a post tagged by, “Chicago”, then the widget would display recent posts from Chicago. This would accomplish the feature of “Related posts”. Which could be done with a separate plugin, but this feature is common to recent posts by category
2. Display posts from categories. If your plugin did either tags OR categories, it would be a completely functional plugin for all possible blogs.
Greg,
Thanks for the ideas.
I completely agree with the first one and is there in my TODO list. Will work on it when I get some time.
For the second idea, I am not sure if it would help to include categories, since there are already lot of Plugins which allow you to display posts based on categories.
Nice job. One request (I see it’s been requested before): an option to show the date of the posts.
It is there in my todo list. Will add the feature when I get some free time.
Thanks, I’ll watch for it. In the meantime, I moved to the posts-by-category plugin, which does have a date option. In the long run, I’d prefer to use tags for this.