简体   繁体   English

wordpress 3.5分页

[英]wordpress 3.5 pagination

I am using wordpress 3.4=5 where i have used code to get posts , but pagination is not working for this ,please help 我使用的是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 } ?>

Pagination doesn't work with get_posts() . 分页不适用于get_posts()。 Because you have modified the normal loop iter . 因为您已经修改了普通循环iter。

You Can do it like this, and use wp-pagenavi plugin for this 您可以这样做,并为此使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM