[英]wordpress 3.5 pagination
我使用的是wordpress 3.4 = 5,我在其中使用代码来获取帖子,但是分页对此不起作用,请帮助
$posts = get_posts('category='.$subcatid.'&orderby=rand&numberposts=4');
foreach($posts as $post) { ?>
<h2>
<a href="<?php the_permalink() ?>" target="_parent"><?php the_title(); ?></a>
</h2>
<p><?php //echo $post->post_content; ?></p>
<p><?php echo get_post_meta($post->ID, 'Address', true); ?></p>
<hr style="margin-left:0px; margin-right:0px; margin-bottom:15px; margin-top:15px;" />
<?php } ?>
分页不适用于get_posts()。 因为您已经修改了普通循环iter。
您可以这样做,并为此使用wp-pagenavi插件
<?php get_query_var('paged');
query_posts('cat='.$subcatid.'&posts_per_page=2');
if (have_posts()) : while (have_posts()) : the_post();
?>
<h2>
<a href="<?php the_permalink() ?>" target="_parent"><?php the_title(); ?></a>
</h2>
<p><?php echo get_post_meta($post->ID, 'Address', true); ?></p>
<hr style="margin-left:0px; margin-right:0px; margin-bottom:15px; margin-top:15px;" />
<?php endwhile;
if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>
<?php
endif; ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.