[resolved] Displaying The Title Of A Single Category (2 posts)

  1. swortis
    Posted 9 years ago #


    Sort of a newbie question: I need to apply individual category titles as ID's in the html and CSS.

    HTML example:

    <div id="post-<?php the_ID(); ?>">
    <h2 id="(category name 1?)">Category of post</h2>
    <h3 id="<?php the_title(); ?>Title of post</h3>

    I've tried using <?php the_category(); ?> but that writes a full list of categories; tried single_cat_title; the_category_id, and others but they've all failed.

    What is the correct way of displaying the title of a single category?

  2. swortis
    Posted 9 years ago #

    The answer:

    <h2 id="cat<?php the_category_ID(); ?>"><?php the_category('separator'); ?></h2>

    spits out the following html:

    <h2 id="cat7">The Category</h2>

    You can modify the tag as you like in the CSS

Topic Closed

This topic has been closed to new replies.

About this Topic