在过去的三天里,我一直在尝试使用以下代码在Loop 之外摘录:

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->post_excerpt获得未经过滤的文章摘录。在上面的代码中,您需要调用:

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

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

10-11 13:00