我的网站上有三个页面(Listen、Read、Watch),每个页面分别查询不同的帖子类别:“Listen”、“Read”和“Watch”。我创建了三个单独的php文件,它们有自己独特的模板名称,我在wp admin中创建了一个页面,并为每个文件选择了适当的模板。我多次使用下面的查询时遇到问题。例如,Listen页面将通过分页成功查询“Listen”类别;但是,我无法在其他两页上使用相同的代码。
<?php
/*
Template Name: Listen
*/
?>
<!-- header.php -->
<?php get_header(); ?>
<!-- /header.php -->
<!-- 960 16 Column Grid -->
<div class="container_16">
<!-- Featured News -->
<section class="grid_10 read">
<!-- Featured News Heading -->
<h1></h1>
<!-- /Featured News Heading -->
<!-- Featured News Loop -->
<?php
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$args=array(
\'post_type\'=>\'post\',
\'cat\' => \'listen\',
\'posts_per_page\' => 5,
\'paged\'=>$paged
);
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query($args);
if (function_exists(\'wp_pagenavi\')) { wp_pagenavi(); }
if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post();
?>
<!-- Post -->
<article class="post">
<!-- Featured News Title -->
<span><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( \'%s\', \'twentyten\' ), the_title_attribute( \'echo=0\' ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
</span>
<!-- /Featured News Title -->
<!-- Featured News Meta -->
<p class="featured-news-post-meta">By <span class="featured-news-author"><?php echo get_the_author(); ?></span> / <?php echo get_the_date(\'d.m.Y\'); ?>
</p>
<!-- /Featured News Meta -->
<!-- Featured News Thumbnail -->
<?php the_post_thumbnail(array(640,320)); ?>
<!-- /Featured News Thumbnail -->
<!-- Featured News Excerpt -->
<p class="featured-news-excerpt"><?php the_excerpt(); ?></p>
<!-- /Featured News Excerpt -->
<!-- Featured News Social Links -->
<?php include(\'includes/social.php\'); ?>
<!-- /Featured News Social Links -->
</article>
<!-- /Post -->
<?php endwhile; endif; ?>
<!-- /Featured News Loop -->
<!-- Pagination -->
<?php if ($wp_query->max_num_pages > 1) : ?>
<div class="grid_10 pagination older-news">
<?php next_posts_link( __( \'<span class="arrow">←</span> Older News\', \'twentyten\' ) ); ?>
<div class="pagination newer-news">
<?php previous_posts_link( __( \'Newer News <span class="arrow">→</span>\', \'twentyten\' ) ); ?>
</div>
</div>
<?php endif; ?>
<!-- /Pagination -->
<?php
/* PageNavi at Bottom */
if (function_exists(\'wp_pagenavi\')){wp_pagenavi();}
$wp_query = null;
$wp_query = $temp;
wp_reset_query();
?>
<!-- /Featured News Loop -->
</section>
<!-- /Featured News -->
<!-- Other News -->
<aside class="grid_5 other-news read-other-news">
<!-- Other News Heading -->
<h3></h3>
<!-- /Other News Heading -->
<!-- Other News Loop -->
<?php query_posts(\'category_name=other-news&showposts=6\'); ?>
<?php while (have_posts()) : the_post(); ?>
<!-- Other News List -->
<ul>
<li><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( \'Permalink to %s\', \'twentyten\' ), the_title_attribute( \'echo=0\' ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
</li>
<li class="other-news-post-date"><?php echo get_the_date(\'d.m.Y\'); ?>
</li>
</ul>
<!-- /Other News List -->
<?php endwhile; ?>
<!-- /Other News Loop -->
<!-- View More -->
<div class="view-more">
<a href="/other-news">View More →</a>
<div>
<!-- /View More -->
</aside>
<!-- /Other News -->
</div>
<!-- /960 16 Column Grid -->
<!-- sidebar.php -->
<?php get_sidebar(); ?>
<!-- /sidebar.php -->
<!-- footer.php -->
<?php get_footer(); ?>
<!-- /footer.php -->