1

我想获取特定 WordPress 类别的帖子标题、图片和摘录。我正在使用下面的代码来获取特定类别的帖子标题。

global $post;
$myposts = get_posts('numberposts=5&category_name=Cooling Towers');
foreach($myposts as $post) :
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?> 

任何想法,我如何获得特定 WordPress 类别的帖子图片和摘录?

4

1 回答 1

3

你可以用这个

<?php
    query_posts( array('posts_per_page'=>5, 'category_name'=>'Cooling Towers') );
    while ( have_posts() ) : the_post();
?>
    <h2><a href="<?php the_permalink(' ') ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
    <?php if ( has_post_thumbnail() ): // check for the featured image ?>
    <a href="<?php the_permalink(' ') ?>" title="<?php the_title(); ?>" class="opacity"><?php the_post_thumbnail(); ?></a> <!--echo the featured image-->
<?php
    endif;
    the_excerpt(); // echo the excerpt
    endwhile;
    wp_reset_query(); // resets main query
?>
于 2012-08-10T23:48:11.530 回答