php – WordPress next_post_link / previous_post_link不保持在
发布时间:2020-12-13 16:30:49 所属栏目:PHP教程 来源:网络整理
导读:这是我的设置. single.php中 ?php if ( in_category( 'my-category' ) ) { include( TEMPLATEPATH.'/single-my-category.php' ); } else { include( TEMPLATEPATH.'/single-generic.php' ); }? 单我-category.php ?phpif ( have_posts() ) : while (have_pos
这是我的设置.
single.php中 <?php if ( in_category( 'my-category' ) ) { include( TEMPLATEPATH.'/single-my-category.php' ); } else { include( TEMPLATEPATH.'/single-generic.php' ); } ?> 单我-category.php <?php if ( have_posts() ) : while (have_posts()) : the_post(); ?> <?php echo the_title(); ?> <div class="pagination"> <div class="container"> <div class="row"> <div class="next col-xs-6 col-sm-6 col-md-6 col-lg-6"> <?php next_post_link( '%link','<img src="' . get_template_directory_uri() . '/img/cs-left.png" /> PREVIOUS',true ); ?> </div> <div class="previous col-xs-6 col-sm-6 col-md-6 col-lg-6"> <?php previous_post_link( '%link','NEXT <img src="' . get_template_directory_uri() . '/img/cs-right.png" />',true ); ?> </div> </div> </div> </div> <?php endwhile; endif; ?> 这就是我所追踪的 – http://codex.wordpress.org/Function_Reference/next_post_link 我不太清楚我在这里做错了什么,因为某些原因,即使函数的in_same_term参数设置为true,previous_post_link也会将我转到不同类别的帖子. 有任何想法吗? 谢谢.
编辑你的代码块如下.你没有把’.php’放在你的single.php文件的第5行.上一个/下一个帖子将仅显示您指定的类别的职位,其中if语句为single.php(此处为“php”).对于以下示例,我创建了一个目录“template-parts”,并在该目录中创建了两个php文件(“single-my-category.php”和“single-generic.php”).
single.php中 <?php $the_query = new WP_Query( $post ); if (in_category('php')) { include( 'template-parts/single-my-category.php' ); } else { include( 'template-parts/single-generic.php' ); } ?> 单我-category.php if ( have_posts() ) : while (have_posts() ) : the_post(); ?> <?php the_title(); ?> <div class="pagination"> <div class="container"> <div class="row"> <div class="next col-xs-6 col-sm-6 col-md-6 col-lg-6"> <?php next_post_link( '%link',true ); ?> </div> </div> </div> </div> <?php endwhile; endif; ?> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |