我正在创建一个wordpress主题,其中有一个名为“的页面”blog“这将显示我所有最新的博客帖子。在这里,我每页仅显示5篇帖子,我希望在第一页中只显示”Newer“链接,在第二页中,它将显示“旧”和“新”链接,并且”Older“上一页上的链接如this. 在这里,我使用以下代码来完成我的任务,但它并没有按预期工作。
这是我在中使用的函数functions.php 更改自定义帖子类型“blog“。但这也不起作用,它显示没有帖子,而不是我在这里设置的5个帖子。
// ----------------------- Set the number of a custom post type posts per page
add_filter( \'pre_get_posts\', \'be_archive_query\' );
function be_archive_query( $query ) {
if( $query->is_post_type_archive(\'blog\') ) {
$query->set( \'posts_per_page\', 5 );
}
}
这是我的
page-blog.php<div class="post-content">
<?php
if(have_posts()) {
while(have_posts()) {
the_post();
$link = get_permalink();
echo "<div id=\'bl-post\'>";
echo "<div class=\'thumb\'>";
echo "<a href=$link>";
if(has_post_thumbnail()) {
the_post_thumbnail();
}
echo "</a>";
echo "</div>";
echo "<div class=\'cont\'>";
echo "<h2 class=\'bl-post-title\'><a href=$link>";
the_title();
echo "</a></h2>";
echo "<p>";
$excerpt = get_the_excerpt();
echo string_limit_words($excerpt,30);
echo "</p>";
echo "<a href=$link id=\'cont-read\'>";
_e(\'Read More\',\'nss-framework\');
echo "</a>";
echo "</div>";
echo "</div>";
}
?>
<div class="clr"></div>
<ul class="sl-navi">
<li>
<a data-hover="Previous" href="#">
<span><?php next_posts_link(__(\'Older\',\'nss-framework\')); ?></span>
</a>
</li>
<li>
<a data-hover="Next" href="#">
<span><?php previous_posts_link(__(\'Newer\',\'nss-framework\')); ?></span>
</a>
</li>
</ul>
<?php
}
?>
</div>
这是我的
single-blog.html<div class="clr"></div>
<ul class="sl-navi">
<li>
<a data-hover="Previous" href="#">
<span>Previous</span>
</a>
</li>
<li>
<a data-hover="Next" href="#">
<span>Next</span>
</a>
</li>
</ul>
Expected previews
第1页

第2页

最后一页

但是,在wp中,我得到ds

使用后,我还检查了html部分next_posts_link()
和previous_posts_link()
函数和我得到了这个(span标记之间没有显示任何内容)
我应该做哪些更改?
