• Hi ??

    Am currently coding my first wordpress site, and would like some help with something?

    My client has 3 main categories with sub categories under these. These 3 main categories are colour coded red, blue and green. When these are found on a monthly or yearly archive results page, I would like the results to be shown colour coded, so that one main category and its sub categories would be blue, and so on.

    This is my current loop:

    <?php while (have_posts()) : the_post(); ?>
    <div id="posts">
    <div style="float: left;"><img src="images/postimage.jpg" /></div>
    <div class="poststext">
    
    <?php if (in_category('5') ) { ?>
    <h2><a style="color:#ff3300;" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <? }elseif (in_category('4') ) { ?>
    <h2><a style="color:#c9cc07;" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <? }elseif (in_category('3') ) { ?>
    <h2><a style="color:#0099ff;" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <? } else {}?>
    
    <p><?php the_excerpt() ?> <a style="color:#ff3300; text-decoration:none;" href="<?php the_permalink() ?>"><strong>MORE...</strong></a><br />
    <div id="posted">Posted in <?php the_category(', ') ?></div></p>
    </div>
    <div class="space2"></div>
    </div>
    <?php endwhile; ?>

    At the moment, it doesn’t show the title/permalink or the excerpt, but shows the “More…” link and the category it’s posted in.

    I was wondering whether anyone could give me some pointers?

    Thankyous~

Viewing 2 replies - 1 through 2 (of 2 total)
  • The in_category() function needs either a named category (between quotes), or an numerical ID (without quotes).

    In your case you’re trying to find a category with the name ‘5’, not with the ID 5.

    Peter

    Thread Starter neon_dannii

    (@neon_dannii)

    ah, I see, silly me, I’ll try it out, thanks ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘archive.php – colour coded according to category’ is closed to new replies.