[resolved] Get Category of Page that item is on. (2 posts)

  1. daviddevor
    Posted 3 years ago #

    Hi All,

    I'm trying to make the category the title of the page. for example if a user clicks on a category and goes here:


    My page will show everything in that category with the title of "Camping"

    However, my problem is that a lot of posts have multiple categories and my current code is getting the "first" category present, and not the main category that all the posts have in common

    <h1 class="page_title">
    $category = get_the_category();
    echo $category[0]->cat_name;
  2. daviddevor
    Posted 3 years ago #

    Alright hopefully this helps someone, but I always find the answer after I ask for help! haha

    I used This:

    <h1 class="page_title">
    <?php single_cat_title(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic