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>
The problem is that
the_title()
itself echoes its value, so you can’t use it within anecho
unless you set the echo parameter to false:Try and use
get_the_title()
instead ofthe_title()
, or pass third parameter tothe_title()
function asfalse
, this solution isn’t tested but I think it should help.