主页上的分页WordPress

【主页上的分页WordPress】我在尝试分页以便在我正在工作的网站的主页上工作时遇到问题。
这是我正在使用的代码, 当然已简化:
如何对此进行分页?

< ?php $args = array('cat' => '3, 7, 10, 12', 'posts_per_page'=> 3); ?> < ?php query_posts($args); ?> < ?php if (have_posts()) : while (have_posts()) : the_post(); ?> < article class="col-md-12"> < a href="http://www.srcmini.com/< ?php the_permalink(); ?>" > < div class="image"> < img class="img-responsive" src="http://www.srcmini.com/< ?php echo the_post_thumbnail_url('medium' ); ?> "> < /div> < /a> < div class="entry entry-table"> < div class="title"> < a href="http://www.srcmini.com/< ?php the_permalink(); ?>" > < h3 class="h5"> < ?php the_title(); ?> < /h3> < /a> < span class="cateogry< ?php echo get_the_category( $id )[0]-> cat_ID; ?> "> < ?php echo get_the_category( $id )[0]-> name; ?> < /span> < p> < ?php echo get_excerpt(228, 'content'); ?> < a class="linkmore" href="http://www.srcmini.com/< ?php the_permalink() ?>"> Czytaj dalej ...< /a> < /p> < /div> < /div> < /article> < ?php endwhile; endif; ?>

#1
< ?php $args = array('cat' => '3, 7, 10, 12', 'posts_per_page'=> 3); ?> < ?php query_posts($args); ?> < ?php if (have_posts()) : while (have_posts()) : the_post(); ?> < article class="col-md-12"> < a href="http://www.srcmini.com/< ?php the_permalink(); ?>" > < div class="image"> < img class="img-responsive" src="http://www.srcmini.com/< ?php echo the_post_thumbnail_url('medium' ); ?> "> < /div> < /a> < div class="entry entry-table"> < div class="title"> < a href="http://www.srcmini.com/< ?php the_permalink(); ?>" > < h3 class="h5"> < ?php the_title(); ?> < /h3> < /a> < span class="cateogry< ?php echo get_the_category( $id )[0]-> cat_ID; ?> "> < ?php echo get_the_category( $id )[0]-> name; ?> < /span> < p> < ?php echo get_excerpt(228, 'content'); ?> < a class="linkmore" href="http://www.srcmini.com/< ?php the_permalink() ?>"> Czytaj dalej ...< /a> < /p> < /div> < /div> < /article> < ?php endwhile; ?> < div class="navigation"> < div class="alignleft"> < ?php previous_posts_link('& laquo; Previous') ?> < /div> < div class="alignright"> < ?php next_posts_link('More & raquo; ') ?> < /div> < /div> < ?php endif; ?>

#2首先, 你必须正确设置查询:
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $args = array('cat' => '3, 7, 10, 12', 'posts_per_page'=> 3, 'paged' => $paged);

其次, 你需要在循环外添加分页链接
< div class="navigation"> < div class="alignleft"> < ?php previous_posts_link('& laquo; Previous') ?> < /div> < div class="alignright"> < ?php next_posts_link('More & raquo; ') ?> < /div> < /div>

整个代码如下所示:
< ?php $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $args = array('cat' => '3, 7, 10, 12', 'posts_per_page'=> 3, 'paged' => $paged); ?> < ?php query_posts($args); ?> < ?php if (have_posts()) : while (have_posts()) : the_post(); ?> < article class="col-md-12"> < a href="http://www.srcmini.com/< ?php the_permalink(); ?>" > < div class="image"> < img class="img-responsive" src="http://www.srcmini.com/< ?php echo the_post_thumbnail_url('medium' ); ?> "> < /div> < /a> < div class="entry entry-table"> < div class="title"> < a href="http://www.srcmini.com/< ?php the_permalink(); ?>" > < h3 class="h5"> < ?php the_title(); ?> < /h3> < /a> < span class="cateogry< ?php echo get_the_category( $id )[0]-> cat_ID; ?> "> < ?php echo get_the_category( $id )[0]-> name; ?> < /span> < p> < ?php echo get_excerpt(228, 'content'); ?> < a class="linkmore" href="http://www.srcmini.com/< ?php the_permalink() ?>"> Czytaj dalej ...< /a> < /p> < /div> < /div> < /article> < ?php endwhile; ?> < div class="navigation"> < div class="alignleft"> < ?php previous_posts_link('& laquo; Previous') ?> < /div> < div class="alignright"> < ?php next_posts_link('More & raquo; ') ?> < /div> < /div> < ?php endif; ?>

#3问题已解决:
< ?php global $paged, $wp_query, $wp; $args1 = array('cat' => '3, 7, 10, 12'); $args = wp_parse_args($wp-> matched_query); if ( !empty ( $args['paged'] ) & & 0 == $paged ) { $wp_query-> set('paged', $args['paged']); $paged = $args['paged']; } $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query-> query('paged='.$paged.'& showposts=3& cat=3, 7, 10, 12'); ?> < ?php while ($wp_query-> have_posts()) : $wp_query-> the_post(); ?> < article class="col-md-12"> < a href="http://www.srcmini.com/< ?php the_permalink(); ?>" > < div class="image"> < img class="img-responsive" src="http://www.srcmini.com/< ?php echo the_post_thumbnail_url('medium' ); ?> "> < /div> < /a> < div class="entry entry-table"> < div class="title"> < a href="http://www.srcmini.com/< ?php the_permalink(); ?>" > < h3 class="h5"> < ?php the_title(); ?> < /h3> < /a> < span class="cateogry< ?php echo get_the_category( $id )[0]-> cat_ID; ?> "> < ?php echo get_the_category( $id )[0]-> name; ?> < /span> < p> < ?php echo get_excerpt(228, 'content'); ?> < a class="linkmore" href="http://www.srcmini.com/< ?php the_permalink() ?>"> Czytaj dalej ...< /a> < /p> < /div> < /div> < /article> < ?php endwhile; ?> < ?php wp_pagenavi(); ?> < ?php $wp_query = null; $wp_query = $temp; ?>

    推荐阅读