是否可以在 $post->post_content 中获取帖子内容的 Elementor 样式?

发布于 2025-01-15 12:53:32 字数 233 浏览 1 评论 0原文

我想要得到什么?
我正在创建 Elementor 自定义小部件。这将输出特定帖子类型的帖子列表。到目前为止一切都很好。我得到了我需要的一切。但问题是,我必须使用 Elementor 自定义(使用 Elementor 创建)输出帖子内容。我使用过 WP_Queryget_posts()。我得到的只是原始 HTML,没有任何 Elementor 自定义类

What I am trying to get?
I'm creating an Elementor custom widget. which will output a list of posts of a specific post type. Thus far everything is ok. I'm getting all I need. But the issue is, I have to output post content with its Elementor customization(created with Elementor). I've used WP_Query and get_posts(). all I get is raw HTML without any Elementor customization classes ????. Please check the image
This is the issue

What I've done?

public function wp_post_list($slug_name,$order='ASC',$orderby='date'){
        $args = [
                'post_type' => $slug_name,
                'posts_per_page' => -1,
                'orderby'          => $orderby,
                'order'            => $order,
            ];
            return $all_posts = new \WP_Query($args);
    }
public function post_list($slug_name,$order='ASC',$orderby='date'){
            $args = [
                    'post_type' => $slug_name,
                    'posts_per_page' => -1,
                    'orderby'          => $orderby,
                    'order'            => $order,
                ];
            $all_posts = get_posts($args);
            return $all_posts;
    }

public function skin_time_line($slug){

        $st = $this->get_settings_for_display();
        $order = $st['post_order'];
        $orderby = $st['post_orderby'];
        $posts = $this->post_list($slug,$order,$orderby);
        $all_posts = $this->wp_post_list($slug,$order,$orderby);  
   
        echo '<div class="time_line">';

         foreach($posts as $post){
           echo '<div class="time_line_post">';

             echo '<div class="tl_content">'.$post->post_content.'</div>';
              //Getting just the HTML without any class

           echo '</div>';
         }
        echo '</div>';

//or With WP_Query

        echo '<div class="content">';
        $all_posts = $this->wp_post_list($slug,$order,$orderby);
                if ($all_posts->have_posts()) : 
                    while ($all_posts->have_posts()) : $all_posts->the_post();
                            the_content(); // Getting just the HTML without any class
                    endwhile;
                endif;
            echo '</div>';
        echo '</div>';

}

Please help! Any kind of suggestion or documentation would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泅渡 2025-01-22 12:53:32

尝试使用

echo Elementor\Plugin::instance()->frontend->get_builder_content_for_display(get_the_ID());

用于渲染并返回包含所有 Elementor 元素的帖子内容。

https://github.com/elementor/elementor/blob/9aadba35a9ad52cd5e9cbef55a5761f47403491c/includes/frontend.php#L1020-L1025

如果您只想要可以使用的内容

echo Elementor\Plugin::instance()->frontend->get_builder_content(get_the_ID());

Try to use

echo Elementor\Plugin::instance()->frontend->get_builder_content_for_display(get_the_ID());

Used to render and return the post content with all the Elementor elements.

https://github.com/elementor/elementor/blob/9aadba35a9ad52cd5e9cbef55a5761f47403491c/includes/frontend.php#L1020-L1025

if you want only the content you can use

echo Elementor\Plugin::instance()->frontend->get_builder_content(get_the_ID());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文