WordPress查询带有缩略图和最近帖子标题的帖子



我是WordPress主题开发的初学者。我正在开发一个主题。我正在经历一个问题。

在我的索引.php页面中,我希望最新的帖子显示为缩略图。显示第二、第三和第四个最新帖子,仅显示标题。我还有五个类别。我希望帖子按类别显示。

现在该怎么做。谁能帮我???

请在创建主题之前先查看 wordpress 查询:http://codex.wordpress.org/Class_Reference/WP_Query 。关于这个问题。试试这个:

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

干杯!

请使用以下代码进行测试:

<?php $the_query = new WP_Query('posts_per_page=5&cat=18');
$count = 0;
// The Loop
if ( $the_query->have_posts() ) {
        echo '<ul>';
    while ( $the_query->have_posts() ) : $the_query->the_post();
        if($count == 0){?>
            <?php the_post_thumbnail('medium'); ?>

                                <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( '%s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
                                    <?php the_title();  ?>
                                </a>
    <?php
        }else{ ?>
           <li class="list">
                                <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( '%s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
                                    <?php the_title();  ?>
                                </a>
                        </li>
            <?php
        }
        $count++;
         echo "</li>";
    endwhile;
} else {
    echo "No Post Found!";
}
/* Restore original Post Data */
wp_reset_postdata();
?>

最新更新