WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Can I list only top level cats with wp_list_categories()? (3 posts)

  1. Jonski
    Member
    Posted 7 years ago #

    Can I list only top level cats with wp_list_categories()?

    If not how can I list only the top level categories - ie. no children in the categories list.

  2. Jonski
    Member
    Posted 7 years ago #

    I have managed to get the info out of the db, if anyone else needs to do this this will give you the top level cats;

    $tlcs=wpdb->get_results("SELECT * FROM $wpdb->categories WHERE category_parent=0 ORDER BY cat_name");

    ..but there may be an easier way to do this.

  3. sophiavancouver
    Member
    Posted 7 years ago #

    This is great, Jonski. I'm not able to get it to work, I think because I've got something wrong in the syntax or usage. I can figure things out in php, but am by no means a guru.

    I'm trying to put a dynamic list of parent categories only in the header. It's a multi-user environment and I don't want to have to rewrite the header everytime someone adds a category, but I also want to hide the children in the header or there will be too many items.

    How do I use this code fragment to put a list of links to the parent categories in the header?

Topic Closed

This topic has been closed to new replies.

About this Topic