[英]Get Wordpress excerpt in list of posts
I'm building a custom WordPress widget/plugin to return the title and excerpt of a post within a permalink to the article. 我正在构建一个自定义WordPress小部件/插件,以在文章的永久链接中返回帖子的标题和摘录。 I am almost there but am struggling with getting the excerpt to show.
我快到了,但正在努力摘录显示。 Here is my current code:
这是我当前的代码:
<?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>';
}
?>
It's an array so: 它是一个数组,所以:
$recent->post_excerpt
should be: 应该:
$recent['post_excerpt'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.