Support » Fixing WordPress » Displaying The Title Of A Single Category

  • Resolved swortis

    (@swortis)


    Hello,

    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>
    [etc]
    </div>

    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?

Viewing 1 replies (of 1 total)
  • swortis

    (@swortis)

    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

Viewing 1 replies (of 1 total)
  • The topic ‘Displaying The Title Of A Single Category’ is closed to new replies.