Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php /* Assign a class to each div in a foreach loop for the following blog post:
- http://www.worldoweb.co.uk/2012/display-your-wordpress-recent-posts-on-a-static-page
- */
- $args = array( 'numberposts' => 3, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
- $postslist = get_posts( $args );
- $count = 0; // set up a post counter
- $class = '';
- foreach ($postslist as $post) : setup_postdata($post);
- $count++;
- switch ($count) {
- case 1:
- $class = ' class="one"';// change div class here and below to suit your needs
- break;
- case 2:
- $class = ' class="two"';
- break;
- case 3:
- $class = ' class="three"';
- break;
- default:
- $class= ' class="other_div"';//added default div as an example
- break;
- }//end switch?>
- <div <?php echo $class ; ?>>
- <strong><?php echo get_the_date(); ?></strong>
- <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
- </div>
- <?php endforeach; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement