【问题标题】:Get Wordpress excerpt in list of posts在帖子列表中获取 Wordpress 摘录
【发布时间】:2014-06-01 20:39:05
【问题描述】:

我正在构建一个自定义 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>';
}
?>

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    这是一个数组所以:

    $recent->post_excerpt
    

    应该是:

    $recent['post_excerpt'];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多