【问题标题】:Is it possible to get Elementor Style of post content in $post->post_content?是否可以在 $post->post_content 中获取帖子内容的 Elementor 样式?
【发布时间】:2022-07-02 19:56:03
【问题描述】:

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

我做了什么?

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>';

}

请帮忙!任何形式的建议或文档将不胜感激。

【问题讨论】:

    标签: php wordpress widget elementor


    【解决方案1】:

    尝试使用

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-10
      • 1970-01-01
      • 2010-10-16
      • 2021-08-31
      • 1970-01-01
      • 2010-12-22
      • 1970-01-01
      • 2016-08-05
      相关资源
      最近更新 更多