• cron

    (@cron)


    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • MichaelH

    (@michaelh)

    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;
    ?>

    Thread Starter cron

    (@cron)

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Listing Categories’ is closed to new replies.