• I’m creating a WordPress site and I’m doing something I’ve never done before in all the years I’ve used WP. I’m creating a homepage where I have two div and each div calls the last article from a blog category. OK, I know how to do that. The Loop. However, what I want to display is the Title, Excerpt and a photo relating to the article that actually does not show up in the article itself or if it does, it’s a different size. You’ve seen homepages like this before. Primarily on news sites. Now getting the title and excerpt to appear isn’t an issue. I’m just trying to figure the best solution to upload an image to the uploads folder and then call that image just for the excerpt. Do I need to create another field in the New Post area? Or does it require a lot of PHP code?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Here’s what I use:

    <?php
    						if ($images = get_children(array(
    						'post_type' => 'attachment',
    						'numberposts' => 1,
    						'post_status' => null,
    						'post_parent' => $post->ID,)))
    
    						foreach($images as $image) {
    						$attachment=wp_get_attachment_image_src($image->ID, $size);
    						?><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo $attachment[0]; ?>&h=200&w=200&zc=1" alt="<?php the_title(); ?>" /></a>
    						<?php } else { ?>
               					<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><img src="<?php bloginfo('template_directory'); ?>/images/preview.jpg" alt=""/></a>
               				<?php } ?>

    You’ll need to make sure you download the timthumb.php script (just google it) and put it in your theme folder in a folder called “scripts”.

    Basically what it does is it will pull the first image that’s uploaded via the uploader in the write panel… Then it uses timthumb to resize/crop the image to your specifications.

    Thread Starter databell96

    (@databell96)

    Cool! I will try that. Thanks.

    Thread Starter databell96

    (@databell96)

    OK, I got it working to a point. If you go to https://www.pattyspizza.com/blog1/ you’ll see it’s there. Two issues still remain. The first is that theimage is showing up twice and I only want it to appear once. Secondly, my social bookmarks plugin is also appearing and that’s fine for the blog page but not here on the homepage. How do I lose that?

    Finally, you see the empty box next to where the photo is? I want to use the script again for that area using the latest post from a different category using the loop. Problem is if I do that, the scripts basically cancel each other out. So you just have two background images. How can I run a duplicate of your script alongside the other script on the same home.php page?

    Thanks for all the advice so far. I really appreciate the assistance.

    Thread Starter databell96

    (@databell96)

    Solved the picture problem by using the_excerpt instead of the_content. Still got to lose the Bookmarks section beneath the copy though.

    Thread Starter databell96

    (@databell96)

    Solved another issue. Just copied all the code from the div with the loop and Tim Thumb script, placed it in the next div and changed $myquery to $myquery2 (or anything you want) and it worked. So the final thing is to remove that Bookmark area somehow.

    Thread Starter databell96

    (@databell96)

    Solved the last piece of the puzzle! There was a setting in Social Bookmarks to get rid of the Bookmarks in list view and only show if for single posts. Perfect!

    Sorry I wasn’t around to answer your latest questions… I’ve been pretty swamped with support requests for my plugin lately.

    I’m glad to see you got it figured out!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Home Page Question: How to place an image alongside an excerpt?’ is closed to new replies.