我有一个页面,其中有很多项目来自帖子。
我将它设置为一次只显示10个帖子,但我的上一个/下一个按钮实际上并没有显示下一个或上一个帖子 - 它只是一直显示相同的帖子。
这是我写的函数:
function add_shop() {
if (is_page('shop') || is_page('7')) { ?>
<div id="content">
<div class="post_box">
<div id="column_1">
<div id="shop_wrapper">
<?php query_posts('tag=shop&orderby=title&order=ASC&posts_per_page=10');
if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="shop_item"> <a href="<?php getCustomField('link_to_project_page'); ?>"><img src="<?php getCustomField('shop_thumbnail_image'); ?>" alt='photo of <?php getCustomField('title'); ?>' class="shop_thumb" /></a>
<div class="shop_content">
<h4><a href="<?php getCustomField('link_to_project_page'); ?>">
<?php getCustomField('title'); ?>
</a></h4>
<?php getCustomField('duration'); ?>
<?php getCustomField('paypal_code'); ?>
</div>
</div>
<?php endwhile; ?>
</div>
<?php posts_nav_link(); ?>
</div>
<?php else : ?>
<h2>Not Found</h2>
<p>Sorry, but you are looking for something that isn't here.</p>
<?php include (TEMPLATEPATH . "/searchform.php"); ?>
<?php endif; ?>
</div>
</div>
<div id="sidebars">
<div id="sidebar_1" class="sidebar">
<ul class="sidebar_list">
<li class="widget">
<div class="widget_box">
<?php dynamic_sidebar(5); ?>
</div>
</li>
</ul>
</div>
</div>
<?php } }
答案 0 :(得分:2)
根据上述帮助,我只是让它使用它:
<?php $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
if ($page == 1) {
query_posts('tag=shop&orderby=title&order=ASC&posts_per_page=10&paged=$page');
} else {
$numposts = get_option('posts_per_page');
// work out offset
$offset = (($page -1) * $numposts); // i.e. page 2 - 1 = 1 * 10 (10 for the number of posts)
query_posts("tag=shop&orderby=title&order=ASC&offset=$offset&paged=$page&showposts=$numposts");
}
if (have_posts()) : ?>
答案 1 :(得分:1)
您手动调用query_posts()
,这将覆盖与提取wordpress尝试发送的帖子相关的所有变量。如果你想保留它已经发送的查询字符串,你应该连接它而不是替换它:
query_posts($query_string.'&tag=shop&orderby=title&order=ASC&posts_per_page=10');
或者,如果您只想包含“页面”变量,请将其包含在$paged
中:
query_posts('tag=shop&orderby=title&order=ASC&posts_per_page=10&paged='.$paged);