在配置文件选项卡中添加列结构(如网格)

时间:2015-12-01 15:34:23

标签: php html css

在我的网站上,每个用户都有一个配置文件,其中提交的帖子位于专用的个人资料标签中。

我使用此代码显示帖子:

<?php while ($ultimatemember->shortcodes->loop->have_posts()) { $ultimatemember->shortcodes->loop->the_post(); $post_id = get_the_ID(); ?>

    <div class="um-item">
        <div  class="um-item-link"><i class="um-icon-ios-paper"></i><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>

        <?php if ( has_post_thumbnail( $post_id ) ) {
                $image_id = get_post_thumbnail_id( $post_id );
                $image_url = wp_get_attachment_image_src( $image_id, 'full', true );
        ?>

        <div class="um-item-img"><a href="<?php the_permalink(); ?>"><?php echo get_the_post_thumbnail( $post_id, 'thumbnail' ); ?></a></div>

        <?php } ?>

        <div class="um-item-meta">
            <span><?php echo sprintf(__('%s ago','ultimatemember'), human_time_diff( get_the_time('U'), current_time('timestamp') ) ); ?></span>
            <span>dans: <?php the_category( ', ' ); ?></span>
            <span><?php comments_number( __('no comments','ultimatemember'), __('1 comment','ultimatemember'), __('% comments','ultimatemember') ); ?></span>
        </div>
    </div>


<?php } ?>

但是,在这里,每个帖子都会在一列中显示其特色图片,而另一个帖子则在另一个帖子下方。我试图在两个或三个相邻的列中显示我的帖子而不是仅仅一个(如网格)。我从这开始看看两列是否显示得很好:

<?php while ($ultimatemember->shortcodes->loop->have_posts()) { $ultimatemember->shortcodes->loop->the_post(); $post_id = get_the_ID(); ?>

        <div id = "left" class="um-item">
            <div  class="um-item-link"><i class="um-icon-ios-paper"></i><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>

            <?php if ( has_post_thumbnail( $post_id ) ) {
                    $image_id = get_post_thumbnail_id( $post_id );
                    $image_url = wp_get_attachment_image_src( $image_id, 'full', true );
            ?>

            <div class="um-item-img"><a href="<?php the_permalink(); ?>"><?php echo get_the_post_thumbnail( $post_id, 'thumbnail' ); ?></a></div>

            <?php } ?>

            <div class="um-item-meta">
                <span><?php echo sprintf(__('%s ago','ultimatemember'), human_time_diff( get_the_time('U'), current_time('timestamp') ) ); ?></span>
                <span>dans: <?php the_category( ', ' ); ?></span>
                <span><?php comments_number( __('no comments','ultimatemember'), __('1 comment','ultimatemember'), __('% comments','ultimatemember') ); ?></span>
            </div>
        </div>

        <div id = "right" class="um-item">
            <div style="height: 10px;  class="um-item-link"><i class="um-icon-ios-paper"></i><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>

            <?php if ( has_post_thumbnail( $post_id ) ) {
                    $image_id = get_post_thumbnail_id( $post_id );
                    $image_url = wp_get_attachment_image_src( $image_id, 'full', true );
            ?>

            <div class="um-item-img"><a href="<?php the_permalink(); ?>"><?php echo get_the_post_thumbnail( $post_id, 'thumbnail' ); ?></a></div>

            <?php } ?>

            <div class="um-item-meta">
                <span><?php echo sprintf(__('%s ago','ultimatemember'), human_time_diff( get_the_time('U'), current_time('timestamp') ) ); ?></span>
                <span>dans: <?php the_category( ', ' ); ?></span>
                <span><?php comments_number( __('no comments','ultimatemember'), __('1 comment','ultimatemember'), __('% comments','ultimatemember') ); ?></span>
            </div>
        </div>

    <?php } ?>

用这个css:

 #left
        {
          width: 200px;
          float: left;
        }

        #right
        {
          margin-left: 200px;
        }

        .clear
        {
          clear: both;
        }

但布局很乱,一切都坏了。我怎么能改进它?我想要一个帖子网格:

Post 1     Post 2      Post 3

Post 4     Post 5      Post 6

Post 7     Post 8      Post 9

Post 10    Post 11    Post 11

感谢您的帮助和时间

1 个答案:

答案 0 :(得分:2)

为什么不使用桌子?如果你使用像bootstrap这样的CSS框架,你也可以使用类“col-md-4”。