Advertisement
alchymyth

pagofposts.php with date parameter

Nov 20th, 2011
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.18 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Template Name: List Category Posts Page
  4.  *
  5.  * a page template to incorporate the 'List Category Posts' functionality
  6.  *
  7.  * date parameter added 20/11/2011
  8.  * @package WordPress
  9.  * @subpackage Twenty Ten / Weaver2010
  10.  * @since 3.0.0
  11.  */
  12. ?>
  13. <?php if(function_exists('catlist_func')) remove_shortcode( 'catlist', array('ListCategoryPosts', 'catlist_func') ); ?>
  14.    
  15. <?php get_header(); ?>
  16.     <div id="container">
  17.     <?php ttw_put_ttw_widgetarea('top-widget-area','ttw-top-widget','ttw_hide_widg_pages'); ?>
  18.     <div id="content">
  19.  
  20.         <?php the_post(); ?>
  21.         <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  22.            
  23.             <h1 class="entry-title"><?php the_title(); ?></h1>
  24.            
  25.             <div class="entry-content">
  26.                 <?php // remove the shortcode section from the page content //
  27.                 $the_content = preg_replace('~\[([^\[\]]+)\]~is', '', get_the_content());
  28.                 echo apply_filters('the_content', $the_content); ?>
  29.                 <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', TTW_TRANS ), 'after' => '</div>' ) ); ?>
  30.                 <?php edit_post_link( __( 'Edit', TTW_TRANS ), '<span class="edit-link">', '</span>' ); ?>
  31.             </div><!-- .entry-content -->
  32.        
  33. <?php //start of 'List Category Posts' section; // ?>
  34.  
  35.             <?php //get the shortcode values from the page content, by using a regex //
  36.             preg_match_all('~\[([^\[\]]+)\]~is', get_the_content(), $short); $short = $short[1];
  37.             $shortcode = $short[0];
  38.             preg_match_all('~id=([0-9,]+)\b~is', $shortcode, $id);
  39.             $cat_ids = $id[1][0]; $cat_id = explode(',', $cat_ids);
  40.             preg_match_all('~numberposts=(-([0-9]+)|([0-9]+))\b~is', $shortcode, $numberposts);
  41.             $cat_numbers = $numberposts[1][0];
  42.             if(!$cat_numbers) $cat_numbers = get_option('posts_per_page');
  43.             preg_match_all('~excerpt=(yes|no)\b~is', $shortcode, $excerpt);
  44.             $cat_excerpt = $excerpt[1][0];
  45.            
  46.             preg_match_all('~date=(yes|no)\b~is', $shortcode, $date);
  47.             $cat_date = $date[1][0];
  48.  
  49.             //start the 'list category posts' query //         
  50.             $temp_post = $post; $temp = $wp_query; //save original query
  51.             $wp_query = new WP_query(array('category__in' => $cat_id, 'posts_per_page' => $cat_numbers, 'paged' => get_query_var('paged') ));
  52.             if( $wp_query->have_posts() ) : ?>
  53.             <div class="entry-content">
  54.             <ul class="lcp_catlist">
  55.             <?php while( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
  56.             <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
  57.             <?php if($cat_date == 'yes') { echo '<span class="lcp-date">'; the_date(); echo '</span>'; } //date output ?>
  58.             <?php if($post->post_excerpt){ //rebuild the 'list catgory posts' excerpt
  59.                     $lcp_excerpt = $post->post_excerpt;
  60.             } else {
  61.             $lcp_excerpt = strip_tags($post->post_content); }
  62.             if ( post_password_required($post) ) {
  63.                     $lcp_excerpt = __('There is no excerpt because this is a protected post.');
  64.             }
  65.             if (strlen($lcp_excerpt) > 255) {
  66.                     $lcp_excerpt = substr($lcp_excerpt, 0, 252) . '...';
  67.             } ?>
  68.             <div class="lcp_excerpt"><?php echo $lcp_excerpt; ?></div>
  69.             </li><br /><br />
  70.             <?php endwhile; ?>
  71.             </ul>
  72.             </div><!-- .entry-content of category posts -->
  73.            
  74.         <?php if (  $wp_query->max_num_pages > 1 ) : ?>
  75.         <div id="nav-below" class="navigation">
  76.         <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', TTW_TRANS ) ); ?></div>
  77.         <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', TTW_TRANS ) ); ?></div>
  78.         </div><!-- #nav-below -->
  79.         <?php endif; // end of pagination ?>
  80.             <?php $wp_query = $temp; $post = $temp_post; //restore original query ?>
  81.             <?php endif; ?>
  82.            
  83. <?php //end of 'List Category Posts' section ?>
  84. <?php remove_shortcode( 'catlist', 'ListCategoryPostsArgs' );
  85. if(function_exists('catlist_func')) add_shortcode( 'catlist', array('ListCategoryPosts', 'catlist_func') ); ?>
  86.  
  87.             </div><!-- #post-<?php the_ID(); ?> -->
  88.        
  89.     </div><!-- #content -->
  90.     <?php ttw_put_ttw_widgetarea('bottom-widget-area','ttw-bot-widget','ttw_hide_widg_pages'); ?>
  91.     </div><!-- #container -->
  92. <?php get_sidebar(); ?>
  93. <?php get_footer(); ?>
  94.  
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement