WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. daviddevor
    Member
    Posted 1 year 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:

    http://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>
  2. daviddevor
    Member
    Posted 1 year 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(); ?>
    </h1>

Topic Closed

This topic has been closed to new replies.

About this Topic