Advertisement
alchymyth

List Category Posts Page template

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