• Resolved daviddevor

    (@daviddevor)


    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:

    https://www.mydomainname.com/category/camping

    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">
    <?php
    $category = get_the_category();
    echo $category[0]->cat_name;
    ?>
    </h1>
Viewing 1 replies (of 1 total)
  • Thread Starter daviddevor

    (@daviddevor)

    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(); ?>
    </h1>
Viewing 1 replies (of 1 total)
  • The topic ‘Get Category of Page that item is on.’ is closed to new replies.