WordPress.org

Support

Support » How-To and Troubleshooting » Help needed to get posts Category Name

Help needed to get posts Category Name

  • I need some help (I’m a big PHP noobie) to show an image like this:

    <img src="www.mysite.com/IMAGE.jpg" />

    I would like “IMAGE” to be replaced by the actual category name of the specific post. I tried the following snippets, found on Codex and on this forum, with no luck (they all result in “www.mysite.com/.jpg”):

    <?php echo $cat->category_nicename; ?>
    <?php echo $post->cat_name; ?>
    <?php echo $category->cat_name; ?>
    <?php get_the_category( $id ) ?>
    <?php echo $post->cat_name;?>
    <?php echo $category->cat_name;?>

    Only this one worked, but showed me only one post and broke the site layout:

    <?php foreach((get_the_category()) as $category) { echo $category->cat_name; } ?>

    Any other suggestions? Many thanks

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Help needed to get posts Category Name’ is closed to new replies.