我有一个WordPress网站,在主页上我列出了更多类别的内容。WordPress自定义查询分页
我的问题是,有没有一个插件,我可以分类从一个类别的结果?我的意思是像$this->plugin_paginate('category_id');
或smth?
最好的问候,
我有一个WordPress网站,在主页上我列出了更多类别的内容。WordPress自定义查询分页
我的问题是,有没有一个插件,我可以分类从一个类别的结果?我的意思是像$this->plugin_paginate('category_id');
或smth?
最好的问候,
如果您使用的是标准的WordPress循环,即使有query_posts
为一类,分页是自动的与平时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; ?>
该链接然后进入到进行分页该类别的类别页面:Category Templates « WordPress Codex
我不知道如何在同一页上对不同的分类进行分页。必须是可能的。也许问问Wordpress forums。
这听起来像一个简单的,格式良好的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;
现在,让11日至从3类20个(也就是说,在未来10个),我们将要使用query_posts的)[偏移]参数(:
// 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);?>
?>
是一个以上的查询。和更多类别:) – Uffo 2009-11-19 15:58:28