Advertisement
masonjames

WordPress Loop shortcode for all of today's posts with image

Jun 12th, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function myLoop($atts, $content = null) {
  2.     extract(shortcode_atts(array(
  3.         "pagination" => 'true',
  4.         "query" => '',
  5.         "category" => '',
  6.     ), $atts));
  7.    
  8.     global $wp_query,$paged,$post;
  9.     $temp = $wp_query;
  10.     $today = getdate();
  11.     $wp_query = new WP_Query( 'year=' . $today["year"] . '&monthnum=' . $today["mon"] . '&day=' . $today["mday"] );
  12.     if($pagination == 'true'){
  13.         $query .= '&paged='.$paged;
  14.     }
  15.     if(!empty($category)){
  16.         $query .= '&category_name='.$category;
  17.     }
  18.     if(!empty($query)){
  19.         $query .= $query;
  20.     }
  21.  
  22.     ob_start();
  23.     ?>
  24.     <h2><?php echo $category; ?></h2>
  25.     <ul class="loop">
  26.     <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
  27.         <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php echo the_post_thumbnail('thumbnail'); the_title(); ?></a></li>
  28.     <?php endwhile; ?>
  29.     </ul>
  30.     <?php if(pagination == 'true'){ ?>
  31.     <div class="navigation">
  32.       <div class="alignleft"><?php previous_posts_link('« Previous') ?></div>
  33.       <div class="alignright"><?php next_posts_link('More »') ?></div>
  34.     </div>
  35.     <?php } ?>
  36.     <?php $wp_query = null; $wp_query = $temp;
  37.     $content = ob_get_contents();
  38.     ob_end_clean();
  39.     return $content;
  40. }
  41. add_shortcode("loop", "myLoop");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement