August 24, 201016 yr Hi, I am trying to find out how i can post a post summary or excerpt next to the post image on my blog page in wordpress. You can see the current layout of my site here: http://www.voltronik.com The post summary and picture will replace my current system of just showing the 5 most recent posts. This site has it exactly how i want it - http://www.wpbeginner.com/category/wp-tutorials/ I've searched everywhere but i can't seem to find anyone that explains how to do it. Maybe i'm searching for the wrong thing i don't know but either way, i thought i'd ask here. Many thanks, -Jack
August 24, 201016 yr Put this code wherever you want a post image inside The Loop: <?php $custom = get_post_custom(); ?> <?php if ($custom['post-image']) : ?> <img src="<?php echo $custom['post-image'][0] ?>" width="125" height="125" alt="Post Image - <?php the_title_attribute(); ?>" class="post_image" /> <?php else : ?> <img src="<?php echo get_option('home'); ?>/wp-content/themes/YOUR_THEME/style/images/no_img.gif" width="125" height="125" alt="Post Image - <?php the_title_attribute(); ?>" class="post_image" /> <?php endif; ?> Then when adding a post in the admin area, under 'custom fields' use this format: post-image | http://yourdomain.com/images/your_post_image.gif on posts you want an image for. I'm sure there's a plugin, but I struggled to find one and this works perfectly well. Just style your posts accordingly - by the looks of your current website, you should be ok to work out the rest from here
August 24, 201016 yr Author Thanks for that andyl. I would however, like to use Wordpress 3's built in post-image functionality instead of inserting extra information into a custom field. Is this possible?
August 24, 201016 yr Of course, again in The Loop: <?php if (has_post_thumbnail() ) { the_post_thumbnail(array(180,180), array("class" => "post_image")); } ?> The first array param of this function is the width and height of the image respectively. To set a post image, just click 'Use as featured image' upon image upload. More info: http://codex.wordpress.org/Function_Reference/the_post_thumbnail
August 24, 201016 yr Author Ok, so the whole code would look like this?: ?php $custom = get_post_custom(); ?> <?php if (has_post_thumbnail() ) { the_post_thumbnail(array(180,180), array("class" => "post_image")); } ?> <?php else : ?> <img src="<?php echo get_option('home'); ?>/wp-content/themes/YOUR_THEME/style/images/no_img.gif" width="125" height="125" alt="Post Image - <?php the_title_attribute(); ?>" class="post_image" /> <?php endif; ?> Is that right?
August 24, 201016 yr Not quite, this should work inside The Loop: <?php if (has_post_thumbnail()) : ?> <?php the_post_thumbnail(array(180,180), array("class" => "post_image")); ?> <?php else : ?> <img src="<?php echo get_option('home'); ?>/wp-content/themes/YOUR_THEME/style/images/no_img.gif" width="125" height="125" alt="Post Image - <?php the_title_attribute(); ?>" class="post_image" /> <?php endif; ?>
August 24, 201016 yr Author Hi, I've tried this every which way but cannot get it to work. I have set my posts page to be 'Blog2' and have set up a custom template called 'Backup Blog' for the Blog 2 page. I have then set the Blog2 page to use the Backup Blog Template. I then edited the Backup Blog Template to include the code you gave me (this part i know i have done right). However, it still hasn't changed the layout. If you go to http://www.voltronik.com/blog2 you'll see what i mean (it is still displaying exactly as before). I think the problem lies in the fact that my Blog2 page is not using the Backup Blog template but somehow and for some reason, still using the default Main Index Template. Is this how it should work? Or is something wrong with my wordpress installation?
August 24, 201016 yr Simple way to test - in the new template you want to use, put a huge red block div somewhere in it. If you see it - you're using the correct template and something else is wrong.
August 24, 201016 yr Author OK, this is very wierd. I did what you suggested (well actually i just wrote test test test test across the template). I then set my blog to use my 'Blog Template' (which is how it was before) (see results at http://www.voltronik.com/blog). This works fine. If you now go to http://www.voltronik.com/blog2 it shows a placeholder for an image and test test test test written across the top of the template above the sidebar. This blog2 page is set to use the Blog Backup template. If i then change my reading settings to display my posts on the Blog2 page, it then just formats everything like it is on the existing page blog page. Can you explain why this might be?
Create an account or sign in to comment