Forums

Styling get_category... Splitting it... (3 posts)

  1. ibeats
    Member
    Posted 2 years ago #

    I've applied a style around my "get_category" as below;

    <span class="<?php $category = get_the_category(); echo $category[0]->category_nicename; ?>-highlight">
    <?php the_category(',') ?></span>

    The problem is this applies the same style to all the categories listed. Can I do something like this...

    <span class="<?php $category = get_the_category(); echo $category[0]->category_nicename; ?>-highlight">
    <?php the_category('</span>, <span class="<?php $category = get_the_category(); echo $category[0]->category_nicename; ?>-highlight">') ?></span>
  2. MichaelH
    Volunteer
    Posted 2 years ago #

    Just iterate through each category

    <?php
    foreach((get_the_category()) as $category) {
        echo '<p>'.$category->category_nicename . '</p>';
    }
    ?>
  3. ibeats
    Member
    Posted 2 years ago #

    Close, but not quite, though I guess It's me that's not doing the right thing...

    Take a look at the bottom here; http://www.ibeats.co.uk/ (4,6,7 in Other News) show two categories but are only taking the styling of the first :(

Topic Closed

This topic has been closed to new replies.

About this Topic