Support » Everything else WordPress » Category colors?

  • Resolved nightlyven


    I don’t know how to do this effect which have. I mean every category (or content, idk..) has own color, and a category name before the title.

    it’s related on php coding? how to do that? in php i’m ‘newbiesh’.

Viewing 6 replies - 1 through 6 (of 6 total)
  • A bit of php, a bit of styling (CSS).
    If you follow the code suggested here, it might be Ok. Don’t be too impressed by the code, I’m no php queen myself.

    You can even style each post differently if you want!

    the site is not based on WordPress;

    in a theme, you could use the post_class() output for the post categories together with the output of the_category() within the loop to get the effect;

    example (for simplicity assuming each post only has one category, needs to be within the loop):

    <div <?php post_class(); ?>>
    <h3 class="entry-title"><span class="media-type"><?php the_category(' '); ?></span><a href="<?php the_permalink(); ?><?php the_title(); ?></a></h3>
    <!--more post output-->

    and in the style.css:

    .category-catname1 span a { color: green; }
    .category-othercatname span a { color: orange; }

    wow, that’s nice, i will try to do somewhat. and thank you for these replies! 🙂

    Haha, that’s right, alchymyth’s solution is far way better and more simple!

    there is no better or more simple – however, I basically tailored my solution more closely to mimic the posted sample site.

    generally, utilizing the css class output by body_class() and post_class() makes these kind of ‘coloring’ ideas quite easy.

    if formatting is designed to be very different between categories, there is a case for loading different stylesheets as well.

    alchymyth, don’t let me be misunderstood, it wasn’t a mocking commentary, I really beleive it is easier in that case, since we just add 2 lines in the same CSS.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Category colors?’ is closed to new replies.