我正在使用Wordpress的最新版本,子主题和Visual Composer WPBakery页面生成器。
我使用WP_Query
将我的博客文章列出到php文件模板中,在该页面中,我需要:
我只需要回显/显示/显示该文本,但是当我执行the_content ();
时,它会将VC短代码连续输出为带有短代码和文本的原始文本。我还需要将此文本限制为250个字符。
这里是内容部分的代码:
<?php
$query = new WP_Query( array( 'post_type' => 'post' ) );
$posts = $query->posts;
foreach($posts as $post) {
?>
<p>
<?php
$char_limit = 250; //character limit
$content = $post->post_content; //contents saved in a variable
echo substr(strip_tags($content), 0, $char_limit);
?>
</p>
<?php
}
?>
谢谢你。
H
我找到了一个小解决方案,可以将WPBakery Page Builder的帖子内容放入一个列出所有帖子的php模板文件中,例如博客页面。可能会有更好的聪明方法,但这解决了我的问题。
<?php
$the_query = new WP_Query( array( 'post_type' => 'post' ) );
while ($the_query->have_posts() ) {
$the_query->the_post(); ?>
<!-- you may add more post content here
I just want to refer to the content, not meta content or custom fields -->
<p class="bowe-post-content-bloc">
<?php
$conteudo = get_the_content(); //get ALL content for the post
$padrao = array('(\[vc(.?)\])', '(\[/vc(.?)\])','(\[booom_baannng_anypostsharebuttons])'); //create a filter
$reparacao = preg_replace ($padrao, "",$conteudo ); //remove content based on filter
echo wp_trim_words ( $reparacao, 40, '...'); //display only 40 words
?>
</p>
<!-- you may add more post content here
I just want to refer to the content, not meta content or custom fields -->
<?php
}
wp_reset_postdata(); ?>