Advertisement
tourpro

Daily Digest - Page Template - Last 3 Days

Apr 16th, 2011
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.54 KB | None | 0 0
  1. <?php
  2. /*
  3. Template Name: Front Page -3 days
  4. */
  5. ?>
  6.  
  7. <?php
  8. /**
  9.  * The template for displaying all pages.
  10.  *
  11.  * This is the template that displays all pages by default.
  12.  * Please note that this is the WordPress construct of pages
  13.  * and that other 'pages' on your WordPress site will use a
  14.  * different template.
  15.  *
  16.  * @package WordPress
  17.  * @subpackage Twenty_Ten
  18.  * @since Twenty Ten 1.0
  19.  */
  20.  
  21. get_header(); ?>
  22.  
  23.         <div id="container">
  24.             <div id="content" role="main">
  25.  
  26.             <?php
  27. // list all posts, sectioned by post date
  28. function filter_where($where = '') {
  29.     //posts in the last 3 days
  30.     $where .= " AND post_date > '" . date('Y-m-d', strtotime('-2 days')) . "'";
  31.     return $where;
  32.   }
  33. add_filter('posts_where', 'filter_where');
  34. $args=array(
  35.   'orderby' => 'date',
  36.   'order' => 'DESC',
  37.   'posts_per_page'=>-1,
  38.   'caller_get_posts'=>1
  39. );
  40. $my_query = new WP_Query($args);
  41. if( $my_query->have_posts() ) {
  42.   while ($my_query->have_posts()) : $my_query->the_post();
  43.     $this_date =  get_the_time(__('l d F Y'));
  44.     if ($this_date != $last_date) {
  45.       $last_date = $this_date;
  46.       echo '<h2>'.$last_date.'</h2>';
  47.     } ?>
  48.     <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a><br /><?php the_content(); ?></p>
  49.     <?php
  50.   endwhile;
  51. } //if ($my_query)
  52. wp_reset_query();  // Restore global post data stomped by the_post().
  53. ?>
  54.  
  55.             </div><!-- #content -->
  56.         </div><!-- #container -->
  57.  
  58. <?php get_sidebar(); ?>
  59. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement