Creating an excerpt without images (4 posts)

  1. bengiordano
    Posted 5 years ago #

    Looking to create an excerpt from a specific category. However, the code is pulling the image code from the post instead of the plain text. I want to filter out all html tags and just get plain text. Must be missing something simple.

    Code is as follows:

    $latestPosts = new WP_Query();
    $args = array('post_type' => 'post', 'order' => 'DESC', 'posts_per_page' => 1, 'cat' => '11' );
              <?php foreach($latestPosts->posts as $blogPost): ?>
              <?php $authorInfo = get_userdata($blogPost->post_author); ?>
              <p> <strong><?php echo $blogPost->post_title; ?></strong><br/>
                <?php echo date('F d, Y', strtotime($blogPost->post_date)); ?> | POSTED BY <?php echo $authorInfo->user_login; ?> <?php echo strip_tags(substr($blogPost->post_content, 0, 110)); ?><br />
                <a href="<?php echo get_permalink($blogPost->ID); ?>">read more...</a> </p>
              <?php endforeach; ?>
  2. bengiordano
    Posted 5 years ago #

    Fixed! Had the PHP functions nested the wrong way...

    This is the correct line:
    <?php echo substr(strip_tags($blogPost->post_content), 0, 115); ?>

    Hopefully this helps someone down the road!

  3. SocialBlogsite
    Posted 4 years ago #

    Will that strip manually typed paragraphs?

  4. Michael
    Forum Moderator
    Posted 4 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic