Posted By

dallasbpeters on 09/01/10


Tagged

wordpress count posts customposttype


Versions (?)

Wordpress Get Custom Post Type and Count posts for CSS Classes


 / Published in: PHP
 

Used this on the vox site to find a custom post type and then assign a variable to get different classes for the output.

  1. <?php query_posts('post_type=slashies&posts_per_page=3'); ?>
  2. <?php $count = 0; ?>
  3.  
  4. <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
  5. <?php
  6. $extra_class = "";
  7. if($count % 3 == 0){
  8. $extra_class = "alpha";
  9. }elseif($count % 3 == 2){
  10. $extra_class = "omega";
  11. }
  12. ?>
  13. <div class="grid_3 partner <?php echo $extra_class ?>">
  14. <?php if ( has_post_thumbnail()) the_post_thumbnail('220-square'); ?>
  15. <h3><?php the_title();?></h3>
  16. <?php the_content(); ?>
  17. <?php if ( get_post_meta($post->ID, 'partner-website', true) ) : ?>
  18. <p></p><a href="<?php echo get_post_meta($post->ID, 'partner-website', true) ?>" title="<?php the_title();?>" target="_blank" rel="bookmark">Visit Partner Website</a></p>
  19. <?php endif; ?><!-- end link check -->
  20. </div>
  21. <?php $count++ ?>
  22. <?php endwhile; else: ?>
  23. <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
  24. <?php endif; ?>
  25. <?php wp_reset_query(); ?>

Report this snippet  

You need to login to post a comment.