我直接从抄本上取了这个例子,我的分页被破坏了。
这是我复制/粘贴代码的codex页面:https://codex.wordpress.org/Function_Reference/next_posts_link
一切正常。我的帖子显示出来了only 这个next_posts_link, 然而,它只在第页之前有效2. 这个previous_posts_link 从不出现。
我只能分页到第2页,不能再往回走或再往前走。
我正在使用WordPress 3.5.2,在尝试此操作后,我重置了永久链接。
我在下面添加了一个调试部分,以查找最大页面数var_dump  退货float(87).
这是我的PHP代码。有什么想法吗?
function homepage_test() {
    // Set the limit of posts to show per page
    $limit = 5;
    // set the "paged" parameter (use \'page\' if the query is on a static front page)
    $paged = ( get_query_var( \'page\' ) ) ? get_query_var( \'page\' ) : 1;
    // the query
    $the_query = new WP_Query( \'showposts=\' . $limit . \'&paged=\' . $paged . \'&orderby=date&order=DESC\' );
    if ( $the_query->have_posts() ) :
    // the loop
    while ( $the_query->have_posts() ) : $the_query->the_post(); 
        the_title();
    endwhile;
    // usage with max_num_pages
    next_posts_link( \'Older Entries\', $the_query->max_num_pages );
    //Debug to show how many max pages.
    var_dump($the_query->max_num_pages);
    previous_posts_link( \'Newer Entries\' );
    // clean up after our query
    wp_reset_postdata();
    else: ?>
        <p><?php _e( \'Sorry, no posts matched your criteria.\' ); ?></p>
    <?php endif;
}
 
                    最合适的回答,由SO网友:Charles Clarkson 整理而成
                    previous_posts_link() 响应的结果get_previous_posts_link() 检查paged 查询变量,而不是page 静态页面上使用的查询变量。您必须编写自己的代码才能在静态页面上显示链接。
我没有测试它,但你可以尝试愚弄WordPress:
function homepage_test() {
    global $paged;
 现在,您对代码中$paged变量所做的更改将显示在
get_previous_posts_link(). 我不知道它还会影响什么,也不知道链接是否正确。