dooid3005 2015-07-16 13:11
浏览 39
已采纳

Wordpress帖子不会彼此相邻显示

I have been searching for a number of hours now and have tried to figure it out myself however I am having great difficulties resolving it. Basically, I have a wordpress loop in which I have, on my homepage, the post thumbnails displayed. They all appear vertically and I want it so that at least 3 images appear next to each other before starting a new line.

The code for the page is:

<?php 
get_header();?>

<div id="primary">
<div id="content" role="main">
    <?php
    $mypost = array('post_type' => 'photo_posts');
    $loop = new WP_Query($mypost);
    ?>
    <?php while ($loop->have_posts()):$loop->the_post();?>
        <article id="post-<?php the_ID();?>" <?php post_class(); ?>>
            <header class="entry-header">
                <!-- Display featured image -->
                <div>
                    <a href="<?php echo $permalink = get_post_permalink();?>"><?php the_post_thumbnail(array(230, 230)); ?></a>
                </div>
            </header>
            <div class="entry-content"><?php the_content(); ?></div>
        </article>
<?php endwhile; ?>
</div>
</div>

<?php get_footer(); ?>

CSS:

.container {
   position: absolute;
   padding-right: 20px;
   width: 70%;
   right: 0;
}

Any help is appreciated. Thanks!

  • 写回答

1条回答 默认 最新

  • donglu1472 2015-07-16 13:30
    关注

    If you want the articles to be placed next to each other, there are several methods how you can achieve this.

    The most simple solution would be to assign a class to your articles (just in case you don't want to rely on post_class() or not to affect other articles on the same site), and use the css display property, and set it to inline-block.

    article {
        display: inline-block;
    }
    

    This way your articles are going to be on the same horizontal line until they reach the end of the screen. The following articles will be placed in the next line, and so on.

    Note that the css above does not use a class, and therefor applies to all articles on the page

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?
  • ¥15 大智慧怎么编写一个选股程序
  • ¥100 python 调用 cgps 命令获取 实时位置信息
  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证
  • ¥20 ensp怎么配置让PC1和PC2通讯上
  • ¥50 有没有适合匹配类似图中的运动规律的图像处理算法
  • ¥15 dnat基础问题,本机发出,别人返回的包,不能命中
  • ¥15 请各位帮我看看是哪里出了问题