如何将一行中的3个帖子整理成一个div

时间:2017-01-22 04:35:15

标签: html css twitter-bootstrap row col

我有一个循环使用col-md-4在一行中显示3个帖子。有没有办法将此行包装成div?现在,如果我将css添加到col-md-4,它会将css应用于每个帖子,我宁愿css集体影响行中的3个帖子。有谁知道我怎么能做到这一点?

前page.php文件

<?php
/*
 * Template Name:
 */

get_header();
get_template_part ('inc/carousel');

$the_query = new WP_Query( [
    'posts_per_page' => 14,
    'paged' => get_query_var('paged', 1)
] );

if ( $the_query->have_posts() ) { ?>
    <div id="ajax">
    <?php
    $i = 0;
    while ( $the_query->have_posts() ) { $the_query->the_post();

        if ( $i % 7 === 0 ) { // Large post: on the first iteration and every 7th post after... ?>
        <article <?php post_class( 'col-md-12' ); ?>>
            <div class="large-front-container">
<?php the_post_thumbnail('full', array('class' => 'large-front-thumbnail')); ?>
                </div>
            <h2><a class="post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
            <p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p>
            <div class="front-post-info">
            <a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
                <?php get_template_part ('front-page-shop'); ?>
                                 <?php get_template_part( 'share-buttons' ); ?>
                <div class="front-comments"><?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?></div>
            </article><?php

        } else { // Small posts ?>
            <article <?php post_class( 'col-md-4' ); ?>>
                <div class="front-thumbnail-image"><?php the_post_thumbnail('full', array('class' => 'medium-front-thumbnail')); ?></div>
                <a class="front-page-post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                <p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p>
                <a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
                <?php get_template_part ('front-page-shop'); ?>
                                 <?php get_template_part( 'share-buttons' ); ?>
                <div class="front-comments"><?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?></div>
            </article>
            <?php
        }
        $i++;
    }?>
    </div>
    <?php if(get_query_var('paged') < $the_query->max_num_pages) {
       load_more_button();
    }
}
elseif (!get_query_var('paged') || get_query_var('paged') == '1') {
    echo '<p>Sorry, no posts matched your criteria.</p>';
}
wp_reset_postdata();
get_footer();

1 个答案:

答案 0 :(得分:0)

尝试使用FlexBox

设置post container / parent元素的样式