Question

I'm trying to display categories in a list form. Basically, every category (item) in the loop has different style. So I need to display item 1 in one style, item 2, 3, 4 in another style and rest of the items in another style. How do I frame the wordpress for loop structure?

<?php 
if ( have_posts() ) {
    while ( have_posts() ) {
        the_post(); 
        // My Content
    } // end while
} // end if
?>
Was it helpful?

Solution

<?php $i=1; if (have_posts()): while ( have_posts() ) : the_post();
if($i==1){ ?> 
... code for the first post ... 
<?php } if(($i>1)&&($i<5)) { ?>
... code for 2nd, 3rd, 4th post ...
<?php } if($i>4) { ?>
... code for 5th, 6th, 7th, 8th post ...
<?php } $i++; endwhile; endif; ?>

^ This is to display posts with different styles

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top