我有一个 WordPress 网站,在主页上我列出了更多类别的内容。
我的问题是,有没有一个插件可以让我对某个类别的结果进行分页?我的意思是什么$this->plugin_paginate('category_id');
?
此致,
我有一个 WordPress 网站,在主页上我列出了更多类别的内容。
我的问题是,有没有一个插件可以让我对某个类别的结果进行分页?我的意思是什么$this->plugin_paginate('category_id');
?
此致,
如果您使用标准的 Wordpress 循环,即使使用query_posts
for 类别,分页也是自动使用通常的posts_nav_link
. 您是否尝试在同一页面上为多个查询和多个类别分页?
编辑 11/20:我在一个页面的几个不同位置使用它来显示一个类别中的最新帖子:
<?php
$my_query = new WP_Query('category_name=mycategory&showposts=1');
while ($my_query->have_posts()) : $my_query->the_post();
?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
<?php endwhile; ?>
然后该链接转到为该类别分页的类别页面:类别模板«WordPress Codex
我不知道如何在同一页面上对不同类别进行分页。必须是可能的。也许在Wordpress 论坛中询问。
这听起来像是一个简单的、格式良好的 query_posts() 调用就可以做到的事情。我怀疑你甚至需要依赖插件。:)
我将假设您熟悉 query_posts() 函数,所以让我们继续使用这个示例作为基础:
// let's get the first 10 posts from category ID 3
query_posts('posts_per_page=10&cat=3');
while(have_posts()):the_post();
// do Wordpress magic right here
endwhile;
现在,要从类别 3 中获取第 11 到第 20 个帖子(即 NEXT 10 个帖子),我们将要使用 query_posts() 的 [offset] 参数:
// let's get the next 10 posts from category ID 3
query_posts('posts_per_page=10&cat=3&offset=10');
while(have_posts()):the_post();
// do Wordpress magic right here
endwhile;
对于大多数目的,这应该足够了。但是,您确实提到您计划仅从主页对类别帖子列表进行分页?我假设您的意思是您的主页上有多个类别的帖子列表,并且所有这些都是独立分页的。
有了类似的东西,看起来您必须使用 Javascript 来为您完成工作,以及我上面说明的内容。
我相信你可以做这样的事情:
<?php
if(isset($_GET['paged'])){
$page = $_GET['paged']-1;
}else{
$page = 0;
}
$postsPerPage = 5;
$theOffset = $page*$postsPerPage;
?>
<?php query_posts(array('posts_per_page' => $postsPerPage, 'cat' => CATEGORIES HERE, 'offset' => $theOffset)); ?>
希望对你有帮助 :)
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => 5,
'paged' => $page,
);
query_posts($args);?>
?>