首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何展示post_excerpt?

如何展示post_excerpt?
EN

Stack Overflow用户
提问于 2016-08-25 12:42:41
回答 2查看 467关注 0票数 0

我是wordpress主题的新手。我正在开发一个主题,但使用post_excerpt它不显示内容。

代码语言:javascript
复制
$recent_posts = wp_get_recent_posts($args);
    foreach( $recent_posts as $recent ){
              echo $recent[post_content];

}

为什么它没有显示。但是post_content它显示的是内容。

EN

回答 2

Stack Overflow用户

发布于 2016-08-25 13:00:35

在WordPress循环操作中显示

帖子摘录。

假设你在帖子中的摘录部分发布了一些东西。

代码语言:javascript
复制
$recent_posts = wp_get_recent_posts($args);
print_r($recent_posts);
foreach( $recent_posts as $recent )
{
 echo $recent[the_excerpt];
}

这将使您能够单独显示帖子摘录。

票数 0
EN

Stack Overflow用户

发布于 2016-08-25 13:11:07

另一种解决方案可以是:

代码语言:javascript
复制
<?php
    global $post;
    $recent_posts = wp_get_recent_posts($args);
     if( $recent_posts-> have_post()) : while( $recent_posts->have_post()) : $recent_posts->the_post(); ?>
       <?php echo $post->post_excerpt; ?>
       <?php endwhile; endif; ?>
 <?php wp_reset_postdata(); ?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39136816

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档