如何在不使用PHP循环的情况下分别显示第一篇和第二篇最近的文章?

如何在不使用PHP循环的情况下分别显示第一篇和第二篇最近的文章?,php,wordpress,Php,Wordpress,我需要在不使用循环的情况下,分别显示类别中的第一个和第二个最新帖子。下面是我尝试过的;item1 div应显示最近的,item2 div应显示第二个最近的 <div class = 'item item1'> <?php get_posts('numberposts=1&offset=1&category='); ?> <?php while (have_posts()) : the_post(); ?> <a href=

我需要在不使用循环的情况下,分别显示类别中的第一个和第二个最新帖子。下面是我尝试过的;item1 div应显示最近的,item2 div应显示第二个最近的

  <div class = 'item item1'>
  <?php get_posts('numberposts=1&offset=1&category='); ?>
  <?php while (have_posts()) : the_post(); ?>
  <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><h3><?php the_title(); ?></h3></a>
  <?php endwhile;?>
    </div>

   <div class = 'item item2'>
  <?php get_posts('numberposts=2&offset=1&category='); ?>
  <?php while (have_posts()) : the_post(); ?>
  <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><h3><?php the_title(); ?></h3></a>
  <?php endwhile;?>
    </div>

有一个内置函数,名为:
wp\u get\u recent\u posts()

使用以下参数:

<?php $args = array(
    'numberposts' => 10,
    'offset' => 0,
    'category' => 0,
    'orderby' => 'post_date',
    'order' => 'DESC',
    'include' => ,
    'exclude' => ,
    'meta_key' => ,
    'meta_value' =>,
    'post_type' => 'post',
    'post_status' => 'draft, publish, future, pending, private',
    'suppress_filters' => true );

    $recent_posts = wp_get_recent_posts( $args, ARRAY_A );
?>

例如:

<?php
    $args = array( 'numberposts' => '2' );
    $recent_posts = wp_get_recent_posts( $args );
    foreach( $recent_posts as $recent ){
        echo '<div><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" ><h3>' .   $recent["post_title"].'</h3></a></div>';
    }
?>


来源:

你可以用它来检索两篇文章,并将它们放在一个数组中,以便在任何你喜欢的地方使用。

为什么不
从表限制2中选择*
,将它放在一个数组中,并使用第一个和第二个索引?我需要div名称保持不变,以便滑块可以使用。有没有办法让代码只显示第二篇最近的文章?