Forums
Forums / Fixing WordPress / Thumbnails in sidebar
(@bjihalliday)
14 years, 3 months ago
I am trying to get the title of each post below the thumbnails in my sidebar.
The code I am currently using is
<div class="th fl"><?php $thumbnails = get_posts('numberposts=4'); foreach ($thumbnails as $thumbnail) { if ( has_post_thumbnail($thumbnail->ID)) { echo '<a href="' . get_permalink( $thumbnail->ID ) . '" title="' . esc_attr( $thumbnail->post_title ) . '">'; echo get_the_post_thumbnail($thumbnail->ID, 'thumbnail'); echo '</a>'; } } ?> </div>
This draws the thumbnails into the sidebar but I cannot seem to be able to get the post titles below these.
Can someone please help.
(@alchymyth)
have you tried to use
echo $thumbnail->post_title;
Thank you very much, that has worked wonderfully.
The topic ‘Thumbnails in sidebar’ is closed to new replies.