嗨:)可以在循环中显示4条新闻,但只有第一条新闻显示图像
实施例 图片http://oi58.tinypic.com/ea09i9.jpg
我的代码
<?php $postslist = get_posts('category=14&showposts=4&order=DESC'); foreach ($postslist as $post) : setup_postdata($post); ?>
<a href="<?php the_permalink(); ?>">
<img src="<?php bloginfo('template_directory'); ?>src=<?php echo catch_that_image() ?>&w=120&h=74&zc=1&q=100" alt="<?php the_title(); ?>"/></a>
答案 0 :(得分:0)
<?php
$i=1;
$postslist = get_posts('category=14&showposts=4&order=DESC');
foreach ($postslist as $post) : setup_postdata($post);
?>
<?php
if($i%4==0 && $i==1) : ?>
<a href="<?php the_permalink(); ?>">
<img src="<?php bloginfo('template_directory'); ?>src=<?php echo catch_that_image() ?>&w=120&h=74&zc=1&q=100" alt="<?php the_title(); ?>"/>
</a>
<?php
endif;
?>
<?php
$i++;
endforeach;
?>
//在分类后对您的代码进行实现,但添加您的帖子类型。
<?php
$i=1;
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'genre',
'field' => 'slug',
'terms' => 'news'
)
),
'post_type'=>'', //add your post type name
'posts_per_page' => 5,
'order' => 'DESC',
);
query_posts($args);
while ( have_posts() ) : the_post();
?>
<?php
if($i%4==0 && $i==1) : ?>
<a href="<?php the_permalink(); ?>">
<img src="<?php bloginfo('template_directory'); ?>src=<?php echo catch_that_image() ?>&w=120&h=74&zc=1&q=100" alt="<?php the_title(); ?>"/>
</a>
<?php
endif;
?>
<?php
$i++;
endwhile;
wp_reset_query();
?>