WordPress.org

Forums

Listing Categories (3 posts)

  1. cron
    Member
    Posted 9 years ago #

    I would like to be able to have a simple list of all the categories on the site in this sort of format.

    Cat 1, Cat 2, Cat 3

    I do not want them displayed as links and I would like to exclude the 'Uncategorised' category. Is this possible. I have looked at <?php list_cats(); ?> and the <?php wp_list_cats(); ?> template tags but they are not waht I am looking for.

    Any sugestions would be appreciated.

  2. MichaelH
    Member
    Posted 9 years ago #

    This should work for you.

    <?php
    global $wpdb;
    $where = 'cat_ID > 1'; //exlcude Uncategorized
    $orderby = 'cat_name';
    $order = 'ASC';
    $my_cats = '';

    $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories WHERE $where ORDER BY $orderby $order");

    if ( count($categories) ) {
    foreach ( $categories as $category ) {
    if (empty($my_cats))
    $my_cats = $category->cat_name;
    else
    $my_cats .= ', ' . $category->cat_name;
    }
    }
    echo $my_cats;
    ?>

  3. cron
    Member
    Posted 9 years ago #

    Thanks alot Michael. I was looking for a template tag of something but this works great. I appreciate the help.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.