显示所有帖子中的特定文本块

问题描述 投票:0回答:1

我正在使用Wordpress的最新版本,子主题和Visual Composer WPBakery页面生成器。

我使用WP_Query将我的博客文章列出到php文件模板中,在该页面中,我需要:

  1. 显示特色图片(有标题)-完成,
  2. 发布日期-完成,
  3. 和只是发布内容中的一个文本块-特定的行,其中有一个带有文本块的列。该文本块的类名称为:bblog-text-row。

我只需要回显/显示/显示该文本,但是当我执行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

php wordpress visual-composer wpbakery
1个回答
0
投票

我找到了一个小解决方案,可以将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(); ?>
© www.soinside.com 2019 - 2024. All rights reserved.