Category Posts in Custom Menu

WARNING: Version 2.0 has breaking changes! See changelog.

This plugin is now available as Free and as Premium version.

Free

The free version of the plugin can be found at https://wordpress.org/plugins/category-posts-in-custom-menu/. You can install it via the usual WordPress Plugin route, just search for “Category Posts in Custom Menu”. Or search for “CPCM”, that also often 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
  • Buy a license

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:

  1. Allow expanding unlimited amount of posts (-1 for unlimited)
  2. Extra wildcards, see below.
  3. Build a custom HTML structure for your menu items (no longer only flat text)
  4. More fine-grained control over how the posts are ordered. (Separate selection of Order By and Ascending/Descending, more fields to order by)
  5. More fine-grained control over how the posts are expanded. (When to remove the parent item, ability to exclude nested subcategories)
  6. The ability to extend the plugin with your custom post filtering and wildcards using the CPCM hooks
  7. 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: Screenshot

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.

You should first check that the Free version of my plugin works as intended, before you purchase the Premium version