Post Title displaying but not in the wrapped HTML I need

I have a custom query to get the post title, permalink, and featured image. However the Post title is displaying but not in the container I want it in. here is the query

     <ul class="updatelist">
                    <?php 
                        $portquery = new WP_Query();
                        $portquery->query(array('cat' => 3, 'posts_per_page' => 2));
                        while ($portquery->have_posts()) : $portquery->the_post(); 
                            echo "<li class="firstupdate">";
                        ?>
                            <?php  
                                echo '<span class="thumb-title">'.the_title().'</span>';
                            ?>
                            <?php if (has_post_thumbnail( $post->ID ) ): ?>
                                <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
                                <?php 
                                    echo "<br><img src="".$image[0]."" />"; 
                                ?>
                            <?php endif; 

                            echo "</li>";
                            ?>

                    <?php endwhile; ?>
                    <li class="showupdates">
                        <a href="#">More Blog Updates</a>
                    </li>
                </ul>

and here is the output I get

    <ul class="updatelist">
                    <li class="firstupdate">
                                Another Portfolio Post
             <span class="thumb-title"></span>                                                                                                         
            <br>
              <img src="http://localhost/sosboston/wordpress/wp-content/uploads/2011/08/thumb-1.jpg">                               
               </li>                            
                    <li class="firstupdate">
                            Portfolio Post
             <span class="thumb-title"></span>                                                                                                      

              <br>
               <img src="http://localhost/sosboston/wordpress/wp-content/uploads/2011/08/thumb-1.jpg">                                                        
                </li>           

2 Answers
2

The problem is that the_title() itself echoes its value, so you can’t use it within an echo unless you set the echo parameter to false:

the_title( '', '', false );

Leave a Comment