WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Can I list only top level cats with wp_list_categories()?

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

  • 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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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.

    sophiavancouver
    Participant

    @sophiavancouver

    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?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Can I list only top level cats with wp_list_categories()?’ is closed to new replies.