NEW: CPCM V3 now provides support for Full Site Editing with the Gutenberg Block Editor
The default custom menu in WordPress only allows adding a link that leads to a list of posts and pages belonging to a taxonomy (category, tag, etc). If you want to list the posts and pages themselves and if you want WordPress to do this automatically for you, then I hope you will find this plugin useful.
This plugin is available as Free and as Premium version.
Free
The free version of the plugin can be found in the WordPress.org Plugin Directory. Just search for “Category Posts in Custom Menu”. Or search for “CPCM”, that also works.
Premium
Premium: Pricing in 2024
- Single-site: 1 year, 1 URL €10,-
- Developer pack: 1 year, 10 URLs €80,-
- Payment in Euro’s via Stripe or bank transfer (IBAN) to The Netherlands
You’ll receive an automatic e-mail a month before your license expires.
Premium: Features
When you go Premium, you get the following extra features:
- Allow expanding unlimited amount of posts (-1 for unlimited)
- Extra wildcards, see below.
- Build a custom HTML structure for your menu items (no longer only flat text)
- More fine-grained control over how the posts are ordered. (Separate selection of Order By and Ascending/Descending, more fields to order by)
- More fine-grained control over how the posts are expanded. (When to remove the parent item, ability to exclude nested subcategories)
- The ability to extend the plugin with your custom post filtering and wildcards using the CPCM hooks
- Automatic updates
Premium: Support
Going Premium means you can contact me directly via e-mail for support and I’ll help you out. Below, you can read what I’ll help you with.
- Bugs: The plugin crashes, doesn’t expand the posts or doesn’t show the correct output somehow.
- Configuration support: How can I get the menu to show X…?
- Theme support: Support is provided with free WordPress themes. Issues should be reproducible in a free theme. (I cannot provide support for paid WordPress themes or plugins at this moment.)
- Plugin support: Support is provided with free WordPress plugins, provided that these plugins do not affect the menu. If another plugin also edits the menu, I cannot guarantee that my plugin will work properly. (Important note: Conflicts will surely arise if two plugins are tasked with editing your menu. Therefore, you should first check that the Free version of my plugin works as intended, before you purchase the Premium version.)
- Please note: This plugin is delivered as-is. Going Premium does not mean that your feature requests will automatically be honored. That being said, feel free to send me a message, perhaps your request can easily be achieved with the CPCM hooks.
Premium: Extra wildcards
- %post_featured_image_url
- %post_featured_image (insers an HTML ‘img’ tag with the featured image or nothing if there is none)
- %post_featured_image_thumb_url
- %post_featured_image_thumb (inserts an HTML ‘img’ tag with the featured image thumbnail or nothing if there is none)
- %post_excerpt
- %post_url
- %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
Premium: Actions and filters for extensibility
The plugin behavior can be extended.
To extend the backend with your own controls and use them in the posts query, add the following:
- Filter “cpcm_filter_posts_query”: This filter is called to determine which posts to retrieve for the selected category/taxonomy. You can add or modify the posts query to your liking.
- Action “cpcm_custom_fields”: This hook allows you to add your own input fields to the Category Posts in Custom Menu container in Appearance > Menus.
To add your own wildcards for the post navigation label, add the following:
- Filter “cpcm_replace_user_wildcards”: This filter is called after all default CPCM wildcards have been processed.
You can see examples in the sample-extensions directory, included in the plugin code.
Premium: Screenshots
Via Appearance > Menus:
Via Appearance > Customize:
Via Appearance > Editor:
Known limitations
Missing CSS class (WordPress bug)
The CSS class ‘current-post-ancestor’ is not applied correctly. This is a bug in WordPress that I have reported here: https://core.trac.wordpress.org/ticket/32918. This is not something I am able to fix in the plugin, it has to be fixed in WordPress. I’m sorry for the inconvenience.
Performance
The plugin is potentially very expensive, especially when you decide to build your entire menu out of nothing but category posts.
The solution would be to cache the menu using transients, as reported here https://wordpress.org/support/topic/performance-problem-many-database-queries?replies=11#post-7829450
> $my_cached_menu = get_transient( 'my_cached_menu');
>
> if( $my_cached_menu === false )
>
> {
>
> $my_cached_menu = wp_nav_menu( ... );
>
> set_transient( "my_cached_menu_", $my_cached_menu, YEAR_IN_SECONDS );
>
> }
>
> echo $my_cached_menu;
Conflicts with plugins/themes
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.”
If you are using a recent version of category Posts in Custom Menu and an updated version of WordPress, the problem can only occur due to your theme or other plugins conflicting with Category Posts in Custom Menu. Please disable all themes and plugins except CPCM; verify that the CPCM fields show; enable other plugins and themes one by one to determine which plugin/theme conflicts with CPCM.
Note: A theme must either call wp_nav_menu()
or apply_filters( 'wp_nav_menu_objects', … )
for CPCM to be triggered.
You should first check that the Free version of my plugin works as intended, before you purchase the Premium version