php - 自定义帖子类型显示缩略图 - WordPress

标签 php css wordpress blogs custom-post-type

谁知道为什么我的“事件”列表显示如下:

enter image description here

取而代之的是:

enter image description here

所以问题是;如何使自定义帖子类型列表显示为列表,无论图像大小如何?我认为它目前正在尝试显示为行中的列 - 我试图删除下面代码中的 block : $portfolio_count % 4 == 0 - 但这只是打破它......

这是我的循环:

        <?php
        $args = array( 
          'post_type' => 'events'
        );
        $the_query = new WP_Query( $args );

        ?>

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

        <div class="events-index">
          <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'event-thumb' ); ?></a>
          <a href="<?php the_permalink(); ?>"><h3><?php the_title(); ?></h3></a>
          <h4><?php the_field('date_of_event'); ?></h4>
          <p><?php the_field('location'); ?></p>
        </div>

        <?php $portfolio_count = $the_query->current_post + 1; ?>
        <?php if ( $portfolio_count % 4 == 0): ?>

        <?php endif; ?>

        <?php endwhile; endif; ?>

这是 CSS:

.events-index {
  border-bottom: 1px solid #eee;
  margin-bottom: 30px;
  padding-bottom: 15px;
}

.events-index img {
  float: left;
  margin:0 25px 20px 0;
}

.events-index  h4 {
  margin:0 0 20px 0;
}

.events-index h4 {
  margin:0 0 20px 0;
}

.events-index p {
  color:#163a52;
  font-style: italic;
  margin: 10px 0 10px 0;
}

.events-index h4 {
  color:#163a52;
  margin-bottom: 0;
}

我目前在 functions.php 文件中有这个:

add_image_size( 'event-thumb', 250, 150, true ); // Hard Crop Mode

最佳答案

那是因为 img 向左浮动了。在 .events-index block 之后添加下面的 CSS block 。

.events-index::after {
  content: '.';
  display: block;
  color: transparent;
  clear: both;
}

关于php - 自定义帖子类型显示缩略图 - WordPress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42328607/

相关文章:

php - 此用户表单的潜在安全问题

php - 生成具有完整路径 (URLS) 和数据库值的嵌套树

performance - SVG 对象的 CSS3 动画的缺点?

javascript - 如何使用仪表板在WordPress中插入iframe

php - 如何防止 WordPress 更新通知显示在插件管理页面?

php - 如何使用 MYSQL 在结果中将 0 值设置为 NULL

php - 在列而不是行中显示 php 查询

javascript - 加载 GIF 与旋转 css img

css - 挣扎着关闭地基中的显示窗口

javascript - jquery 输入字段更改 wordpress 中的所有 php 循环项值