在两列中显示Wordpress博客帖子?

时间:2014-01-10 13:32:22

标签: wordpress

您好我需要修改我的WP主题,以便在两列中显示最新的帖子标题和精选图片。

我已经尝试了几个小时,但我无法使其工作,任何建议?

这是博客部分自定义php文件的当前代码,我可以做一个wipeout并忘记这段代码并从头开始,我已经尝试但我无法使其工作......真的很感激任何提示/建议..我不是专科医生,我正在学习:)。

 <div class="main-container">
            <div class="main wrapper clearfix">



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


<aside class="left"></aside>
<article>
  <h1><?php the_title(); ?></h1>
<?php endwhile; ?>


<ul class="posts">

<?php 
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('cat=9&posts_per_page=10&&paged=' . $paged); 
?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
   <li>

      <h2><?php the_title(); ?></h2><span class="tags"><?php
$posttags = get_the_tags();
if ($posttags) {
  foreach($posttags as $tag) {
    echo $tag->name . ' '; 
  }
}
?></span>
  <time datetime="<?php the_time( 'Y-m-d' ); ?>" pubdate><?php the_time('j F Y'); ?></time> 

  <?php global $more;
    $more = 0;
    the_content('Read more'); ?>


  </li>
<?php endwhile; endif; ?>

</ul>

<div class="pagination">
<?php
global $wp_query;

$big = 999999999; // need an unlikely integer

echo paginate_links( array(
  'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
  'format' => '?paged=%#%',
  'current' => max( 1, get_query_var('paged') ),
  'total' => $wp_query->max_num_pages
) );
?></div>

</article-blog> 

3 个答案:

答案 0 :(得分:2)

答案 1 :(得分:0)

你能不能用CSS做到这一点?只需将所有LI设置为(例如)width:50%;,然后将它们全部向左浮动,它们应该以两列布局并排放置。

li {
    display:block;
    width:50%;
    float:left;
}

答案 2 :(得分:0)

我遇到了同样的问题,这帮助了我 - http://wordpress.org/support/topic/how-to-show-front-pagelatest-posts-in-two-columns#post-4500258

@media screen and (min-width : 640px){

.home ul.index > li{

    display:inline-block;
    clear:none;
}

.home .index > li:nth-child(odd){

    width:50%;
    float:left;
    border:1px solid #fff;
    clear:both;
}
.home .index > li:nth-child(even){

    width:46%;
    float:right;
    border:1px solid #fff;
}}
相关问题