Add image to featured posts on front page
-
I have a theme that has “featured posts” on the front page. Currently those featured posts only show some of the text from that post. What I want to do is also show the image from the post.
Here is the code:
<td id="td-app-featured-post"> <div id="app-featured-post"> <h3> <?php _e( 'Featured Post', 'app_post' ); ?> </h3> <span class="app-pagination"> <a id="cafe-post-banner-prev" class="prev"></a> <p id="pagefeature">1 <?php _e( 'of', 'app_post' ); ?> 1</p> <a id="cafe-post-banner-next" class="next"></a> </span> <?php global $options; foreach ($options as $value) { if (get_settings($value['id']) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings($value['id']); } } if (empty($wpc_no_feat_post_index)) { $wpc_no_feat_post_index = "3"; } ?> <?php /* To display featured posts */ $wpc_no_feat_post_index =trim($wpc_no_feat_post_index); $querystr = " SELECT $wpdb->posts.* FROM $wpdb->posts, $wpdb->postmeta WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = '_is_featured' AND $wpdb->postmeta.meta_value = 'yes' AND $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'post' ORDER BY $wpdb->posts.post_date DESC LIMIT $wpc_no_feat_post_index"; $pageposts = $wpdb->get_results($querystr, OBJECT); $wpc_no_feat_post_perpage = trim($wpc_no_feat_post_perpage); if ($pageposts): ?> <div class="app-featured-news slideshow"> <?php global $post; ?> <?php $inc = 1; foreach ($pageposts as $post): ?> <?php setup_postdata($post); ?> <?php //{?> <?php if ($inc == 1 || $inc % $wpc_no_feat_post_perpage == 1) { ?> <ul style="position:relative;"> <?php } ?> <li class="post" id="post-<?php the_ID(); ?>"> <h2> <?php echo '<span class="app-index-category">'; the_category(', '); echo '</span><span class="app-category-arrow"></span>'; ?> <a class="app-index-title" href="<?php the_permalink() ?> " > <?php $tit = the_title('', '', FALSE); echo substr($tit, 0, 55); if (strlen($tit) > 55) echo " ..."; ?> </h2> <div class="app-date"><?php the_time('M, jS Y') ?></div> <div class="entry"> <?php //Display the post content text $postContent = substr(strip_tags($post->post_content), 0, 100); if (strlen($post->post_content) > 100) { $postContent .= '...'; } echo $postContent; ?> </a> </div> <div class="readmore"> <a href="<?php the_permalink() ?>"> <?php comments_popup_link('Comments', 'Comments', 'Comments'); ?> </a> </div> </li> <?php if ($inc % $wpc_no_feat_post_perpage == 0 || count($pageposts) == $inc) { ?> </ul> <?php } ?> <?php $inc++; endforeach; ?> </div> <?php endif; ?> </div> </td>
I think I need to include something like this…
//Display the post image $postImage = <img alt="" src="<?php echo $postImage; ?>" width="298" height="" />
to this…
<?php //Display the post content text $postContent = substr(strip_tags($post->post_content), 0, 100); if (strlen($post->post_content) > 100) { $postContent .= '...'; } echo $postContent; ?>
Can someone help me figure this out?
Thanks
- The topic ‘Add image to featured posts on front page’ is closed to new replies.