This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

WP Shortcode to add all today's posts to any wordpress page

By: masonjames on May 28th, 2012  |  syntax: PHP  |  size: 1.17 KB  |  views: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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 $thumbnail_image; 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");
clone this paste RAW Paste Data