• I am trying to pull in my recent posts and place them on my home page and I want to pull in the title and the first image that is displayed in the post to display on my homepage. What is the easiest way to do this?

    <ul>
    <?php
        /*
         * Displays a bar of the five latest listings added
         */
     		$myposts = get_posts('numberposts=5&category=4');
     		foreach($myposts as $post) :
       				setup_postdata($post);
    ?>
        <li><?php the_title(); the_content();?></li>
    <?php endforeach; ?>
    </ul>

    I was using that but the_content() displays all of the content not just the image. How can I do this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try this:

    <?php $myposts = get_posts('numberposts=5&offset=0');
    foreach($myposts as $post) :?>
    <?php $thumbnail = get_post_meta($post->ID, 'post_thumb', true); ?>
    <ul>
    <li><a href="<?php the_permalink(); ?>"><?php the_title();?>
    <img src="<?php echo $thumbnail; ?>" alt="<?php the_title(); ?>" />
    </a></li>
    </ul>
    <?php endforeach; ?>

    You’ll have to create a custom field in each of your posts called “post_thumb” and then assign an image to it that you want shown.

    Thread Starter EvanWatkins

    (@evanwatkins)

    is there another way to do it without using custom fields?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to add images to my recent posts?’ is closed to new replies.