Listing Categories (3 posts)

  1. cron
    Posted 10 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
    Posted 10 years ago #

    This should work for you.

    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;
    $my_cats .= ', ' . $category->cat_name;
    echo $my_cats;

  3. cron
    Posted 10 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


No tags yet.