Wordpress Bootstrap选项卡未显示帖子限制

时间:2016-09-01 01:01:08

标签: php wordpress twitter-bootstrap

我已设置循环以显示每个标签(类别)的5个帖子。但它并没有这样做,即使一个类别中有5个或更多帖子。它不会超过4.我不知道为什么。以下是我的代码(我使用ACF来选择从后端显示哪些类别)。任何帮助将不胜感激(请注意,我正在格式化每个选项卡中的第一个项目不同):

<!-- Nav Tabs -->
<ul  class="nav nav-pills">
    <?php if (have_rows('home_categories')) {
        $i = 0;
        while (have_rows('home_categories')) {
            the_row();
            $term = get_sub_field('categories'); ?>
    <li class="<?php if ($i == 0) { echo ' active'; }?>"> 
        <a href="#tab-pane-<?php echo $i; ?>" data-toggle="tab"><?php echo $term->name; ?></a>
    </li>
        <?php $i++;
        }
    } ?>
</ul>

<!-- Tab Content -->
<div class="tab-content clearfix">
    <?php $home_categories = get_field("home_categories");

        foreach($home_categories as $key => $home_cat) {
            $term_id = $home_cat['categories']->term_id;
            $term_name = $home_cat['categories']->name;
    ?>
    <div class="tab-pane fade<?php if ($key == 0) { echo ' in active'; }?>" id="tab-pane-<?php echo $key; ?>">
        <div class="posts-box row">
            <div class="box-content">
                <ul>
                    <?php $args = array(
                        'post_type' => 'post',
                        'tax_query' => array(
                            array(
                                'taxonomy' => $term->taxonomy,
                                'terms' => array($term_id)
                            )
                        ),
                        'posts_per_page' => 5,
                        'orderby' => 'date',
                        'order' => 'ASC',
                    );

                    $query = new WP_Query( $args );
                    $count = 0;

                    foreach($query->posts as $post) {
                        $count++;
                        if ($count == 1) {
                    ?>

                    <div class="col-xs-12 col-sm-6 col-md-6">
                        <li class="first-news clearfix">
                            <a href="<?php echo get_permalink($post->ID); ?>" title="<?php echo get_the_title($post->ID); ?>" data-toggle="tooltip" rel="bookmark">
                                <?php $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
                                <div class="post-thumbnail" style="background-image: url(<?php echo $feat_image; ?>); height: 200px; background-size: cover; background-position: center center;">

                                    <span class="fa overlay-icon"></span>
                                </div>
                            </a>

                            <a title="<?php the_title($post->ID) ?>" href="<?php echo get_permalink($post->ID); ?>" rel="bookmark">
                                <h3 class="post-box-title"><?php echo get_the_title($post->ID); ?></h3>
                            </a>

                            <p class="post-meta">
                                <span class="darwin-date">
                                    <i class="fa fa-clock-o"></i>
                                    <?php echo get_the_date($post->ID); ?>
                                </span>

                                <span class="post-comments">
                                    <i class="fa fa-comments"></i>
                                    <a href="<?php echo get_comments_link( $post->ID ); ?>">
                                        <?php comments_number( '0' , '1' , '%' ); ?>
                                    </a>
                                </span>
                            </p>

                            <div class="entry">
                                <p><?php echo wp_trim_words($post->post_content, 20, '...'); ?></p>

                                <div class="more-posts">
                                    <a class="more-link" title="<?php echo get_the_title($post->ID); ?>" href="<?php the_permalink($post->ID); ?>" data-toggle="tooltip">Read More &raquo;</a>
                                </div>
                            </div>
                        </li>
                    </div>

                    <div class="col-xs-12 col-sm-6 col-md-6">
                        <div class="container-fluid">

                        <?php } else { ?>
                            <li class="other-news row">
                                <a href="<?php echo get_permalink($post->ID); ?>" title="<?php echo get_the_title($post->ID); ?>" data-toggle="tooltip" rel="bookmark">
                                    <div class="col-md-3" style="background-image: url(<?php echo $feat_image; ?>); height: 100px; background-size: cover; background-position: center center;">
                                        <span class="fa overlay-icon"></span>
                                    </div>
                                </a>

                                <div class="news-info col-md-9">
                                    <h4 class="post-box-title">
                                        <a title="<?php the_title($post-ID) ?>" href="<?php the_permalink($post->ID); ?>"><?php echo get_the_title($post->ID); ?></a>
                                    </h4>

                                    <p class="post-meta">
                                        <span class="darwin-date">
                                            <i class="fa fa-clock-o"></i>
                                            <?php echo get_the_date($post->ID); ?>
                                        </span>

                                        <span class="post-cats">
                                            <i class="fa fa-folder"></i>
                                            <?php printf('%1$s', get_the_category_list(', ' ) ); ?>
                                        </span>

                                        <span class="post-comments">
                                            <i class="fa fa-comments"></i>
                                            <a href="<?php echo get_comments_link( $post->ID ); ?>">
                                                <?php comments_number( '0' , '1' , '%' ); ?>
                                            </a>
                                        </span>

                                        <span class="post-views">
                                            <i class="fa fa-eye"></i>
                                            <?php //echo getPostViews(get_the_ID()); ?>
                                        </span>
                                    </p>
                                </div>
                            </li>
                        <?php $count++; }
                    } ?>
                        </div>
                    </div>
                </ul>
            </div>
        </div>
    </div>

        <?php } ?>
</div>

提前致谢。

0 个答案:

没有答案