Forums

How to list parent categories ONLY on a page (2 posts)

  1. Kalytopia
    Member
    Posted 3 months ago #

    Say the WordPress I run has over 50 categories and they have their sub categories as well; and I'd like to only list the parent categories on a page.

    Parent Category A
    -Child Category 1
    -Child Category 2

    Parent Category B
    -Child Category 1

    Parent Category C
    -Child Category 1
    -Child Category 2

    and etc.

    And I want it to appear in a list with links like this

    -Category A
    -Category B
    -Category C

    How is this possible if I do not want to use a plugin that requires me to manually include or exclude the sub cats?
    Thanks in advance. :)

  2. alchymyth
    The Sweeper
    Posted 3 months ago #

    'on a page':
    you might need to create a page template
    http://codex.wordpress.org/Pages#Page_Templates

    then add either:

    wp_list_categories() with the 'depth' parameter sert to 1

    http://codex.wordpress.org/Template_Tags/wp_list_categories

    or:

    get_categories() with the 'parent' parameter set to 0 (zero)

    http://codex.wordpress.org/Function_Reference/get_categories

Reply

You must log in to post.

About this Topic