簡體   English   中英

WordPress:posts_per_page無法處理存檔頁面

[英]WordPress: posts_per_page not working on archive pages

我有一個自定義循環,它應該以隨機順序顯示每個類別3個項目。 問題是,循環始終顯示該類別中的所有項目。

我已經在單個頁面上測試了代碼,它的工作原理應該如何,只顯示了3個項目。

所以我想這與存檔頁面有關?!

這是循環本身:

<?php

        $args_thema = array (
            'post_type' => array( 'project' ),
            'orderby' => 'rand',
            'posts_per_page'    => 3,
            'paged'             => $paged,
            //'ignore_sticky_posts'    => 1,
            'tax_query' => array(
                array(
                    'taxonomy' => 'project-category',
                    'field'    => 'slug',
                    'terms'    => $category->slug,
                ),
            ),
        );

        $query_thema = new WP_Query( $args_thema ); if ( $query_thema->have_posts() ) : ?>
        <ul class="">
            <?php $i = 0; while ( $query_thema->have_posts() ) : $query_thema->the_post(); $i++; // echo $i; ?>
                <li class="">
                    <a class="url uid" href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
                        <?php the_title(); ?>
                    </a>
                </li>
            <?php endwhile; ?>
        </ul>
        <?php else : ?>

        <?php endif; wp_reset_postdata(); ?>

這是完整的代碼(我猜不相關):

<?php

    $args       = array('hide_empty' => '0', 'taxonomy' => 'project-category', 'orderby' => 'name', 'order' => 'ASC', 'parent' => 0 );
    $categories = get_categories($args);

    foreach($categories as $category) {

?>
<div class="row">
    <div class="col-lg-4">

        <?php
            $term_child = get_term_by('slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
            $args_child = array('hide_empty' => '0', 'taxonomy' => 'project-category', 'orderby' => 'name', 'order' => 'ASC', 'parent' => $category->term_id );
        ?>

        <h4><a href="<?php echo get_term_link($category->slug, 'project-category')  ?>" title="<?php echo $category->name ?>"><?php echo $category->name; ?></a></h4>

    </div>
    <div class="col-lg-8">

        <?php

        $args_thema = array (
            'post_type' => array( 'project' ),
            'orderby' => 'rand',
            'posts_per_page'    => 3,
            'paged'             => $paged,
            //'ignore_sticky_posts'    => 1,
            'tax_query' => array(
                array(
                    'taxonomy' => 'project-category',
                    'field'    => 'slug',
                    'terms'    => $category->slug,
                ),
            ),
        );

        $query_thema = new WP_Query( $args_thema ); if ( $query_thema->have_posts() ) : ?>
        <ul class="">
            <?php $i = 0; while ( $query_thema->have_posts() ) : $query_thema->the_post(); $i++; // echo $i; ?>
                <li class="">
                    <a class="url uid" href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
                        <?php the_title(); ?>
                    </a>
                </li>
            <?php endwhile; ?>
        </ul>
        <?php else : ?>

        <?php endif; wp_reset_postdata(); ?>

    </div>
</div>

<?php } ?>

對不起,這是一個額外的功能,它將存檔帖子設置為99。

Isreg of is_post_type_archive我用的是is_archive

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM