Home>

The wp_list_categories function is a function used in wordpress to list categories in the system.This function has many parameters that control the output,Suddenly asked by a friend today,So I sorted it out.

Because of the expanded gadget functionality built into wordpress,

So we can display a list of categories in the sidebar or other places we want without any function,

So the wp_list_categories function is rarely used,

The function is a bit similar to wp_list_bookmarks,

wp_list_categories descriptionThe wp_list_categories function is a function used in wordpress to list category links in the system.

usage

<?php
 wp_list_categories ($args);
$args=array (
 "show_option_all" =>"", // list category links
 "orderby" =>"name", // order by name
 "order" =>"asc", // ascending, descending
 "style" =>"list", // Whether to use a list (ul>li)
 "show_count" =>0, // whether to show the number of articles
 "hide_empty" =>1, // whether to show no log category
 "use_desc_for_title" =>1, // whether to display the category description
 "child_of" =>0, // whether to restrict sub-categories
 "feed" =>"", // whether to display rss
 "feed_type" =>"", // rss type
 "feed_image" =>"", // whether to display rss picture
 "exclude" =>"", // Exclude classification id, multiple separated by ", (comma)"
 "exclude_tree" =>"", // Exclude classification tree,The parent category and its sub-categories
 "include" =>"", // Included categories
 "hierarchical" =>true, // whether child and parent are classified
 "title_li" =>__ ("categories"), // the name of the list title
 "show_option_none" =>__ ("no categories"), // the title displayed when there is no category
 "number" =>null, // show the number of categories
 "echo" =>1, // whether to show,Display or return a string
 "depth" =>0, // level limit
 "current_category" =>0, // Add a category without
 "pad_counts" =>0, // I don't understand this
 "taxonomy" =>"category", // The taxonomy used
 "walker" =>null // classes for display (very complicated concept)
?>

Regarding "pad_counts", I haven't figured out what this parameter does.

If you are interested you can study the official documentation of this parameter.

You can also use wp_list_bookmarks.

pad_counts
(boolean) calculates link or post counts by including items from child categories. if show_counts and hierarchical are true this is automatically set to true. this parameter added at version 2.9 valid values:
1 (true)
0 (false) – default

Use case

Show category links with ids 3,5,9,16,And sorted by name

<ul>
<?php wp_list_categories ("orderby=name&include=3,5,9,16");?>
</ul>

Show category with title as category including id 5,9,23

<ul>
<?php wp_list_categories ("include=5,9,23&title_li =<h2>". __ ("poetry"). "&/ H2>");
</ul>

Of course you can also write parameters like this,Combine the parameters into an array.

<?php
$taxonomy="genre";
$orderby="name";
$show_count=0;// 1 for yes, 0 for no
$pad_counts=0;// 1 for yes, 0 for no
$hierarchical=1;// 1 for yes, 0 for no
$title="";
$args=array (
 "taxonomy" =>$taxonomy, "orderby" =>$orderby, "show_count" =>$show_count, "pad_counts" =>$pad_counts, "hierarchical" =>$hierarchical, "title_li" =>$title
);
?>
<ul>
<?php wp_list_categories ($args);?>
</ul>

The taxonomy taxonomy is a concept relative to tags.

php
  • Previous Detailed animation of Android programming
  • Next Analysis of Cosine Theorem and SimHash of Text Similarity Algorithm under NET and Application Example
  • Trends