Counting in Post List
-
Hi,
I’m not exactly sure how to explain this but I’ll give it a try. The code might help to.I am trying to count at the list of posts goes through so I can change the way it displays based on the post number, like:
<?php $count = 0; $while have posts ?> <?php count++; ?> <?php if(count == 1) ?> //Do this <?php else ?> //Look like this <?php endif; endwhile; ?>Something isn’t working although my code looks that same as it does in other themes I’ve made. Maybe I’m just missing something and some new eyes will help. Here is what I hve
<?php $recent = new WP_Query("cat=7&showposts=4"); $count = 0; while($recent->have_posts()) : $recent->the_post(); ?> <?php $count++; ?> <!-- First Content --> <?php if ($count == 1) : ?> <div id="fragment-1" class="ui-tabs-panel" style=""> <img src="<?php bloginfo('template_directory'); ?>/tools/timthumb.php?src=<?php echo get_post_meta($post->ID, "articleimg", $single = true); ?>&h=250&w=400&zc=1" alt="" /> <div class="info" > <h2><a href="<?php the_permalink(); ?>" ><?php the_title(); ?></a></h2> <p><?php echo $count; ?> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla tincidunt condimentum lacus. Pellentesque ut diam....<a href="#" >read more</a></p> </div> </div> <?php else : ?> <!-- 2-4 Content --> <div id="fragment-<?php echo $count; ?>" class="ui-tabs-panel ui-tabs-hide" style=""> <img src="<?php bloginfo('template_directory'); ?>/tools/timthumb.php?src=<?php echo get_post_meta($post->ID, "articleimg", $single = true); ?>&h=250&w=400&zc=1" alt="" /> <div class="info" > <h2><a href="<?php the_permalink(); ?>" ><?php the_title(); ?></a></h2> <p><?php echo $count; ?> Vestibulum leo quam, accumsan nec porttitor a, euismod ac tortor. Sed ipsum lorem, sagittis non egestas id, suscipit....<a href="#" >read more</a></p> </div> </div> <?php endif; endwhile; ?>Thanks
Grant
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Counting in Post List’ is closed to new replies.