1

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

4

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 );
4

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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