No description, website, or topics provided.
PHP JavaScript CSS
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


=== Category Posts in Custom Menu ===
Contributors: anaid
Donate link:
Tags: menu, category, post tag, tag, posts, dynamic, automatic, custom, taxonomy, custom taxonomy
License: GPLv2
Requires at least: 3.2.1
Tested up to: 4.7
Stable tag: 1.2.3

Dynamic menus: List all posts from a category in your menu. Also works for tags, custom taxonomies as well as pages and custom post types.

== Description ==

The custom menu only allows adding a <i>link</i> 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 <b>themselves</b> and if you want Wordpress to do this automatically for you, then I hope you will find this plugin useful.

<strong>Also works for custom taxonomies and custom post types!</strong>

= 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, 0 also allowed now);
* their ordering ascending or descending by ID, Author, Title and other properties. See 'Other Notes > Ordering';
* keep or remove the original menu item (always / only if there are no posts / never);
* 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.

The plugin now supports the wp_nav_menu_item_custom_fields hook and should be compatible with other plugins that also use this hook.

= Wildcards =

You can control the title of the menu items generated by the plug-in with the following wildcards:

* %post_title
* %post_author
* %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 (insers an HTML 'img' tag with the featured image thumbnail or nothing if there is none)
* %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(&lt;your formatting here&gt;) for custom date formatting. Example: %post_date(l jS \of F Y, h:i:s A). See <a href=""></a> for formatting options.
* %post_date_gmt
* %post_date_gmt()
* %post_date_gmt(&lt;your formatting here&gt;)
* %post_status
* %post_modified
* %post_modified()
* %post_modified(&lt;your formatting here&gt;)
* %post_modified_gmt
* %post_modified_gmt()
* %post_modified_gmt(&lt;your formatting here&gt;)
* %post_comment_count
* wildcards for custom fields, like %post_my_field, where 'my field' or 'my_field' is a custom field

The following wildcards are deprecated:

* %post_feat_image (url only)
* %post_feat_image_thumb (url only)

= Ordering =

You can control the ordering of the items in the menu by sorting ascending or descending on the following properties:

* None
* ID
* Author
* Title
* Date
* Last Modified
* Post/Page parent ID
* Random Order
* Number of Comments
* Menu Order - Ordering by menu order is only possible for hierarchical types, such as pages. These have the 'Order' option when editing, this is the menu order.

= Extend the plugin =

The plugin behavior can be extended.

To extend the backend with your own controls and use them in the posts query, add the following:

* Action "cpcm_custom_fields": Use this to extend the custom fields to add to the Category Posts in Custom Menu container in Appearance > Menus
* Filter "cpcm_filter_posts_query": This filter is called when the menu_item is of taxonomy type and the "Create submenu containing links to posts in this category" is checked. Here, you can add or modify the posts query to your liking.

To add your own wildcards, add the following:

* Filter "cpcm_replace_user_wildcards": Called after all default CPCM wildcards have been processed.

You can see an example in the sample-cpcm-extension directory, included in the plugin code.

== Screenshots ==

1. Go to Appearance > Menu to enable/disable and set the options for the replacement of Category / Post Tag links by their posts.

== Upgrade Notice ==

= 1.2.3 = 

Now compatible with WordPress 4.7!

= 1.2.2 =

New feature: Allow users to add their own wildcards.
Minor: readme, unittests.

= 1.2.1 =

Bugfixes of minor issues

== Changelog ==

= 1.2.3 =

* Hide the options when 'Create submenu ...' is not checked, thanks for contribution by websevendev
* Fix compatibility issue with 4.7, resulting in options not being shown.

= 1.2.2 =

* Allow users to plug-in their own wildcards to facilitate
* Edit readme to explain usage of the custom wp_nav_menu_item_custom_fields that several plugin authors have been using.
* Add example implementation to the sample extension that shows how to extend the CSS classes of the menu items, as indicated here
* Unit tests

= 1.2.1 =

* Only commit meta data for menu items that actually had a CPCM checkbox, reported here
* Set default skip parameter to 0, as reported here

= 1.2.0 =

* Fixed serious bug in versioning, which resulted in version 1.1 having no settings at all anymore. This fix has been tested with both both the upgrade path 1.0.1 -> 1.2 and upgrade path 1.0.1 -> 1.1 -> 1.2, both upgrade paths should be fined now. My sincere apologies to all who experienced this issue.
* Fixed debug errors as reported here

= 1.1 =

* Process custom fields last, so that users cannot override the built-in options like %post_featured_image with a custom field named "featured_image". As reported here
* Allow others to extend my CPCM plugin with their own fields. Also includes a sample that shows how to do this.
* Some comments and code formatting
* Introduced plugin versioning in code in order to perform data conversion 
* Converted "cpcm-" custom fields to "_cpcm-" so that they don't show on post edit pages and the like.
* Update contact information
* Ensure that excluding subcategories now also works for custom taxonomies. Only show the dropdown for hierarchical taxonomies. (Tags no longer show 'Subcategory posts' dropdown.)
* Add custom CSS classes, as suggested here

= 1.0.1 =

* Added hook wp_nav_menu_item_custom_fields for compatibility with other plug-ins adding fields to the Appearances > Menus page.
* Fix for CSS class bugs reported by brangelo in
* Bugfix: normal menu items that were below a menu item removed by cpcm, are now repositioned in the menu correctly.
* Bugfix for subcategories with a single post with setting remove="only if empty": "For example, I have a parent category A with sub categories A1, A2 and A3. I have all sub categories set to remove only if there are no posts. Subcat A1 displays with submenu of posts (2), subcats A2 and A3 do not display and their posts (1 each) show directly under the parent as posts links."

= 1.0 =

* Bugfix: Correctly set the menu item parents. Relevant when nesting categories with 'Create submenu' checked.
* First implementation (WIP) for request:
When the menu item is marked as remove "always" or "only if empty" and there was one post, then make sure that any childen of the menu item become children of this single post.
* Implement skip-parameter
* Implemented exclusion of subcategories, useful alternative to

= 0.9.5 =

* Fixed You can now specify 0 in 'Number of posts'. That way, the category can be shown/hidden based on whether it is empty or not.
* Fixed Forward slash is now accepted in date formatting.

= 0.9.4 =

* Fix due to variable $string that has been moved out of the global scope in new Wordpress release.

= 0.9.3 =

* Fix
* Fix
* Add support for auto-generated image tags, see

= 0.9.2 =

* Fixed bug introduced in 0.9.1 with respect to old PHP versions (5.2 and before)
* Introduced an extra ordering option 'Menu Order', as suggested here:

= 0.9.1 =

* Edits for strict mode (
* Add thumbnail option with posts (
* PHP 5.5 preg_replace() /e modifier deprecated (

= 0.9 =

* Fixed CSS 'active' class problem: CSS classes are no longer copied from the parent menu item to the menu item for the posts/pages.

= 0.8 =

* Added the option to keep or remove the original menu item. Initially, the original menu item was replaced by the list of its posts, but now you can choose for yourself whether this should be done (always / only if there are no posts / never)

= 0.7.2 =

* Bugfix: Fixed invalid argument error reported by macrocurio in Plugin Support.

= 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 ==

= How do I use it?  =

Here's a walkthrough:

<li>Enable the Twenty Eleven theme.</li>
<li>Disable all plugins except Category Posts in Custom Menu.</li>
<li>Create a post with title "Post 1" and add a _new_ category "Category A"</li>
<li>Save the post</li>
<li>Go to Appearances > Menus</li>
<li>Click "create a new menu"</li>
<li>Add the category "Category A" by opening "Categories", checking that category and clicking "Add to menu"</li>
<li>Open the menu item and check "Create submenu containing links to posts with this tag."</li>
<li>Do not change anything else about the menu item</li>
<li>Scroll all the way down and check under "Theme Locations" the checkbox "Primary Menu"</li>
<li>Save the menu</li>

If you now look at your blog, you will have a menu with only one item: "Category A". If you hover over that item with the mouse, it will open, and a post is displayed titled "Post 1". Add additional posts to Category A and you will see these additional posts in the menu.

= Missing CSS classes =

The CSS class 'current-post-ancestor' is not applied correctly. This is a bug in WordPress that I have reported here: 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 issues =

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

> $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;

= Compatibilty =

When another plugin or theme, other than CPCM, has a higher priority than CPCM and overwrite sthe fields in Appearances > Menus, this means CPCM's fields won't show. (Verify by disabling all plugins and check if the CPCM fields now show.)

There is no way to go around this with native Wordpress hooks. A proposed solution is for all plugin and theme users to start calling and using a custom hook. CPCM does this. The proposed hook is `wp_nav_menu_item_custom_fields`. Several plugin authors are using this hook. If another plugin is not compatible, contact the author and request they start using this hook. Also see

= 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." 

This problem should only occur if:
<li>Your Wordpress version is 3.0 or before: Issue 14527 ( may be the cause. When adding a menu item but <i>before</i> saving it, you will indeed see none of the promised checkboxes. So be sure to <b>save your menu</b> after you add a Category/Tag to your menu. <i>Then</i> you'll see the added functionality. Please update your Wordpress version to at least 3.0.1.</li>
<li>You're using an old version of Category Posts in Custom Menu. Please update to the latest version of CPCM.</li>
<li>Other theme or plugin conflicts. 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.</li>