【问题标题】:how can i wrap 3 posts in one row into a single div如何将一行中的 3 个帖子包装到一个 div 中
【发布时间】:2017-06-06 20:13:45
【问题描述】:

我有一个循环,它使用 col-md-4 在一行中显示 3 个帖子。有没有办法将此行包装成一个div?现在,如果我将 css 添加到 col-md-4 它会将 css 应用于每个单独的帖子,我希望 css 共同影响该行中的 3 个帖子。有谁知道我该怎么做?

首页.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();

【问题讨论】:

    标签: html css twitter-bootstrap row col


    【解决方案1】:

    尝试使用 FlexBox 设置帖子容器/父元素的样式

    【讨论】:

      猜你喜欢
      • 2011-12-19
      • 2016-11-30
      • 2014-07-15
      • 2013-03-03
      • 2014-07-20
      • 2011-03-22
      • 1970-01-01
      • 2014-01-22
      相关资源
      最近更新 更多