开发者

Wordpress > Exclude specific categories from categories listing

开发者 https://www.devze.com 2022-12-22 15:19 出处:网络
I have created some functional categories that I use to show/hide markup elements. However, when I go to list the legit categories, these show up too, which I would expect. I want to list the开发者_开

I have created some functional categories that I use to show/hide markup elements. However, when I go to list the legit categories, these show up too, which I would expect. I want to list the开发者_开发问答 legitimate categories and omit others.

I need to know how you would do it under two circumstances....

1) Each category that I want to exclude is preceded by an underscore character in its name.

2) Each category that I want to exclude is NOT preceeded by a special character and I will just provide an ID to the script that handles the exclusion listing.


A check over at the codex for the wp_list_categories template tag (http://codex.wordpress.org/Template_Tags/wp_list_categories) describes three parameters of wp_list_categories() that allow you to control the inclusion or exclusion of categories.

exclude (string) Exclude one or more categories from the results. This parameter takes a comma-separated list of categories by unique ID, in ascending order. See the example. The child_of parameter is automatically set to false.

exclude_tree (string) Exclude category-tree from the results. This parameter added at Version 2.7.1

include (string) Only include the categories detailed in a comma-separated list by unique ID, in ascending order. See the example.

You might have checked this already, and maybe you are looking for a more dynamic way to exclude categories with the prefix you describe.
A: you could hard-code the categories you want to exclude in your call to wp_list_categories().

B: you could write a function that loops through the category names (using get_categories() and create a comma separated string of of the category id's that preg_match() the prefix you designated. Pass the string to wp_list_categories argument under the exclude parameter.

0

精彩评论

暂无评论...
验证码 换一张
取 消