Support » Fixing WordPress » List Categories or Tags that starts with

  • In one of my blogs Ive a lot of categories, categorisied in this way:


    If I change this structure to

    Is there anyway to display categories that starts with A,
    If I add Adam, Amaro… tags to posts is there anyway to list tags that starts with A.

    Thank you.

Viewing 1 replies (of 1 total)
  • This means going into your template file and adding the code that pulls out the categories you’d like to have appear.

    You’ll want to look at the PHP function strncmp and the WordPress function get_categories.

    Here’s one possible way to put them together:

    $categories=  get_categories();
    $letter = 'A';
    foreach ($categories as $category) {
        if ( strncmp($category->cat_name,$letter,1)==0) {
            $option = "<br/>";
            $option .= $category->cat_name;
            echo $option;

    You’ll undoubtedly want something more complicated than that, and there are some examples in the Codex page for get_categories that may be helpful.

    To do the same kind of thing with tags, you’d use the same get_categories function, but tell it you were interested in the “post_tag” taxonomy:

      'taxonomy' => 'post_tag',
    $tags = get_categories($args);

    I hope that’s enough to get you started.

Viewing 1 replies (of 1 total)
  • The topic ‘List Categories or Tags that starts with’ is closed to new replies.