WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display post excerpts without images. (5 posts)

  1. bencharity
    Member
    Posted 4 years ago #

    At the end of each of my pages I display the two latest posts (with a short excerpt) as part of my page footer.

    However the images in my posts are screwing it up. Is there a way to call the excerpt excluding the images of a post? It seems as though this should be a simple command, but I can't seem to find any documentation.

    My code:

    <div id="latestBlog">
    	<?php $temp_query = $wp_query; ?>
    
    <?php
    query_posts("cat=7,10,8&showposts=2");
    
    global $more;
    // set $more to 0 in order to only get the first part of the post
    $more = 0;
    ?>
    
    <?php while (have_posts()) : the_post(); ?>
      <div class="post" id="post-<?php the_ID(); ?>">
    
      <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    
     <div class="entry">
       <?php the_content('<span class="moretext">[continue reading...]</span>'); ?>
     </div>
    	</div>
    <?php endwhile; ?>
    
    </div>  <!-- end #latestBlog -->

    You can see how it is screwing up the bottom of my page here: http://benjamincharity.com/freelance/process/

    Thanks in advance!
    Benjamin

  2. MichaelH
    Member
    Posted 4 years ago #

    Might want to look at the Excerpt article.

  3. bencharity
    Member
    Posted 4 years ago #

    Thanks Michael,

    I've read this: http://codex.wordpress.org/Template_Tags/the_excerpt

    And this: http://codex.wordpress.org/Function_Reference/apply_filters

    But neither say anything about not including images.

    Any ideas?

  4. MichaelH
    Member
    Posted 4 years ago #

    Someone else might need to jump in here, cause I thought strip_tags caused img tags to be removed from the auto excerpt...

  5. bencharity
    Member
    Posted 4 years ago #

    Ok I have acheived my goal using this snip of code:

    <?php
    query_posts('showposts=2&cat=7');
    while(have_posts()) : the_post();
    ?>
    
    	<div class="similarSingle">
    		<h5><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h5>
    
    		<?php the_excerpt(); ?>
    
    	</div>  <!-- end .similarSingle -->
    
    <?php endwhile; ?>

    However I'm not sure why this works when the other does not. I'd love to actually learn why instead of just using this blindly. Any wise words would be welcome!

Topic Closed

This topic has been closed to new replies.

About this Topic