Moker
V2EX  ›  WordPress

WORDPRESS 文章无法分页问题

  •  
  •   Moker · Jun 13, 2014 · 6023 views
  •   You need to sign in to view this topic
    This topic created in 4495 days ago, the information mentioned may be changed or developed.
    去网上查了些...发现那些答案基本都是互相复制的....
    然后试了下发现没成功
    目前是给文章页新建了一个特定的模板
    如果在后台阅读设置里面,把这个模板的页面设置为文章页的时候,它会自动跳到首页
    如果设置为其他页面,则这个文章模板可正常显示
    但不能显示翻页
    查了下好像是query_post的问题
    代码如下:

    $limit = get_option('posts_per_page');
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('&showposts=' . $limit=9 . '&paged=' . $paged);
    $wp_query->is_archive = true; $wp_query->is_home = false;




    // 主循环
    if ( have_posts() ) : while ( have_posts() ) : the_post();?>
    <li><h3><span>[<?php the_time('Y-n-j'); ?>]</span><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3><?php the_content(); ?></li>
    <?php endwhile; else:

    par_pagenavi(9);
    if(
    function_exists('wp_pagenavi'))
    {
    wp_pagenavi();
    }
    endif;

    // 重置query
    wp_reset_query();

    ?>


    <?php par_pagenavi(9); ?>

    <?php if(
    function_exists('wp_pagenavi'))
    {
    wp_pagenavi();
    }
    ?>

    不懂哪里出了问题。。。
    哎。。求支招
    Supplement 1  ·  Jun 13, 2014
    补下图
    Supplement 2  ·  Jun 13, 2014
    发现分页问题解决了
    把翻页代码放到wp_reset_query();前面

    $limit = get_option('posts_per_page');
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('cat=1&showposts=' . $limit=3 . '&paged=' . $paged);
    $wp_query->is_archive = true; $wp_query->is_home = false;





    // 主循环
    if ( have_posts() ) : while ( have_posts() ) : the_post();?>
    <li><h3><span>[<?php the_time('Y-n-j'); ?>]</span><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3><?php the_content(); ?></li>
    <?php
    endwhile; else:
    endif;?>





    </ul>
    </div>
    <div id="pages">
    <?php
    if(
    function_exists('wp_pagenavi'))
    {
    wp_pagenavi();
    }
    // 重置query
    wp_reset_query();

    ?>
    11 replies  •  2014-06-13 19:51:56 +08:00
    Zhang
        1
    Zhang  
       Jun 13, 2014
    Moker
        2
    Moker  
    OP
       Jun 13, 2014
    @Zhang 表示失败了
    而且这篇文章看起来像是 文章里面翻页的 不是导航的那种
    iloveyou
        3
    iloveyou  
       Jun 13, 2014   ❤️ 1
    <div class="content_box" style="position:relative;">
    <?php
    $args = array(
    'post_type' => 'new',
    'meta_query' => array(
    array(
    'key' => 'category',
    'value' => $category,
    )
    ),
    'paged' => get_query_var('paged')
    );
    $my_query = new WP_Query($args);
    echo '<ul class="news_list">';
    while ( $my_query->have_posts() ) : $my_query->the_post();
    echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a><span>'.get_the_date().'</span>'.'</li>';
    endwhile;
    echo '</ul>';
    ?>
    </div>
    </div>
    <?php
    wp_pagenavi( array( 'query' => $my_query ) );
    wp_reset_postdata();
    ?>
    </div>
    Moker
        4
    Moker  
    OP
       Jun 13, 2014
    @iloveyou 这种方法试了下是失败的
    不过刚发现在页面模板里面是失效的 如: http://127.0.0.1/?page_id=372
    不过在分类目录下的页面 是可以显示的: http://127.0.0.1/?cat=47
    Zhang
        5
    Zhang  
       Jun 13, 2014
    @Moker 你问的就是文章翻页啊!
    bingu
        6
    bingu  
       Jun 13, 2014
    实在看不懂lz的意图,你弄个图表达一下比较好。 你发两127.0.0.1的链接谁能看到啊
    Moker
        7
    Moker  
    OP
       Jun 13, 2014
    @bingu 链接只是想表达后面的page跟cat
    先上课去了。稍后弄个图出来
    Moker
        8
    Moker  
    OP
       Jun 13, 2014
    @Zhang 是的就是导航的那种
    emric
        9
    emric  
       Jun 13, 2014
    XY 问题, 我猜你想实现自定义URl.
    Moker
        10
    Moker  
    OP
       Jun 13, 2014
    @emric 不是。。自定义URL不是用后台的固定链接可以实现?
    我现在发现用着方法翻页问题是解决了,但是如果用文章分类做导航,发现不能显示该分类下的文章。。显示的而是全部分类下的文章
    query_posts('cat=1&showposts=' . $limit=3 . '&paged=' . $paged);
    现在是想cat后面的值能自动获取当前页面的值,可是发现试了几种方法。。都失败了
    估计语法上写错了吧
    emric
        11
    emric  
       Jun 13, 2014
    @Moker
    不是自定义URL, 那你为什么要用 page.php? 不就是为了固定链接的自定义模板吗?
    估计你和我一样都是语死早类型.
    建议你直接说需求, 你做的现在用方法不一定是对的. 所以我想说这个是 XY 问题.
    说实话, 你后面补充的我一句也看不懂(不只是我).
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2213 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 04:51 · PVG 12:51 · LAX 21:51 · JFK 00:51
    ♥ Do have faith in what you're doing.