WordPress.org

Support

Support » How-To and Troubleshooting » Conditional CSS for individual posts

Conditional CSS for individual posts

  • I don’t know if I can do this, but I want to be able to show different css styling for select posts on a category or archive page.

    On my category pages, as can be seen here, I want to be able to add a category to a specific post and have it show “recommended” on the category page.

    I thought I could do a conditional is_category statement like this but wasn’t sure

    <?php /* If this is a category archive */ if (is_category('recommended')) {

    <div class="special"><?php while (have_posts()) : the_post(); ?>

    <?php echo wptexturize(the_excerpt_reloaded()); ?>
    <code><?php endwhile; ?></code>
    </div>
    
    <code>} else {</code>
    <code><div class=&quot;regular&quot;><?php while (have_posts()) : the_post(); ?></code>

    <?php echo wptexturize(the_excerpt_reloaded()); ?>
    <?php endwhile; ?>
    </div>
    }
    ?>

    Is this possible or should I use the in_category v. the is_category?

    Is there a limit to how many conditional if statements I can have in one php file? I know my questions sound very rudimentary.

  • The topic ‘Conditional CSS for individual posts’ is closed to new replies.
Skip to toolbar