2012-08-10 222 views
1

我想获得特定WordPress类别的帖子标题,图片和摘录。我正在使用下面的代码来获取特定类别的帖子标题。如何获取特定类别的标题,图片和帖子的摘录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类别?

回答

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 
?> 
+1

感谢,效果不错:) – 2012-08-11 13:04:47

相关问题