Download
You can get the plugin here. And you can see a sample menu at the right hand side, including a link to a post that shows how this sample menu was created.
Contributors: anaid
Tags: menu, category, post tag, posts, dynamic, automatic
Requires at least: 3.2.1
Tested up to: 3.4.2
Stable tag: 0.7.1
Dynamic menus: This plugin automatically replaces selected Category links / Post Tag links / Custom Taxonomy links in a Custom Menu by a list of their posts/pages.
Description
The custom menu only allows adding a link that leads to a list of posts and pages belonging to a taxonomy (category, tag or custom). I wanted to insert the posts and pages themselves into the menu, so I wrote this plug-in. If you want to list the posts and pages belonging to a certain taxonomy in the menu and if you want WordPress to do this automatically for you, then I hope you will find this plugin useful.
Now also works for custom post taxonomies and custom post types!
Using it
Enable the plugin and go to Appearance > Menus. Create your Custom Menu. Add a taxonomy (category/tag/custom) to the menu. Next, you can choose if you would like to replace the original link (to a page that lists the items) by the posts and pages themselves.
For each Category or Post Tag item in the menu, you now have the following extra configuration options:
- replace the link by a list of posts in the menu y/n;
- specify the (maximum) number of posts you want to show for this item (-1 = all);
- their ordering (ascending/descending by none, ID, author, title, date, modified, parent, rand or comment_count);
- specify the title for the menu items. For this you can use %post_title, %post_author and other wildcards, see ‘Other Notes > Wildcards’.
Details
This plugin uses the wp_nav_menu_objects filter hook to remove and replace category items in the menu by the posts in that category. It extends Walker_Nav_Menu_Edit to add input fields to Appearance > Menus and adds some CSS to style this properly.
Other Notes
Wildcards
You can control the title of the menu items generated by the plug-in with the following wildcards:
- %post_title
- %post_author
- %post_feat_image (url only)
- %post_excerpt
- %post_url
- %post_date for the unformatted post date: 2012-11-10 18:14:23
- %post_date() for a formatted post date with the following default formatting: November 10th, 2012
- %post_date(<your formatting here>) for custom date formatting. Example: %post_date(l jS \of F Y, h:i:s A). See http://codex.wordpress.org/Formatting_Date_and_Time for formatting options.
- %post_date_gmt
- %post_date_gmt()
- %post_date_gmt(<your formatting here>)
- %post_status
- %post_modified
- %post_modified()
- %post_modified(<your formatting here>)
- %post_modified_gmt
- %post_modified_gmt()
- %post_modified_gmt(<your formatting here>)
- %post_comment_count
- wildcards for custom fields, like %post_my_field, where ‘my field’ or ‘my_field’ is a custom field
Tips and tricks
Partial links
then WordPress creates, for example:
<a href=”link_to_post1″>Chocolate pie by Anna</a>
which results in
Chocolate pie by Anna
Some things you can do:
- Set title: %post_title</a> by %post_author
Then WordPress creates:
<a href=”link_to_post1″>Chocolate pie</a> by Anna</a>
which results in
Chocolate pie by Anna(Yes, there’s an extra closing </a> but that doesn’t really matter.)
-
Set title: </a><a href=”http://www.mysite.com/something/”>%post_title</a> by %post_author
Then WordPress creates:
<a href=”link_to_post1″></a><a href=”http://www.mysite.com/something/”>Chocolate pie</a> by Anna</a>
<a href=”link_to_post2″></a><a href=”http://www.mysite.com/something/”>Strawberry muffins</a> by Susan</a>which results in
Chocolate pie by Anna
Strawberry muffins by SusanNote that all post links will point to the same URL.
-
Set title: </a><a href=”%post_url#myhashtag”>%post_title</a> by %post_author
Then WordPress creates:
<a href=”link_to_post1″></a><a href=”link_to_post1#myhashtag”>Chocolate pie</a> by Anna</a>
<a href=”link_to_post2″></a><a href=”link_to_post2#myhashtag”>Strawberry muffins</a> by Susan</a>which results in
Chocolate pie by Anna
Strawberry muffins by SusanYou can use this to have menu item links skip to a certain paragraph if you’re using anchors in your HTML.
You can freely use HTML in the menu items.
Changelog
0.7.1
- Bugfix: Link Target, CSS Classes, Link Relationship (XFN) and Description weren’t inherited from the original menu item. They are now.
0.7
- Added support for custom post types
- Fixed user_data bug
- Added date formatting options
0.6
- Added a bunch of wildcards: %post_feat_image (url only), %post_excerpt, %post_url, %post_date, %post_date_gmt, %post_status, %post_modified, %post_modified_gmt, %post_comment_count
0.5
- Enable custom taxonomies.
- Change plugin URL.
0.4
- Fix plugin bug for Tags, probably related to 3.2.2 update.
- Edit documentation
- Change some CSS to show checkbox next to label instead of above it.
- Edit text in menu item block to clarify use of custom fields.
0.3
- Extended the plugin for use of custom fields. Use a custom field with name ‘my field’ with wildcard %post_my_field. Note that if the post does not have this custom field, the wildcard is removed (it is not replaced by anything).
0.2
- Extended the plugin to post tags. Note that the plugin name has unfortunately _not_ been changed to reflect this extension.
Added checkboxes, dropdowns and text fields to Appearance > Menu. It is now possible to:
- Enable/disable per taxonomy item whether you want to replace it by its posts
- Specify the (maximum) number of posts that should be displayed.
- Specify the ordering (Descending/Ascending) and the field to order by (ID, title, etc..)
- Set a title for the menu items. For this you can use the wildcards %post_title and %post_author.
Installation
1. Upload `category-posts-in-custom-menu.php` to the `/wp-content/plugins/` directory
2. Activate the plugin through the ‘Plugins’ menu in WordPress
Frequently Asked Questions
Can’t see it working in any way
Problem: “I can’t see what effect it has had. Nothing has changed (not that I can see) in the Appearance > Menu page. Just like before.”
Two possible causes:
- Issue 14527 (http://core.trac.wordpress.org/ticket/14527) is the cause. When adding a menu item but before saving it, you will indeed see none of the promised checkboxes. So be sure to save your menu after you add a Category/Tag to your menu. Then you’ll see the added functionality.
The reason is because the hook that is used to extend the functionality is not being applied until you’ve saved the item. A patch was approved for WordPress 3.4, so upgrade your WordPress installation.
- You’re already using another plugin that uses the wp_nav_menu_edit hook and has a higher priority than mine. This is by design: My plugin is not critical and therefore I don’t claim a high priority on the hooks. Plugins/Themes that indicate to be more important will be given priority.
- You’re using a theme that somehow doesn’t support editing the menu. Try using the default WordPress theme to see if your problem persists. I can’t offer much support if the theme is the problem, because this is my first and only plugin and I wouldn’t know where to begin to solve theme problems..

36 Responses to “Category Posts in Custom Menu”
Hey! Thank you so much for the great plugin!
It totally took away my pains!
I know this is your first plugin, and it’s totally great !
So this is just for your information if you didn’t know it, and so if you will, can get some programmers out there to correct a flaw in the code. (I don’t know how, would have done it if i could:)
I am using a visual editor theme called headway, wich is awesome when working with wordpress.
It’s not a big problem, i just wait to activate it to when i publish the site.
But the code conflicts somehow with headway, so the headway editor cant load the css at all hehe.
But the plugin works flawless when viewing in my browser
Hay just wanted to thank you Diane!
Hi Emil,
thank you for your kind words. I’ve taken a look at the Headway website, but I don’t have a license and I will not be paying money just to fix it if it only occurs in Headway. However, if you can be more specific of what the problem is, I’m willing to take a stab at debugging it blindly. Can you do the following for me: In headway, however that works, activate the plugin and go to a page where the problem occurs. Then, save that page (File > Save). This will save the page as .html, including a folder with the same name in which resources like images and CSS are saved. Now open that .html file on your computer and if the error also occurs there, please put everything in a .zip file and e-mail it to me (diana at imyou) and I’ll see what I can do.
In any case, glad that it was useful for you, even with headway messing it up
EDIT: Via e-mail I notified Emil that I had updated the plugin to version 0.2 after which he let me know that the problems with Headway do not occur anymore.
Thank you so much for this plugin! Real life saver. It was exactly what I needed for my members area. This plugin mixed with wishlistmember is amazing!
Thanks!
Josh
@Josh Glad to hear it is useful to you
Thank you for taking the time to comment.
Hi,
after the installation I don’t see any difference in the Appearance > Menu . :O
I am using WordPress 3.3.
Hi Salvo,
I added a FAQ to the plugin page at WordPress.org, but hadn’t added it to my personal site yet. I’ve just added two possible explanations. Please check whether one of these applies and let me know!
Kind regards,
Diana
This is a great plugin that has saved me on a couple of occasions already, so thank you for sharing
I’m looking to extend it by adding extra HTML using content from custom fields but don’t know where to start. Can you give me any pointers?
Hi Derek,
thank you for your message! Glad to hear that you find my plugin useful
As for extending the HTML: in what way? Do you mean replacing custom placeholders by data (currently done with %post_author and %post_title)?
I’m willing to extend the plugin, but only if the added functionality benefits everybody. I could try to add support for inserting the data in custom fields, but I’m not sure yet if and how this is possible, because I’ve never used custom fields before.
If you can be more specific on what you want to do, I’ll see what I can do for you
In the meantime, you may want to check out lines 131 and 132 in the plugin source.
Hope this helps.
Kind regards,
Diana
Thanks for the reply Diana.
I have a custom field on each post called “image”, and I have made a custom placeholder %post_image. I want to show the image inside the <li>
I have added $posts[$pkey]->title = str_replace( “%post_image”, $image, $posts[$pkey]->>title);
which works when $image is set to a string, but when I set it to a custom field using
$image = get_post_meta($menu_item->db_id, “image”, true);
it doesn’t work. Please note at this stage I’m only expecting it to give me the path to the image, not the actual image.
Hi Derek,
haven’t looked into it in detail yet, but I’m pretty sure you should use something like
$image = get_post_meta($posts[$pkey]->ID, “image”, true);
This is because $menu_item->db_id refers to the database-id of the menu item, not of the post itself. Menu-items are stored in the same table and have similar attributes as posts, but aren’t the same thing.
Let me know if that’s it, if not then I’ll look into it next week.
Kind regards,
Diana
Hi Diana,
Thanks again for replying. I’m only just getting back to this now – another project jumped the queue.
Unfortunately that method didn’t work. Sorry I can’t give you more details but I’m a bit lost in the PHP and database.
Derek
Hi Derek,
I’ve just updated the plugin to 0.3, the update should appear sometime soon. You can speed things up by uninstalling 0.2 and then re-installing the plugin from WordPress plugin repo. I’ve added support for custom fields.
Example:
Add custom field ‘my image’ to a post and give it the value
‘http://diana.imyou.nl/wp-content/uploads/2012/01/cropped-skull-island.jpg’ (without all these quotation marks of course)
Then, under Appearance > Menus, create a new category/tag menu item, save the menu and then set the Post Navigation Label for this item to something like:
<span class=”titlespan”>%post_title</span><span class=”imagespan”><img src=”%post_my_image” /></span>
Note that this requires you to use the custom ‘my image’ field *for everything in that category*, because the %post_my_image wildcard returns empty string if the image is not available, which results in a broken image icon in that case.
I hope this helps. I’d love to hear from you if this solves your problem
Kind regards,
Diana
Worked like a charm. Thank you very much for your help and an excellent plugin
Thanks alot for this plugin, really usefull!
Is there maybe any way to limit the output of the titles?
I am using post titles as menu in my right menubar but when they are too long it gets kinda ugly.
hope to hear from you!
Thanks for the good plugin anyway!
Hi Ruben,
Right now, there’s no way to clip the length of the post title (or other field) in the menu. Perhaps I’ll add that later.
In the meantime, you could:
Hope that helps.
Kind regards,
Diana
Thanks for the great plugin. Worked perfectly; just what I needed!
Hi Diana,
first, thanks a lot…! Your plug-in works great and I love to use it!
But I still have one Question:
While I’m using it right now, I don’t have the chance to customize the url where it is linking to (e.g. in my case: the plug-in links to “…/?p=4″ and I would need to customize it into “#postname” because I’m using anchors and I want it to jump to my posts.)
I was trying to find the answer in your code, but I guess I’m a too bad developer.
Tnx a lot,
Björn
Hi Björn,
what you’re trying to do is unrelated to my plug-in. If you want to customize the post-URLs, then you should do so via the Settings > Permalinks option in WordPress. My code simply requests the URL that WordPress has set for the post, and copy-pastes this into the menu. (The code does not manually build the links, it merely requests the posts and post data from the database.)
I hope this answers your question. If not, feel free to ask, or visit WordPress.org and ask there.
Thank you very much for responding to my plug-in, I hope you will continue to find it useful.
Kind regards,
Diana
It is possible!
It’s not perfect, but if you’d like, here’s the way to do it:
Note that the closing tag comes first, so that the final result becomes:
<a href=”http://www.mysite.com/something/”>%post_title</a>
Note that this results in an empty <a> tag, I cannot guarantee that this does not have unforeseen consequences.
Hi,
I’m trying this plugin, but don’t see it working.
I save menu after adding a Category/Tag to your menu. but nothing appears
Disable all other plugin (for higher priority. Nothing.
I use Suffusion theme : a conflict with it ?
Thanks for help
Hi Didier,
I’m sorry to hear the plugin is not working.
Can you be more specific? What is it that you don’t see?
1) You don’t see my extra checkboxes under Appearances > Menus
2) You see my extra checkboxes but after saving, you don’t see a difference on the website
3) Something else?
Please consider also switching to the default WordPress theme if you feel that the theme may be causing it.
Kind regards,
Diana
Hi Diana
Thanks for answer.
I don’t see extra checkboxes under Appearances > Menus
But when I switch from Suffusion Theme to Twenty Eleven Theme : it works.
Any idea (I want to keep suffusion theme)
Thanks
Hi Didier,
it is definitely the theme that prevents you from seeing these changes.
There is nothing I can do about it:
The Suffusion theme does not implement the wp_edit_nav_menu_walker hook.The Suffusion theme also uses the wp_edit_nav_menu_walker hook, with a higher priority than my plugin. If you want to work with the Suffusion theme, I can suggest one work-around:De-activate the Suffusion theme, then use my plug-in for the menu. Next, enable the theme again. The settings from my plugin are saved and applied. The only thing that doesn’t seem to work is Appearances > Menus.
In any case, the Suffusion theme should support the wp_edit_nav_menu_walker hook in order for this to work. Since it doesn’t, that is the reason you don’t see any differences.Kind regards,
Diana
[Edited to inlude new information]
Hi Diana,
Thanks for details and solution.
I tried : “De-activate the Suffusion theme, then use my plug-in for the menu. Next, enable the theme again. The settings from my plugin are saved and applied. ”
After re-activate Suffusion, it’s OK;
But when I add something to Menu and save Menu with suffusion active : all comes back like before
Kind Regards
Didier
Hi Diana,
I ask Suffusion developer about this problem, but I had this answer in his forum (<snip>) :
“Sorry, I have no idea what that means. I searched all my installed themes and I didn’t find wp_edit_nav_menu_walker anywhere (not even in TwentyTen or TwentyEleven). In fact, only Suffusion has wp_edit_nav_menu_walker, which it uses for Mega Menus. So I don’t know what the developer means when he says, “The Suffusion theme does not implement the wp_edit_nav_menu_walker hook”.”
I’m just using wordpress… and I don’t understand where is the problem… but I think that lots of peopls would like to use your plugin.
Could you give more details to Sayontan (Suffusion developer) ?
Thanks
I’ve updated my earlier reply, I made a mistake there: For a minute, I thought the Suffusion theme was overriding the Appearances > Menus page with a .php of their own. This is not the case, it seems to be that they are also using the wp_edit_nav_menu_walker hook, with a higher priority, which prevents my plug-in from using it. I will update the documentation accordingly.
I’m so glad this exists! It’s just what I was looking for. Thanks for sharing.
Hi,

great plugin I think. Very useful. Thos little gems are making wordpress a great system. Thank You.
But, I am trying to figure out, why the dropdown tier only shows 6 not all posts that are in the category. I am already looking into the code.
And what does the value “-1″ really mean?
I tried to enter 10 as number of posts there, but no changes at all.
Thanks in advance.
Cheers.
Ah, one thing now is clear:
In the plugin code it says: // default value of -1 returns all posts
But it doesnt do so on my site to be frank.
(I could only give You access over mail, if You would like to take a look, cause this is a clients’ site under development)
err, I completely move back. The current WP version gives me the possibility to add articles to custom menus already.
As I just want a link to the article and when all options in the “show options” dropdown (top right corner in custom menus admin page) are active I can already do a lot with them.
Okay, so thank You anyway for this plugin, when it would be still needed, it was great. Thanks.
Thanks for letting me know that you have chosen a different approach. If you ever encounter this problem again, I hope you will be able to provide some more information so that we can find the cause.
Kind regards,
Diana
I am using my own plugin on this blog, you can see the resulton the right-hand side. The number of posts works as far as I can see, I’ve added eight posts with a custom taxonomy key and they are all showing. I’ve limited the number of posts under “Posts with category ‘CPCM cat’” to 1, which also works.
If it is not working for you, please help me improve my plugin by telling me what theme and which plugins you are using. If you could then revert to the default WordPress theme and disable all other plugins and see if the problem still occurs, together we can figure out what causes this.
Kind regards,
Diana
Hi there – we’d like to be able to use your plugin on our site, but to list links in the menu to our individual Portfolio posts.
I’ve added the plugin and can easily bring up Portfolio Categories; but nothing displays on the public side in the drop down menu.
Is this something we can tweak? Or outside the scope of your plugin.
Thanks – your feedback is appreciated.
The plug-in currently does not support custom post types. However, there’s a thread in the support forum suggestion how that functionality can be added. I will add it in a next version, but first I need to get around to testing it myself. In the meantime, check that out and apply the change to enable the plug-in for custom post types.
Thanks alot for this very useful plugin!
There’s a small bug though!
In line 127:
$post->title = str_replace(“%post_author”,$userdata ? $userdata->display_name : ”, $post->title);
…should be:
$post->title = str_replace( “%post_author”, $userdata ? $userdata->data->display_name : ”, $post->title);
George, thank you for your feedback. I am at the moment unable to make any modifications to the plug-in (don’t have internet at home and can’t do this in the boss’s time), but as soon as I can I will fix this.
Thank you for reporting!