Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Template Name: List Category Posts Page
- *
- * a page template to incorporate the 'List Category Posts' functionality
- *
- * date parameter added 20/11/2011
- * @package WordPress
- * @subpackage Twenty Ten / Weaver2010
- * @since 3.0.0
- */
- ?>
- <?php if(function_exists('catlist_func')) remove_shortcode( 'catlist', array('ListCategoryPosts', 'catlist_func') ); ?>
- <?php get_header(); ?>
- <div id="container">
- <?php ttw_put_ttw_widgetarea('top-widget-area','ttw-top-widget','ttw_hide_widg_pages'); ?>
- <div id="content">
- <?php the_post(); ?>
- <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
- <h1 class="entry-title"><?php the_title(); ?></h1>
- <div class="entry-content">
- <?php // remove the shortcode section from the page content //
- $the_content = preg_replace('~\[([^\[\]]+)\]~is', '', get_the_content());
- echo apply_filters('the_content', $the_content); ?>
- <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', TTW_TRANS ), 'after' => '</div>' ) ); ?>
- <?php edit_post_link( __( 'Edit', TTW_TRANS ), '<span class="edit-link">', '</span>' ); ?>
- </div><!-- .entry-content -->
- <?php //start of 'List Category Posts' section; // ?>
- <?php //get the shortcode values from the page content, by using a regex //
- preg_match_all('~\[([^\[\]]+)\]~is', get_the_content(), $short); $short = $short[1];
- $shortcode = $short[0];
- preg_match_all('~id=([0-9,]+)\b~is', $shortcode, $id);
- $cat_ids = $id[1][0]; $cat_id = explode(',', $cat_ids);
- preg_match_all('~numberposts=(-([0-9]+)|([0-9]+))\b~is', $shortcode, $numberposts);
- $cat_numbers = $numberposts[1][0];
- if(!$cat_numbers) $cat_numbers = get_option('posts_per_page');
- preg_match_all('~excerpt=(yes|no)\b~is', $shortcode, $excerpt);
- $cat_excerpt = $excerpt[1][0];
- preg_match_all('~date=(yes|no)\b~is', $shortcode, $date);
- $cat_date = $date[1][0];
- //start the 'list category posts' query //
- $temp_post = $post; $temp = $wp_query; //save original query
- $wp_query = new WP_query(array('category__in' => $cat_id, 'posts_per_page' => $cat_numbers, 'paged' => get_query_var('paged') ));
- if( $wp_query->have_posts() ) : ?>
- <div class="entry-content">
- <ul class="lcp_catlist">
- <?php while( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
- <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
- <?php if($cat_date == 'yes') { echo '<span class="lcp-date">'; the_date(); echo '</span>'; } //date output ?>
- <?php if($post->post_excerpt){ //rebuild the 'list catgory posts' excerpt
- $lcp_excerpt = $post->post_excerpt;
- } else {
- $lcp_excerpt = strip_tags($post->post_content); }
- if ( post_password_required($post) ) {
- $lcp_excerpt = __('There is no excerpt because this is a protected post.');
- }
- if (strlen($lcp_excerpt) > 255) {
- $lcp_excerpt = substr($lcp_excerpt, 0, 252) . '...';
- } ?>
- <div class="lcp_excerpt"><?php echo $lcp_excerpt; ?></div>
- </li><br /><br />
- <?php endwhile; ?>
- </ul>
- </div><!-- .entry-content of category posts -->
- <?php if ( $wp_query->max_num_pages > 1 ) : ?>
- <div id="nav-below" class="navigation">
- <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', TTW_TRANS ) ); ?></div>
- <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', TTW_TRANS ) ); ?></div>
- </div><!-- #nav-below -->
- <?php endif; // end of pagination ?>
- <?php $wp_query = $temp; $post = $temp_post; //restore original query ?>
- <?php endif; ?>
- <?php //end of 'List Category Posts' section ?>
- <?php remove_shortcode( 'catlist', 'ListCategoryPostsArgs' );
- if(function_exists('catlist_func')) add_shortcode( 'catlist', array('ListCategoryPosts', 'catlist_func') ); ?>
- </div><!-- #post-<?php the_ID(); ?> -->
- </div><!-- #content -->
- <?php ttw_put_ttw_widgetarea('bottom-widget-area','ttw-bot-widget','ttw_hide_widg_pages'); ?>
- </div><!-- #container -->
- <?php get_sidebar(); ?>
- <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement