简体   繁体   中英

Display a specific Text block from all posts

I'm using Wordpress latest version, a child theme and Visual Composer WPBakery Page Builder.

I'm getting my blog posts listed into a template php file using WP_Query and in that page I need to:

  1. display the Featured Image (which has caption) - DONE,
  2. the Post Date - DONE,
  3. and just a text block from the Post Content - a specific Row with a Column with a Text Block inside. This Text Block has a class name: bblog-text-row.

I need to echo/display/show just that text, but when I do the_content (); it outputs the VC shortcodes in a row as a raw text with shortcodes and the text. I also need to limit the text for this to 250 chars.

Here is the code I have just for the content part:

<?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
    }
?>

Thank you in advanced.

H

I found a small solution to my issue with getting the post content made with WPBakery Page Builder into a php template file listing all posts - like a blog page. Probably there might be clever and better ways to do it, but this solved my problem.

<?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(); ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM