【问题标题】:wordpress one category split into two columnswordpress 一个类别分为两列
【发布时间】:2018-01-23 15:52:39
【问题描述】:

我正在尝试将 wordpress 类别分成两列,仅显示三个帖子。附上了当前的编码,但最终博客的标题移到了第二列,没有保留它应该在的位置,有没有人可以帮助或帮助指导我?或者如果有更好的方法来解决这个问题。

非常感谢!

        <div class="featuredPosts">

<?php $catquery = new WP_Query( 'cat=3&posts_per_page=5' ); ?>


<?php while($catquery->have_posts()) : $catquery->the_post(); ?>


    <div class="postFeatured">

<img src="<?php echo get_the_post_thumbnail_url($post_id, 'full'); ?>" class="featuredImage">
        <h2><?php the_title(); ?></h2>
        <a href="<?php the_permalink() ?>" rel="bookmark">Read More...</a>
        </div>


<?php endwhile;
    wp_reset_postdata();
?>

                    </div>

和 CSS

.featuredPosts {
      -moz-column-count: 2;
      -moz-column-gap: 4em;
      -moz-column-rule: none;
      -webkit-column-count: 2;
      -webkit-column-gap: 4em;
      -webkit-column-rule: none;
    column-count: 2;
    column-gap: 4em;
    column-rule: none;
}



.postFeatured {
margin: 0 0 5em 0;  
}

.featuredImage {
    border-radius: 8px;
    box-shadow:  0px 0px 20px 0 rgba(000, 000, 000, 0.2);
display: block;
}



.postFeatured h2 {
font-size: 25px;
color: #2B2928;
letter-spacing: 0;
line-height: 40px;
padding: 1em 0;
margin: 0px;
}

【问题讨论】:

    标签: php wordpress wordpress-theming


    【解决方案1】:

    尝试将以下内容添加到.postFeatured

    -webkit-column-break-inside: avoid;
    page-break-inside: avoid;
    break-inside: avoid;
    

    例子:

    .featuredPosts {
      -moz-column-count: 2;
      -moz-column-gap: 4em;
      -moz-column-rule: none;
      -webkit-column-count: 2;
      -webkit-column-gap: 4em;
      -webkit-column-rule: none;
      column-count: 2;
      column-gap: 4em;
      column-rule: none;
    }
    
    .postFeatured {
      margin: 0 0 5em 0;
      -webkit-column-break-inside: avoid;
      page-break-inside: avoid;
      break-inside: avoid;
    }
    
    .featuredImage {
      border-radius: 8px;
      box-shadow: 0px 0px 20px 0 rgba(000, 000, 000, 0.2);
      display: block;
    }
    
    .postFeatured h2 {
      font-size: 25px;
      color: #2B2928;
      letter-spacing: 0;
      line-height: 40px;
      padding: 1em 0;
      margin: 0px;
    }
    <div class="featuredPosts">
      <div class="postFeatured">
        <img src="http://via.placeholder.com/350x150" class="featuredImage">
        <h2>Title</h2>
        <a href="#">Read More...</a>
      </div>
      <div class="postFeatured">
        <img src="http://via.placeholder.com/350x150" class="featuredImage">
        <h2>Title</h2>
        <a href="#">Read More...</a>
      </div>
      <div class="postFeatured">
        <img src="http://via.placeholder.com/350x150" class="featuredImage">
        <h2>Title</h2>
        <a href="#">Read More...</a>
      </div>
    </div>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 2017-01-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多