gpt4 book ai didi

php - 在 Wordpress 中获取循环外的帖子摘录

转载 作者:行者123 更新时间:2023-12-02 07:05:21 27 4
gpt4 key购买 nike

过去三天,我一直在尝试使用以下代码获取帖子的摘录在循环之外:

1) <?php the_excerpt(); ?>
2) the_excerpt();
3) <?php get_the_excerpt(); ?>
4) get_the_excerpt();
5) '.apply_filters('the_excerpt',get_the_excerpt()).'

以上均无效,我认为这是因为我正试图将摘录置于循环之外。一些在插件页面上生成的文本,一些放在不同的位置时破坏了我的主题,还有一些完全没有任何作用。我什至在谷歌上搜索了从循环外部获取摘录的方法,但对于大多数方法,您必须输入要从中摘录的 post_id

这是应该输出异常的完整代码。我列出了我认为摘录应该放在哪里的 div“摘录”:

private function cg_get_title($single) {
global $cg_url;
if($this->params['title']) {
$title_array = get_post_meta($single->ID, $this->params['title']);
$title = $title_array[0];
if(!$title) {
$title = $single->post_title;
}
}
else {
$title = $single->post_title;
}
$returnlink = ($this->params['lightbox']) ? ('"' . $cg_url . '/includes/CatGridPost.php?ID=' . $single->ID . '" class="cgpost"') : ('"' . get_permalink($single->ID)) . '"';
$cgfontsize = $this->cg_get_font_size();
$cgtitle = '<div class="cgback cgnojs ' . $this->params['showtitle'] . '"></div><div class="cgtitle cgnojs '
. $this->params['showtitle'] . '"><p style="font-size:' . $cgfontsize . 'px;line-height:' . (1.2 * $cgfontsize) . 'px;">
<a href=' . $returnlink . '>' . $title . '</a></p><DIV ID="EXCERPT">EXCERPT SHOULD GO HERE</DIV></div>';
return $cgtitle;
}

同样,我现在真的不知道该去哪里,所以我来到了这里。有没有人可以帮助我使用此插件显示每篇文章的摘录?

最佳答案

假设您有一个帖子对象,您可以使用 $post->post_excerpt 获取未过滤的帖子摘录。在上面的代码中,您需要调用:

$excerpt = apply_filters('get_the_excerpt', $single->post_excerpt);

关于php - 在 Wordpress 中获取循环外的帖子摘录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13223455/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com