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 に答える