Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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>           
share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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 );
share|improve this answer
add comment

Try and use get_the_title() instead of the_title(), or pass third parameter to the_title() function as false, this solution isn't tested but I think it should help.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.