Did you know that you can change the sort order of posts and categories listed in menu items with WordPress, and can even eliminate some items that you might not want to display? WordPress uses built-in PHP functions and the output is easily modified without the need to alter the code in the functions themselves.
There is a good reason for not altering the code in the core WordPress scripts unless it is absolutely necessary to do so. Most PHP functions are part of the core code, and if you change the code in these scripts, you will lose your changes the next time you upgrade WordPress.
WordPress developers have set up the system so that you can alter the behavior of several PHP core functions by inserting arguments sent with the call to the function from the theme template scripts. Arguments are name-value pairs, which are sometimes called parameters. You must use a valid name for an argument and assign a valid value in order for a change to work.
There are two functions to look for in your WordPress theme. In most themes, you will find the calls to the menu listings for pages and categories in the sidebar.php script. Sometimes, a designer will place the call to the pages function in the header.php or footer.php script. If you are using sidebar widgets, this information does not apply, because widget code calls to the functions will be found in other scripts.
The two function to look for are the following:
There may already be a set if arguments added to the function call. Be carefully with what you add or remove, because you could break the display of the menu items. Separate arguments are delineated by the ampersand sign ( & ).
Here is a typical set of arguments included in the call to the wp_list_categories function:
These arguments turn on the category post counts and display the name Categories above the list.
If you have an old template, you may see calls to functions named wp_list_cats or list_cats. These functions have been depreciated since WordPress 2.1 and should be replaced with the current version, which is wp_list_categories.
How to Disable the Post Counts in Categories
WordPress category menu with post counts” />Some themes are set up with the post count feature turned on, while other have it turned off. It is turned off by default, which means that if you want to disable post counts, all you have to do is remove the argument. If it is the first argument in the set, make sure that the trailing ampersand that separates the arguments is also removed. If you like post counts and want to turn them on, simply add the argument to the function call.
To turn off the post count, remove the argument show_count=1 and any ampersand separating it from another argument. As an alternate, you could change the value to zero ( 0 ), which would have the same effect. If you want to turn the post count on, change the value to 1. If the show_count argument is missing, add the following as the first argument: show_count=1&. Do not forget to add the ampersand to separate arguments.
Changing the Title for a Category or a Page List
This one is easy and the same argument works for both functions. If the title argument is already included, just change the name. The name for the title argument is title_li.
Be careful that you do not alter any HTML code surrounding the title. To change the title from “Categories” to “Sections”, just change the word or words that you wish to alter.
Including or Excluding Items from a List
You will need to know the category or page IDs for the items that you wish to include or exclude from a list. You will find these in the Admin area of WordPress. Select a category to edit and the IDs can be found in the URL in your browser’s address bar. The category ID will be designated by cat_ID=2 at the end of the URL. Pages use post IDs, so they will be designated as post=6.
The argument to add to only include a few categories or pages is include=2,4,10, where the only categories that you wish to display are those with IDs 2, 4 and 10.
The argument to exclude certain categories or pages is exclude=2,4,10, where the only categories that you wish to exclude from the category list are those with IDs 2, 4 and 10.
Category and page exceptions are an either-or proposition, so do not try to use both at the same time.