Php 设置wordpress帖子循环的样式
我一直在尝试编辑wordpress博客页面的代码。我有14篇文章,我已经将页面设置为每页显示5篇文章。但是,它不起作用。前5篇文章显示得很好,但当你点击“旧条目”时,什么都没有。我试图让它每页显示5篇文章。代码如下:Php 设置wordpress帖子循环的样式,php,wordpress,loops,Php,Wordpress,Loops,我一直在尝试编辑wordpress博客页面的代码。我有14篇文章,我已经将页面设置为每页显示5篇文章。但是,它不起作用。前5篇文章显示得很好,但当你点击“旧条目”时,什么都没有。我试图让它每页显示5篇文章。代码如下: <div id="blog_content_row"> <div class="container"> <div class="row"> <div class="article edi
<div id="blog_content_row">
<div class="container">
<div class="row">
<div class="article editable">
<div>
<?php
// Title on some archive views
get_template_part( 'parts/title', 'archive');
// display featured sometimes
if (!is_paged() && is_home()) {
$original_query = $wp_query;
$wp_query = null;
$wp_query = new WP_Query(array('posts_per_page' => 5, 'meta_key' => 'featured_post', 'meta_value' => 'true', 'post__not_in' => get_option( 'sticky_posts' )));
if ($wp_query->have_posts()) {
} else {
$wp_query = null;
$wp_query = new WP_Query(array('posts_per_page' => 5, 'post__not_in' => get_option( 'sticky_posts' )));
}
if (have_posts()) {
while (have_posts()) {
the_post();
$nimbus_feature_id = $post->ID;
get_template_part( 'parts/blog', 'featured');
}
} else {
// get_template_part( 'parts/error', 'no_results');
}
get_template_part( 'parts/blog', 'pagination');
$wp_query = null;
$wp_query = $original_query;
wp_reset_postdata();
}
// display author stuff here
if (is_author()) {
get_template_part( 'parts/bio');
}
?>
</div>
</div>
</div>
</div>
</div>
你能告诉我怎么了吗?我认为这可能与$wp_查询有关。有问题的网页是。找到了答案。代码里没有。代码很好。重要的是functions.php 我编辑了它,现在可以用了
但问题是,它一直显示相同的5个帖子,而不是14个不同的帖子。帮助?你知道wordpress模板层次结构吗?如果你的页面被分页,那么什么也不会发生,因为它不符合以下条件:
如果(!is_paged()&&is_home()){
并且你没有其他子句。我将“(!is_paged()&&is_home())”替换为“(have_posts())“现在它可以正常工作了,但是它只显示10篇文章,而不是14篇文章。似乎不管有多少篇文章,如果至少有5篇文章,那么编码的内容都会显示出来。我是否会将其更改为“每页文章数”=5?