单个帖子的模板摘录

时间:2017-10-25 22:13:45

标签: wordpress

在主题中,我在get_the_excerpt中使用index.php,我在其中使用循环显示多个帖子的标题,摘录,...并按预期工作。摘录/预告片会手动标记为"阅读更多"标签

但是,我也希望在get_the_excerpt中使用single.php,而不是只接收文本直到"阅读更多"标签,我得到前55个单词。

documentation说:

  

<!--more-->快速标签无法操作,在只显示一个帖子的模板中会被忽略,例如single.php。

好的,如果我希望摘录仅包含single.php中的快速标签,我该怎么办?

1 个答案:

答案 0 :(得分:3)

我相信你可以利用$more变量利用WordPress的内置功能完成你想要的任务。

为了在更多快速标记之前显示内容,您应该可以在single.php上执行此操作:

// Declare global $more (before the loop).
global $more;

while( have_posts() ) {
   // Set (inside the loop) to display content above the more tag.
   $more = 0;
   // call the_post() to prepare post variables / functions
   the_post();
   // output your markup, post title, etc...
   // then this the_content() should render only the content before the more quicktag
   the_content( 'More ...' );
}