Support » Fixing WordPress » Styling categories classes

  • If I have multiple categories assigned to a post, I’d like to be able to style each category link individually. For some reason, WordPress doesn’t assign individual classes to the categories. By using the ‘<?php the_category’ tag all the class names get clustered into one like this:

    <div class=”post-253 post hentry category-devils category-nets”

    Any ideas on how to target each category class?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Looks like .category-devils and .category-nets can be manipulated individually, like:


    That’s what initially thought but it doesn’t work. The styling would only get applied to one category because each link isn’t given it’s own class.

    Here’s what the html output looks like:

    <div class="post-255 post sticky hentry category-nets category-yankees" class="post" id="post-255"> 
    <a href="" title="View all posts in nets" rel="category tag">nets</a>,
    <a href="" title="View all posts in yankees" rel="category tag">yankees</a>

    Anyone have any clue how to target/style those links?

    Anyone have a clue?

    I looked into the default the_category() which ultimately uses the function get_the_category_list where in wordpress core files I don’t see any spot for injecting other attributes such as a class by using filters.

    Maybe try doing it manually.
    $categories = wp_get_post_categories($post->ID);
    Then loop through the $categories array and generate your own links how you want. I haven’t tried this out so Im not sure how much information it will give you such as the URL, etc.

    Unfortunately, I haven’t taught myself php yet. I only get the basics. Would you mind showing me how it would look after I loop through the $categories array?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Styling categories classes’ is closed to new replies.