WordPress分页不起作用

时间:2016-10-07 07:27:26

标签: wordpress pagination wordpress-theming

我编码的这个wordpress主题的分页,似乎没有用,任何一个有更好的理想?提前谢谢你。

下面是我的完整代码,我有点困惑,曾尝试使用插件并调用短代码wp-pagenavi但它也无法正常工作,我将不胜感激。

<?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array('post_type' => 'post', 'posts_per_page' => 10, 'paged' => $paged);
    $query = new WP_Query($args);
    if( $query->have_posts() ) :
    while( $query->have_posts() ) : $query->the_post(); ?>
    <div class="media">
    <div class="media-left">
    <div class="hovereffect">


        <a href="#"><?php the_post_thumbnail();?></a>
        <div class="overlay">
            <h2>Share</h2>
            <p class="icon-links">
                <a href="#">
                    <span class="fa fa-twitter"></span>
                </a>
                <a href="#">
                    <span class="fa fa-facebook"></span>
                </a>
                <a href="#">
                    <span class="fa fa-instagram"></span>
                </a>
            </p>
        </div>

    </div>
    </div>
     <div class="media-body">
        <h4 class="media-heading"><?php the_title()?></h4>
        <p class="media-author"><b><?php the_author()?></b> - <?php echo get_the_date(); ?></p>
            <?php the_content();?>
        </div>
    </div>
    <?php endwhile;?>
<!-- pagination -->
<?php next_posts_link(); ?>
<?php previous_posts_link(); ?>
<?php else : ?>
<!-- No posts found -->
<?php endif; ?>

1 个答案:

答案 0 :(得分:0)

您必须在$query->max_num_pages的第二个参数中使用next_posts_link,因为您可以看到here

// next_posts_link() usage with max_num_pages
next_posts_link( 'Older Entries', $the_query->max_num_pages );
previous_posts_link( 'Newer Entries' );
相关问题