get_posts内get_template_part()

我试图在帖子上显示帖子列表,包括他们的标题和图像。Im 使用带有数组的函数来过滤帖子。我知道获取帖子图像,但是当我在输出上使用它时,它会向我显示当前帖子的图像,而不是过滤后的图像(get_posts()$template_loader->get_template_part( 'content-listing-image');$evento)


这是我的代码:


<?php 


$args = array(

    'author'         => $post->post_author,

    'order'          => 'ASC',

    'posts_per_page' => -1,

    'meta_query'     => array(

        array(

            'key'   => '_listing_type',

            'value' => 'event'

        )

    )

);


    $eventos = get_posts( $args );


    foreach ( $eventos as $evento ) {

        $template_loader = new Listeo_Core_Template_Loader;


        $output .= '<div><a href="'.get_permalink( $evento->ID ).'" target="_blank"> '.$template_loader->get_template_part( 'content-listing-image').' '.$evento->post_title.'</a></div>';  

    }


    if(!empty($eventos)) : ?> 

        <div id="listing-eventosartista" class="listing-section">

            <h3 class="listing-desc-headline margin-top-60 margin-bottom-30"><?php esc_html_e('Eventos','listeo_core'); ?></h3>

                <div class="single-item">

                    <?php echo $output; ?>

                </div>

        </div>

    <?php endif ?>

我想向每个(帖子)显示相应的图像。$evento


ITMISS
浏览 125回答 1
1回答

慕妹3242003

您可以使用get_the_post_thumbnail(),如下所示$output&nbsp;.=&nbsp;'ID&nbsp;).'"&nbsp;target="_blank">&nbsp;'.get_the_post_thumbnail(&nbsp;$evento->ID).'&nbsp;'.$evento->post_title.'';
打开App,查看更多内容
随时随地看视频慕课网APP