如何将分页添加到页中的Foreach循环

时间:2016-10-02 作者:Nitin Poojary

我在wordpress中创建了一个页面series.php 这里是我阻止的代码!

    <?php 
        $categories=get_categories(
            array( \'parent\' => $cat->cat_ID)
        );

        foreach ($categories as $c) {
            // what you really want instead of var_dump is something to
            // to create markup-- list items maybe, For example
            $idp = $c->term_taxonomy_id;
            //then i get the data from the database
            $cat_data = get_option("category_".$idp);
        ?>      

        <div class="wide-box">
            <!-- Content Detail Box -->
            <a href="<?php echo get_category_link( $idp ); ?>" class="wb-image"><img src="<?php echo $cat_data[\'original_img\']; ?>"></a>
            <!-- Wb Center -->
            <div class="wb-center">
                <h3 class="wb-name"><a href="<?php echo get_category_link( $idp ); ?>"><?php echo $c->name; ?></a></h3>
                <div class="wb-details">
                    Genres : <?php echo $cat_data[\'genres\']; ?><br>
                    Country : <?php echo $cat_data[\'country\']; ?><br>
                    Language : <?php echo $cat_data[\'language\']; ?><br>
                    Year : <?php echo $cat_data[\'year\']; ?>
                </div>
                <div class="latest-label">Latest Episode:</div>
                <?php
                    $catquery = new WP_Query( \'cat=\'.$idp.\'&posts_per_page=1\' );
                    while($catquery->have_posts()) : $catquery->the_post();
                ?>
                    <a href="<?php the_permalink() ?>" class="latest-ep"><?php the_title(); ?></a>
                <?php endwhile; ?>
            </div>
            <!-- Wb Center -->
        </div>      

    <?php                   
        }
    ?>
    </div>
那么,如何为循环添加分页来显示它呢?

1 个回复
SO网友:Dev

将此参数添加到WP_Query.

\'paged\' => get_query_var( \'paged\' ),
并使用参数的数组样式,而不是查询帖子样式。