我的分类页面导航似乎根本没有显示,我的编码中缺少了什么?
<?php get_header(); ?>
<div class="inner-page">
<div class="page-spacer"></div>
<!-- Content Start -->
<div id="content-top"></div>
<div id="category-content-wrapper">
<div id="category-content" role="main">
<?php if ( have_posts() ) : ?>
<header class="page-header">
<div class="page-title category-title">
<h1>
<?php
printf( __( \'%s\', \'rsi\' ), \'\' . single_cat_title( \'\', false ) . \'\' );
?>
</h1>
</div>
<?php
$category_description = category_description();
if ( ! empty( $category_description ) )
echo apply_filters( \'category_archive_meta\', \'<div class="category-archive-meta">\' . $category_description . \'</div>\' );
?>
</header>
<?php wp_pagenavi() ?>
<?php /* Start the Loop */ ?>
<?php
$args = array( \'category\' => 5 );
$lastposts = get_posts( $args );
foreach($lastposts as $post) : setup_postdata($post); ?>
<div class="post-holder">
<?php if (has_post_thumbnail( $post->ID ) ): ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), \'single-post-thumbnail\' ); ?>
<a href="<?php the_permalink(); ?>">
<div id="custom-bg" style="background-image: url(\'<?php echo $image[0]; ?>\')"> </div>
</a>
<?php endif; ?>
<div class="blog-title">
<h2><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></h2>
</div>
<div class="blog-excerpt">
<?php the_excerpt(); ?>
</div>
<div class="blog-date"> Posted on:
<?php the_date(); ?>
</div>
</div>
<?php endforeach; ?>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title">
<?php _e( \'Nothing Found\', \'rsi\' ); ?>
</h1>
</header>
<!-- .entry-header -->
<div class="entry-content">
<p>
<?php _e( \'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.\', \'rsi\' ); ?>
</p>
<?php get_search_form(); ?>
</div>
<!-- .entry-content -->
</article>
<!-- #post-0 -->
<?php endif; ?>
<?php wp_pagenavi() ?>
</div>
<!-- #content -->
<div id="sidebar">
<?php if (!function_exists(\'dynamic_sidebar\') || !dynamic_sidebar(\'Right Sidebar\')) : ?>
<?php endif; ?>
</div>
<div class="clear-block"></div>
</div>
<div class="clear-block"></div>
</div>
<div class="clear-block"></div>
<div id="content-bottom"></div>
<!-- Content End -->
</div>
<?php get_footer(); ?>
最合适的回答,由SO网友:kovshenin 整理而成
你应该仔细看看[http://codex.wordpress.org/Template_Hierarchy模板层次结构]。根据我在代码中的理解,您试图在ID=5的类别中列出帖子。您可以轻松地将其映射到category-slug.php
或category-id.php
模板文件,因此您无需执行任何额外操作get_posts
.
分页的问题是wp_pagenavi
正在寻找您的$wp_query
全局并对原始查询(不进行筛选)进行分页或者,唯一的原因可能是您的WP PageNavi插件未安装或禁用;)