Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other How to Get Category-ID or Category Slug Inside the query_post String? (WordPress)

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #42878
    bernar
    Participant

    Hi, I’ve been reading a lot and can’t find a solution for this problem.

    I have several category pages in my WordPress website and I want to use ONLY ONE TEMPLATE for all those category pages. And by the way, I’ve created pages to manage all the sections/categories of my website more easily.

    I know I can use the next code for every single page template and change the slug:

    ‘whatever_category’); ?>

    Is there any way to make it so ‘whatever_category’ is got from the current category or custom field so I don’t have to create page templates for every single category page?

    #125442
    TheDoc
    Member

    Maybe I’m a little confused. Is there any reason why you aren’t just using category.php?

    #125512
    bernar
    Participant

    Hi, Thanks, I was trying the wrong approach.

    By the way, I have created the category.php using the following code so the category-slug is displayed inside the string based on the current category:

    $cat = get_query_var(‘cat’);
    $yourcat = get_category ($cat);
    ?>

    slug); ?>

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Other’ is closed to new topics and replies.