Using WordPress ‘list_cats()’ PHP function

The list_cats() WordPress PHP function is used to list categories.

Usage

list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', $file = '', $list = true, $optiondates = 0, $optioncount = 0, $hide_empty = 1, $use_desc_for_title = 1, $children = false, $child_of = 0, $categories = 0, $recurse = 0, $feed = '', $feed_image = '', $exclude = '', $hierarchical = false);

Parameters

  • $optionall (int) – Optional. Default: 1
  • $all (string) – Optional. Default: ‘All’
  • $sort_column (string) – Optional. Default: ‘ID’
  • $sort_order (string) – Optional. Default: ‘asc’
  • $file (string) – Optional. Default: ”
  • $list (bool) – Optional. Default: true
  • $optiondates (int) – Required
  • $optioncount (int) – Required
  • $hide_empty (int) – Optional. Default: 1
  • $use_desc_for_title (int) – Optional. Default: 1
  • $children (bool) – Optional. Default: false
  • $child_of (int) – Required
  • $categories (int) – Required
  • $recurse (int) – Required
  • $feed (string) – Optional. Default: ”
  • $feed_image (string) – Optional. Default: ”
  • $exclude (string) – Optional. Default: ”
  • $hierarchical (bool) – Optional. Default: false

More information

See WordPress Developer Resources: list_cats

Examples

Basic usage

// List all categories, sorted by name
list_cats();

Sorting by category count

// List all categories, sorted by category count in descending order
list_cats(1, 'All', 'count', 'desc');

Hiding empty categories

// List categories with at least one post, sorted by name
list_cats(1, 'All', 'name', 'asc', '', true, 0, 0, 1);

Showing category description as title

// List all categories with their description as the title attribute
list_cats(1, 'All', 'name', 'asc', '', true, 0, 0, 1, 1);

Displaying categories hierarchically

// List categories hierarchically, sorted by name
list_cats(1, 'All', 'name', 'asc', '', true, 0, 0, 1, 1, false, 0, 0, 0, '', '', '', true);

Tagged in

Leave a Comment

Your email address will not be published. Required fields are marked *