我有一个显示摘录的自定义主题:
$data = get_the_excerpt();
if ($data) echo "<div class=\'excerpt\'>$data</div>";
如果在帖子编辑器Wordpress的摘录字段中未输入任何内容will automatically use the auto-generated teaser.我想摆脱这种行为。有什么办法吗?目前,我必须在每篇文章的摘录字段中输入一个空格,以防止自动摘要显示出来。
我有一个显示摘录的自定义主题:
$data = get_the_excerpt();
if ($data) echo "<div class=\'excerpt\'>$data</div>";
如果在帖子编辑器Wordpress的摘录字段中未输入任何内容will automatically use the auto-generated teaser.我想摆脱这种行为。有什么办法吗?目前,我必须在每篇文章的摘录字段中输入一个空格,以防止自动摘要显示出来。
尝试使用$post->post_excerpt
而是:
// globalize $post, just in case
global $post;
// find out if the post has a defined excerpt
$data = $post->post_excerpt;
// If so, output something
if ($data) echo "<div class=\'excerpt\'>$data</div>";
此方法将绕过中固有的自动摘录生成get_the_excerpt()
.EDIT
根据流行的需求,相同的代码,使用has_excerpt()
:// find out if the post has a defined excerpt
$data = ( has_excerpt() ? get_the_excerpt() : false );
// If so, output something
if ($data) echo "<div class=\'excerpt\'>$data</div>";
我使用的不需要使用的方法global $post;
就是在之前使用这个狙击手the_excerpt()
在回路内部。
<?php
if (!has_excerpt()) {
the_content(); //show the content if no excerpt
} else {
the_excerpt(); //else show excerpt
}
?>
如果你只想展示the_excerpt()
是否存在the_content()
您可以使用: if(has_excerpt()){
the_excerpt();
}
是否可以调用标记完整的\\u摘录()?我想创建一个特定类别中我的帖子的摘录列表,但我也希望从帖子内容中保留链接和格式。我目前使用的是\\u extract(),它在其他方面工作正常,但是标记被去掉了。我找不到可以放置在\\u摘录()上的筛选器来执行此操作,因此如果不这样做,是否可以筛选\\u内容()以提取前100个单词,并在末尾添加标记和阅读更多链接?