WordPress.org

Forums

How to list cats in title of post when in single view (2 posts)

  1. MrFlora
    Member
    Posted 9 years ago #

    Hey there, a good while ago people on here helped me figure out how to display the name of one category for a post in its title text when in single view for that blog post. Its been very useful.

    I was wondering however how would one do that with multiple categories associated with a post? I've found i'm using more and more categories for each post and would like all of them and not just the one with the lowest ID being included in the page title.

    Here's the PHP thats worked so well for me so far:

    <?php
    global $post;
    $my_cat_name = $wpdb->get_var("SELECT cat_name FROM $wpdb->categories, $wpdb->post2cat WHERE cat_ID = category_id AND post_id = $post->ID");
    echo strip_tags($my_cat_name);
    ?>

    Is there something i can do to this so I'll start showing all the categories instead of just the first one? Or do I need something completely different?

    Thanks

  2. MrFlora
    Member
    Posted 9 years ago #

    ba-dump!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags