$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>categories - Create a category list page|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

categories - Create a category list page

matteradmin8PV0评论

I am trying to create a category list page that displays only the category titles with corresponding links.

It should not be PHP directly in the page. So how can I include a listing of categories on a page?

I am very new to WordPress and have searched many websites and found only how to list posts.

Please suggest a way I might be able to display categories.

I am trying to create a category list page that displays only the category titles with corresponding links.

It should not be PHP directly in the page. So how can I include a listing of categories on a page?

I am very new to WordPress and have searched many websites and found only how to list posts.

Please suggest a way I might be able to display categories.

Share Improve this question edited Mar 31, 2015 at 23:10 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Mar 31, 2015 at 13:33 AnuAnu 1831 gold badge1 silver badge4 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 10

To display a list of categories on your page by just putting something into the content area, you need a shortcode.

You can create a shortcode by using add_shortcode. This defines the tag and the function to call when that shortcode is used.

Here's a basic example that creates a shortcode [my_cat_list]:

/**
 * This creates the [my_cat_list] shortcode and calls the
 * my_list_categories_shortcode() function.
 */
add_shortcode( 'my_cat_list', 'my_list_categories_shortcode' );

/**
 * this function outputs your category list where you
 * use the [my_cat_list] shortcode.
 */
function my_list_categories_shortcode() {
    $args = array( 'echo'=>false );
    return wp_list_categories( $args ); 
}

Adding this snippet to your theme's functions.php file will create the shortcode.

Placing the shortcode [my_cat_list] into a post or page will then display a list of categories with links to them.

The example uses wp_list_categories() in the shortcode function to display a list of categories. The example just relies on the defaults for the function, but there are quite a few options for the way the list is output. See the documentation in the codex for wp_list_categories for a full explanation of all of the defaults and options and what they do.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far