dsbezji539113152 2016-08-21 05:26
浏览 57

Prime策略页面Navi wordpress在archive.php中不起作用

The below plugin works beautifully on every archive_{post-type}.php that I have, but it doesn't work in archive.php (which loads all posts). I don't understand the reason for this.

archive.php:

<?php /* Template Name: Archives */
 get_header(); ?>

 <div class="head-style col-md-12 col-sm-12 col-xs-12">

    <div class="title-pack col-md-12 col-sm-12 col-xs-12">
        <span class="line visible-sm-block"></span>
        <span class="visible-sm-block tittle-style">آخرین اخبار</span>
    </div>
    <div class="row news-content">
        <div class="last-news-box col-md-9 col-sm-8 col-xs-12">
            <?php $args = array( 'post_type' => 'post'); 
                $loop = new WP_Query( $args );
                while ( $loop->have_posts() ) : $loop->the_post();?>

                    <div class="col-md-11 col-sm-11 col-xs-12">
                        <div class="image-news col-md-4 col-sm-4 col-xs-12">
                            <?php the_post_thumbnail(); ?>
                        </div>
                        <div class="newstext col-md-8 col-sm-8 col-xs-12">
                            <div>
                                <h3><?php the_title(); ?></h3>
                                <p><?php the_excerpt(); ?>...</p>

                                <a href="<?php the_permalink(); ?>">
                                    <button class="readmore-button">ادامه مطلب</button>
                                </a>
                            </div>  
                        </div>
                    </div>
                <?php endwhile ?>               
        </div>

    </div>

<div><?php if ( function_exists( 'page_navi' ) ) { page_navi(); } ?></div>  
<?php get_footer(); ?>

When debugging this, the if condition line is never reached. In my setup there are more than 10 posts and I have set posts_per_page=5.

What else am I missing?

  • 写回答

1条回答 默认 最新

  • douxuanling6523 2016-08-21 08:07
    关注

    Can you please try below code:

    <?php /* Template Name: Archives */
     get_header(); ?>
    
     <div class="head-style col-md-12 col-sm-12 col-xs-12">
    
        <div class="title-pack col-md-12 col-sm-12 col-xs-12">
            <span class="line visible-sm-block"></span>
            <span class="visible-sm-block tittle-style">آخرین اخبار</span>
        </div>
        <div class="row news-content">
            <div class="last-news-box col-md-9 col-sm-8 col-xs-12">
                <?php 
                    if ( get_query_var('paged') ) {
                        $paged = get_query_var('paged');
                    } elseif ( get_query_var('page') ) { // 'page' is used instead of 'paged' on Static Front Page
                        $paged = get_query_var('page');
                    } else {
                        $paged = 1;
                    }
                    $args = array( 'post_type' => 'post', 'paged' => $paged); 
                    $loop = new WP_Query( $args );
                    while ( $loop->have_posts() ) : $loop->the_post();?>
    
                        <div class="col-md-11 col-sm-11 col-xs-12">
                            <div class="image-news col-md-4 col-sm-4 col-xs-12">
                                <?php the_post_thumbnail(); ?>
                            </div>
                            <div class="newstext col-md-8 col-sm-8 col-xs-12">
                                <div>
                                    <h3><?php the_title(); ?></h3>
                                    <p><?php the_excerpt(); ?>...</p>
    
                                    <a href="<?php the_permalink(); ?>">
                                        <button class="readmore-button">ادامه مطلب</button>
                                    </a>
                                </div>  
                            </div>
                        </div>
                    <?php endwhile ?>               
            </div>
    
        </div>
    
    <div><?php if ( function_exists( 'page_navi' ) ) { page_navi(); } ?></div>  
    <?php get_footer(); ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)