• Resolved veronique-m

    (@veronique-m)


    hello

    would there be a way to write sthg like that on the index page:

    <?php while (have_posts()) : the_post(); ?>
    <div class="post<? if ($cat == '7') echo 'cat7'; ?>">

    which would write :

    <div class="postcat7">

    for any post of cat 7

    and so have different styles on the index page (as well) regarding to categories (chosing the first one, for inst. if there are many categories for a post)

    how would i get to know what category i am on the index

    this must be possible

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter veronique-m

    (@veronique-m)

    ok, i did this


    <?php while (have_posts()) : the_post(); ?>
    <?php
    foreach((get_the_category()) as $cat) {
    if ($cat->cat_ID=="8") $pano="yes";
    }
    if ($pano=="yes") $class="pano";
    else $class= "entry";
    ?>

    there must be more beautiful ways to do it but i’m no champion in php
    and this works fine

    nmallory

    (@nmallory)

    or you could use in_category() if you aren’t using the adhesive plugin:

    <?php while (have_posts()) : the_post(); ?>

    <?php if in_category(7) : ?>

    <div class=”postcat7″>

    <?php else : ?>

    <div class=”post”>

    <? endeif; ?>

    Thread Starter veronique-m

    (@veronique-m)

    yes of course, that’s much much better

    (i’m stupid)

    i’ve just found it aswell…


    <?php if ( in_category('8') ) { ?>
    <div class="pano">
    <?php } else { ?>
    <div class="entry">
    <?php } ?>

    THANKS

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘different class/styles on index page regarding to categories’ is closed to new replies.