dongma7796 2013-04-17 12:24
浏览 42
已采纳

两列(“间隙”)布局问题

I have created a two column layout wordpress loop and it is working almost good. The problem is that if I have really long content or image with large height I am getting some layout issues (having a large gap between my post's).

My two column loop looks like this:

<?php 
    $show_all_posts = '';
    $col = 1; //Let's create first column
    /*Let's add pagination to post page and static page*/
    if ( get_query_var('paged') ) {
    $paged = get_query_var('paged');
    } elseif ( get_query_var('page') ) {
    $paged = get_query_var('page');
    } else {
    $paged = 1;
    }

    query_posts(array(
     'paged' => $paged, 
     'post__not_in' => $show_all_posts//added blank value variable in order to show posts if template is         
    ));                   //assigned as Front Page!!
    if(have_posts()) : while(have_posts()) : the_post(); 


    ?>
<?php if ($col == 1) echo '<div class="row">';//If column 1 create first row ?>
<?php if ($col == 2) echo '<div class="row2">';//If column 2 create second row ?>
    <div <?php post_class('col'.$col); ?>>
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
        <div class="entry"> 
                <div class="featured_img">
                <?php the_post_thumbnail();
      echo '<div class="featured_caption">' . get_post(get_post_thumbnail_id())->post_excerpt . '</div>';?>
     </div><!--/featured_img-->
        <?php  // let's enable more link on pages...
        global $more;
        $more = 0;
        ?>
            <?php the_content(); ?>
            <p class="postmetadata">
            <?php _e('Filed under&#58;'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php  the_author(); ?><br/><?php the_tags(); ?><br/>
            <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?> <?php edit_post_link('Edit', ' &#124; ', ''); ?>
            </p>
        </div>
    </div>

    <?php /*Enable Two Column Layout*/
        if($col==1) {
        $col=2;
        echo "</div>";
        }
        else if($col==2)  {
        $col=1;
         echo "</div>";
        }

    endwhile; ?>
    <div class="clear"></div>
    <div class="navigation">

    <?php
    global $wp_query;
    $big = 999999999; // need an unlikely integer

    echo paginate_links( array(
    'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    'format' => '?paged=%#%',
    'current' => max( 1, $paged ),
    'total' => $wp_query->max_num_pages
    ) );
        ?>
</div>
<?php endif; ?> 
<?php wp_reset_query();?>       
</div><!--/blogs--> 
</div><!--/blogswrapper-->  

CSS looks like this:

 /*START styles for two column layout*/
 .row { clear: left; }
 .row2 { clear: right; }
 .col1 { width: 262px;float:left;display:block;position:relative;margin-right:8px;}
 .col2 { width: 262px;float:right;display:block;}
 /*END styles for two column layout*/

Can someone suggest some kind of a solution for removing a "gap" between my posts?

  • 写回答

1条回答 默认 最新

  • duandongjin5647 2013-04-17 12:32
    关注

    I am afraid this is how CSS floats work. In order to achieve what you intend, you can do one of the following:

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

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图