Wordpress-仅1张图像用于4个post循环

Wordpress-仅1张图像用于4个post循环,wordpress,loops,Wordpress,Loops,Hi:)可以在循环中显示,4条新闻,但只有第一条新闻显示图像 范例 形象 我的代码 <?php $postslist = get_posts('category=14&showposts=4&order=DESC'); foreach ($postslist as $post) : setup_postdata($post); ?> <a href="<?php the_permalink(); ?>"> <img src="<?

Hi:)可以在循环中显示,4条新闻,但只有第一条新闻显示图像

范例 形象

我的代码

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


//分类后,在实现中添加代码,但添加帖子类型

<?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();
?>


post
catch_that_image
function'function catch_that_image(){global$post,$first_img='';ob_start();ob_end_clean();$output=preg_match_all('//i',$post->post_content,$matches);$first_img=$matches[1][0];@user3766356如果您想添加信息,请编辑您的问题,并使用注释来通知某人您编辑了它。正如您所看到的,代码在注释中…嗯…不可读;-)嗨@ravipatel,我的代码是用于分类的,因为我可以在代码中实现您的代码?
src=&w=100&h=102&zc=1&q=100“alt=”“/>
<?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();
?>