WordPress - 以自定义方式显示最后的帖子


Wordpress - displaying last posts custom way

我是wordpress的新手。我有一个任务来显示最后 3 个帖子,但不是以通常的方式。帖子div 将有不同的大小。这是我的 html 代码。

<div class="latest-posts">
       <div class="latest-posts-news-left">NEWS</div>
       <div class="latest-posts-news-right">
           <div class="l">
               <div class="latest-posts-news-first">first post</div>
               <div class="latest-posts-news-second">second post</div>
           </div>
           <div class="r">
               <div class="latest-posts-news-third">third post</div>
           </div>
       </div>
</div>

这是向您展示它的外观的图像 http://img607.imageshack.us/img607/5194/1n3u.png

所以左边有两个div,右边有一个更长的div。

在这种情况下,我应该如何循环?如果您能给我一个工作示例,我将不胜感激,因为我正在寻找答案,但没有找到。

多谢!

<?php
$queryObject = new WP_Query( 'post_type=post&posts_per_page=5,orderby=post_date,order=DESC' );
// The Loop!
if ($queryObject->have_posts()) {
while ($queryObject->have_posts()) {
$queryObject->the_post();
?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php
}
}
?>

试试这个

<?php 
// the query
$the_query = new WP_Query( 'post_type=post&posts_per_page=3,orderby=post_date,order=DESC' );
 ?>
<?php if ( $the_query->have_posts() ) : 

        $count_rows  = 0;
?>
<div class="latest-posts">
       <div class="latest-posts-news-left">NEWS</div>
       <div class="latest-posts-news-right">
  <!-- the loop -->
  <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <?php if( ( $count_rows + 1 ) % 2 == 0 ) { ?>
     <div class="l">
               <div class="latest-posts-news-first"><?php the_post(); ?></div>
               <div class="latest-posts-news-second"><?php the_post(); ?></div>
           </div>
       <?php  } else { ?>
        <div class="r">
               <div class="latest-posts-news-third"><?php the_post(); ?></div>
           </div>
  <?php } 
  $count_rows++; 
  endwhile; ?>
  <!-- end of the loop -->
</div>
</div>
  <?php wp_reset_postdata(); ?>
<?php else:  ?>
  <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>