簡體   English   中英

在帖子列表中獲取Wordpress摘錄

[英]Get Wordpress excerpt in list of posts

我正在構建一個自定義WordPress小部件/插件,以在文章的永久鏈接中返回帖子的標題和摘錄。 我快到了,但正在努力摘錄顯示。 這是我當前的代碼:

<?php
$args = array( 'numberposts' => '5' );

$recent_posts = wp_get_recent_posts( $args );

foreach( $recent_posts as $recent ){

    $categories = get_the_category($recent["ID"]);

    $excerpt = apply_filters('get_the_excerpt', $recent->post_excerpt);

    echo '<a class="m-item  diet-and-nutrition" href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" > <div class="pix"></div><div class="eyebrow"> <b>' . $categories[0]->name . '</b> / '.   $recent["post_date"].'</div> <figure>' .  get_the_post_thumbnail($recent["ID"], 'full') . '<figcaption class="center"> <span> <h4>'.  $recent["post_title"].'</h4> </span> <span> <p>'.  $excerpt .'</p> </span> </figcaption> </figure> </a>';
}
?>

它是一個數組,所以:

$recent->post_excerpt

應該:

$recent['post_excerpt'];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM