The default sidebar tool of WordPress contains a tool called a category directory.
This default tool can automatically exclude the categories without articles, which is quite user-friendly.
However,
This default category directory tool does not support excluding the specified category
Although the blogger does not use this default category directory ⊙? ⊙
However, based on the principle of egg pain,
I will post a piece of code.
Paste the following code into function. php of the topic.
Paste the following code into function. php of the topic.
The code is as follows: |
Copy code |
Add_filter ('widget _ categories_args ', 'MK _ exclude_widget_category', 10, 1 ); Function mk_exclude_widget_category ($ cat_args ){ $ Cat_args ['clude'] = array (, 20, 21, 22);/* The number in the array is the id of the category directory to be excluded */ Return $ cat_args; }
|
Exclude the specified category and tag from the sidebar
Add the following code to the topic's functions. php file:
The code is as follows: |
Copy code |
Function shailan_filter_terms ($ exclusions, $ args ){ // IDs of terms to be excluded $ Exclude = "3,257"; // change this to IDs OF YOUR TERMS // Generation of exclusion SQL code $ Exterms = wp_parse_id_list ($ exclude ); Foreach ($ exterms as $ exterm ){ If (empty ($ exclusions )) $ Exclusions = 'AND (t. term_id <>'. intval ($ exterm ).''; Else $ Exclusions. = 'AND t. term_id <>'. intval ($ exterm ).''; } // Closing bracket If (! Empty ($ exclusions )) $ Exclusions. = ')'; // Return our SQL statement Return $ exclusions; } // Finally hook up our filter Add_filter ('list _ terms_exclusions ', 'shailan _ filter_terms', 10, 2 ); |
Note that in the code, the numbers in row 3rd $ exclude = "3,257 & Prime; represent the document category or tag ID. Of course, they are all excluded objects!