我有以下循环(这是在single
页面,而不是index.php
):
$top_meta_cat_args =
array(
\'posts_per_page\' => 9,
\'post_type\' => \'post\',
\'meta_key\' => \'top-radio\',
\'meta_value\' => \'top-yes\',
\'post_status\' => \'publish\',
\'orderby\' => \'date\',
\'order\' => \'DESC\'
);
它工作得很好。但是,当我添加代码将用户带到下一页时,什么都没有发生:
<a href="<?php echo get_next_posts_page_link(); ?>" class="btn-ar"> more articles</a>
这将添加到当前URL:
&paged=3
, 但是内容还是一样的。
我还尝试删除echo
, 但什么都没发生。The Codex explains about adding pagination. 但我不确定如何将其用于上面示例的关联数组。
任何帮助都会很好。
SO网友:Sam
像这样试一下:
<?php
// Get header
get_header(); ?>
<?php // Begin loop
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$args = array (
\'posts_per_page\' => 1,
\'paged\' => $paged
);
query_posts($args);
if (have_posts()) : while (have_posts()) : the_post();
?>
<article>
<h1><?php the_title(); ?></h1>
<p class="time"><?php the_time(\'l, F jS, Y\'); ?></p>
<?php the_content(); ?>
</article>
<?php endwhile; ?>
<nav>
<ul>
<li><?php previous_posts_link(\'< previous page\', 0); ?></li>
</li><?php next_posts_link(\'next page >\', 0); ?></li>
</ul>
</nav>
<?php else: endif; ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
SO网友:user48752
这对我有用。试试看,也许对你也有用。
$paged = (get_query_var("paged")) ? get_query_var("paged") : 1;
$args = array(
\'paged\' => $paged,
\'posts_per_page\' =>9,
\'post_status\' => \'publish\',
\'orderby\' => \'date\',
\'order\' => \'DESC\'
);
$posts = query_posts($args);
<?php
global $post;
if ( ! empty($posts) ) :
foreach ($posts as $post) {
setup_postdata($post);
?>
<a title="<?php echo \'\'.get_the_title(); ?>" href="<?php echo get_permalink($post->ID); ?>">
<?php }
else : ?>
<p><?php _e(\'Sorry, no posts matched your criteria.\'); ?></p>
<?php endif; ?>
<<?php echo get_next_posts_link(); ?></div>
<?php echo get_previous_posts_link(); ?></div>
<?php wp_reset_postdata();?>