这当然是可能的,而且是WordPress的常见做法:
<?php
$q = new WP_Query(\'category_name=category_breaking\'); // query that gets all posts in category "category_breaking"
if( $q->have_posts() ) : // if there are posts returned by query...
echo "<div id=\'breaking_news\'>"; // start the breaking news section
while( $q->have_posts() ) : $q->the_post(); // start looping through query results
echo "<div class=\'bn_post\'>"; // single breaking news post start
echo "<h2>".get_the_title()."</h2>"; // display breaking news post title
if(has_post_thumbnail()) // if post has featured image set...
{
the_post_thumbnail(); // then display featured image
}
echo "</div>"; // close single breaking news post
endwhile;
echo "</div>"; // close breaking news section
endif;
?>