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

标签 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

感谢您的帮助和时间

最佳答案

为什么不直接使用表格呢?如果您使用的是像 bootstrap 这样的 CSS 框架,您还可以应用类“col-md-4”。

关于php - 在配置文件选项卡中添加列结构(如网格),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34024091/

相关文章:

php - 安装 ssl 证书后重定向错误太多

php - 如何将 DIV 元素的值提交到基于 PHP 的表单中

php - 使用 $_GET ['' ]; value inside $_POST ['' ] 并提交到同一页面并在同一页面显示

css - 将 div 放在另一个 div 中?

javascript - 屏幕宽度 Javascript 不适用于所有 Android 设备

html - 带有滚动内容的 CSS 叠加层

php - 解析RDF XML文件得到所有rdf :about values

php - 在 PHP 中转置多维数组

如果我在它后面写悬停,css 伪类事件将不起作用

css - Bootstrap .page-header 背景图片