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

  1. MrFlora
    Posted 10 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:

    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?


  2. MrFlora
    Posted 10 years ago #


Topic Closed

This topic has been closed to new replies.

About this Topic