首页 文章

在wordpress中显示缩略图以及博客页面上的最新帖子

提问于
浏览
-1

<? php echo get _ _ post _ thumbnail($ post _ id); ? >

以上是我在页面上使用的代码,但页面上没有显示任何内容,想要显示最近帖子的缩略图以及博客页面上的内容

1 回答

  • 0

    你在使用WP_Query方法吗?如果没有那么使用

    $args = array(
        'post_type' => 'post',
        'posts_per_page'=> your_desired_number_of_post,
    );
    
    // The Query
    $the_query = new WP_Query( $args );
    
    // The Loop
    if ( $the_query->have_posts() ) {
        echo '<ul>';
        while ( $the_query->have_posts() ) {
            echo '<li>';
            $the_query->the_post();
             the_post_thumbnail();
             the_content();
            echo '</li>';
        }
        echo '</ul>';
    }
    else {
        echo 'no posts found';
    }
    /* Restore original Post Data */
    wp_reset_postdata();
    

相关问题