我很难只在每个类别的第一篇文章中设置特色图像,而其余的只显示文章标题。到目前为止,我一直设法用缩略图显示每个类别中的最新帖子,但我找不到方法,只能用缩略图显示第一篇帖子,其余的都是标题。有解决方案吗?这是我的代码:
<?php
//get terms (category ids 11,2,33,34), then display one post in each term
$taxonomy = \'category\';// e.g. post_tag, category
$param_type = \'category__in\'; // e.g. tag__in, category__in
$term_args=array(
\'include\' => \'4,5,6,7\',
\'orderby\' => \'name\',
\'order\' => \'ASC\'
);
$terms = get_terms($taxonomy,$term_args);
if ($terms) {
foreach( $terms as $term ) {
$args=array(
"$param_type" => array($term->term_id),
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
\'posts_per_page\' => 1,
\'caller_get_posts\'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
//Panikos Remove echo \'Latest Post in \'.$taxonomy .\' \'.$term->name;
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div class="post_home_main">
<!-- Add timthumb to post featured image -->
<?php
$image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_url($image_id);
if ($image_url) {
?>
<img src="<?php bloginfo(\'template_directory\'); ?>/scripts/timthumb.php?src=<?php echo $image_url; ?>&w=196&h=115&q=1000" alt="<?php the_title();?>" />
<!-- // Add timthumb to post featured image -->
<?php } else { ?>
<img src="<?php echo bloginfo(\'template_directory\') . \'/images/no-image.jpg\'; ?>" alt="No image available" class="panikosule" />
<?php } ?>
<a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
<?php the_excerpt(); ?>
</div>
<?php
endwhile;
}
}
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
<span class="arrow"></span> </div>