Prime 策略页面 Navi wordpress 无法在 archive.php 中工作

问题描述 投票:0回答:1

下面的插件在我拥有的每个

archive_{post-type}.php
上都能完美工作,但在
archive.php
(加载所有帖子)中不起作用。我不明白这是为什么。

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(); ?>

调试时,永远不会达到

if
条件线。在我的设置中有超过 10 个帖子,我已经设置了
posts_per_page=5

我还缺少什么?

php wordpress pagination
1个回答
0
投票

您可以尝试以下代码吗:

<?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(); ?>
© www.soinside.com 2019 - 2024. All rights reserved.