I am using wordpress 3.4=5 where i have used code to get posts , but pagination is not working for this ,please help
$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() . Because you have modified the normal loop iter .
You Can do it like this, and use wp-pagenavi plugin for this
<?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; ?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.