Posted By

alexeihidalgo on 04/04/11


Tagged


Versions (?)

Category loop in wordpress


 / Published in: PHP
 

  1. <!-- Start the Loop. -->
  2. <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
  3.  
  4. <!-- The following tests if the current post is in category 3. -->
  5. <!-- If it is, the div box is given the CSS class "post-cat-three". -->
  6. <!-- Otherwise, the div box will be given the CSS class "post". -->
  7. <?php if ( in_category('3') ) { ?>
  8. <div class="post-cat-three">
  9. <?php } else { ?>
  10. <div class="post">
  11. <?php } ?>
  12.  
  13. <!-- Display the Title as a link to the Post's permalink. -->
  14. <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
  15.  
  16. <!-- Display the Time. -->
  17. <small><?php the_time('F jS, Y'); ?></small>
  18.  
  19. <!-- Display the Post's Content in a div box. -->
  20. <div class="entry">
  21. <?php the_content(); ?>
  22. </div>
  23.  
  24. <!-- Display a comma separated list of the Post's Categories. -->
  25. <p class="postmetadata">Posted in <?php the_category(', '); ?></p>
  26. </div> <!-- closes the first div box -->
  27.  
  28. <!-- Stop The Loop (but note the "else:" - see next line). -->
  29. <?php endwhile; else: ?>
  30.  
  31. <!-- The very first "if" tested to see if there were any Posts to -->
  32. <!-- display. This "else" part tells what do if there weren't any. -->
  33. <p>Sorry, no posts matched your criteria.</p>
  34.  
  35. <!-- REALLY stop The Loop. -->
  36. <?php endif; ?>

Report this snippet  

You need to login to post a comment.