[英]How do I get the rendered content of a post created with Divi in wordpress
I have a wordpress site and the Divi plugin used to create pages with the visual editor.我有一个 wordpress 站点和用于使用可视化编辑器创建页面的Divi插件。 I am developing a plugin that needs to get the content of some pages.
我正在开发一个需要获取某些页面内容的插件。 I know that the page content created with Divi is stored on the database with shortcodes.
我知道使用 Divi 创建的页面内容使用短代码存储在数据库中。
When I access the page content using wordpress functions I get the content full of shortcodes, but whenever you open the page built with Divi we can see the rendered HTML generated by these shortcodes.当我使用 wordpress 函数访问页面内容时,我得到的内容充满了短代码,但是每当您打开使用 Divi 构建的页面时,我们都可以看到这些短代码生成的渲染 HTML。 I want to be able to render the pages as rendered when you visit the site.
我希望能够在您访问网站时呈现页面。 I do not want to strip the shortcodes of the post.
我不想删除帖子的短代码。
Is there a wordpress function that renders the content as rendered when you open the page or is there a Divi function that already does it that I can use?是否有一个 wordpress 函数可以在您打开页面时将内容呈现为呈现形式,或者是否有我可以使用的 Divi 函数?
I already tried using both methods我已经尝试使用这两种方法
$post = get_post(1);
//Method 1
echo do_shortcode( $post->post_content) ;
//Method 2
echo apply_filters('the_content', $post->post_content);
but none of these rendered the Divi shortcodes to html.但这些都没有将 Divi 短代码呈现为 html。
尝试使用这样的东西
$content = apply_filters( 'the_content', get_the_content() );
Full code:完整代码:
// Render content of Divi page "404 page"
$args = array(
'page_id' => 10302
);
$post_query = new WP_Query( $args );
if ( $post_query->have_posts() ) {
while ( $post_query->have_posts() ) {
$post_query->the_post();
$content = apply_filters( 'the_content', get_the_content() );
echo $content;
}
}
wp_reset_query();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.