得到并显示5个发布的帖子,并在不同的div逐个wordpress显示

时间:2016-10-21 08:19:21

标签: php wordpress

在WordPress中,我想在一个单独的div中显示第一个发布的帖子,并在我最近发布的5个帖子中显示第二个单个div中的第二个发布的帖子。如何逐一发布每个发布的帖子并将其显示在页面的不同位置?

根据法典,但不能抓住具体的帖子

<?php
    $args = array( 'numberposts' => '5' );
    $recent_posts = wp_get_recent_posts( $args );
    foreach( $recent_posts as $recent ){
        echo '<li><a href="' . get_permalink($recent["ID"]) . '">' .   $recent["post_title"].'</a> </li> ';
    }
    wp_reset_query();
?>

1 个答案:

答案 0 :(得分:0)

不是一个好的解决方案,但这可以解决您的问题

<?php
    $args = array( 'numberposts' => '5' );
    $recent_posts = wp_get_recent_posts( $args );
    $i = 0;
    foreach( $recent_posts as $recent ){

        echo '<li class="post".$i><a href="' . get_permalink($recent["ID"]) . '">' .   $recent["post_title"].'</a> </li> ';
    $i++;
    }

    wp_reset_query();
?>

然后U将有post0,post1,2,3,4类,你可以从CSS到达所有这些类但重复一次这不是一个好的解决方案。