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

Display a specific Text block from all posts

我正在使用 Wordpress 最新版本、child 主题和 Visual Composer WPBakery Page Builder。

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

  1. 显示特色图片(有标题)- 完成,
  2. Post 日期 - 完成,
  3. 并且只是 Post 内容中的一个文本块 - 一个特定的行,其中有一列,里面有一个文本块。此文本块有一个 class 名称:bblog-text-row。

我只需要echo/display/show那个文本,但是当我做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 制作的 post 内容放入一个列出所有 post 的 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(); ?>