• Resolved orbital2000

    (@orbital2000)


    I’ve designed a blog index page that will display the five latest posts. Each post will include an image, post title, date/comments and an excerpt. So far, I have the following code, along with a custom field in each post with name=thumbnail and value= image path. The images displayed won’t appear in the posts, so they can be stand alone images that only appear on the blog index page.

    <div class="post_wrap">
    			<h2 class="heading">Recent Posts</h2>
    
                	<div style="border-bottom:1px dotted #C0C0C0; margin-bottom:10px; margin-left:14px; margin-right:14px; padding:0px
                    0px 10px 0px; clear:both;"></div>
    
                <div class="post_img">
    				<?php $recent = new WP_Query("cat=6&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
    				<?php if( get_post_meta($post->ID, "Thumbnail", true) ): ?>
    				    <img style="float:left;margin:0px 5px 0px 0px;" src="<?php echo get_post_meta($post->ID, "Thumbnail", true); ?>"
                        alt="alt text" />
    				<?php else: ?>
    				    <img style="float:left;margin:0px 5px 0px 0px;"  src="<?php bloginfo('template_url'); ?>/images/thumbnail.jpg" alt
                        ="Default Thumbnail" />
    				<?php endif; ?>
                 </div><!--end post_img-->
    
                 <div class="post_content">
    				<b><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></b>
                    	<div class="stamp"><?php the_time('F jS, Y') ?><!-- by <?php the_author() ?> --> | <?php
    					comments_popup_link(
    					'No
    					Comments »'
    					, '1 Comment »', '% Comments »'); ?></div>
    				<div class="excerpt"><?php if ($post->post_excerpt != "" ) {the_excerpt();}else {the_content_rss('', FALSE, '', 60);}
    				?><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php
    					the_title_attribute(); ?>"> READ MORE</a>
                    </div><!--end excerpt-->   
    
                  </div><!--end post_content-->
    
    				<div style="border-bottom:1px dotted #C0C0C0; margin-bottom:10px; margin-left:14px; margin-right:14px; padding:0px
                    0px 10px 0px; clear:both;"></div>
    
    				<?php endwhile; ?>

    What am I doing wrong?

Viewing 14 replies - 1 through 14 (of 14 total)
  • I think you need to take out the ‘echo’ in <?php echo get_post_meta(....

    If this solves your problem, please mark this topic ‘Resolved’.

    If you update to 2.9, and add a couple of lines to your theme, you can have post images without the need to use custom fields.

    2.9 adds post image support..

    There’s a good post about how to add the support to your theme here.
    https://justintadlock.com/archives/2009/11/16/everything-you-need-to-know-about-wordpress-2-9s-post-image-feature

    However, it looks like Justin’s site is down at the moment, so might need to check later(or use google’s cache).

    Disregard my post about removing the echo – didn’t engage brain before typing.

    If you don’t want to upgrade to 2.9, can you post a link to the site where your code is in use so we can see the output of the script?

    Thread Starter orbital2000

    (@orbital2000)

    t31os & vtxyzzy-

    Thanks for the advice. Upgrading to 2.9 wouldn’t be a problem, since my site is in development. One question about this: I’m using two divs: one for the post image, and one for the content output. With 2.9, can I specify post images to show up in the div I’ve specified for images?

    I’m running the site on my local server with XAMPP, so unfortunately I can’t provide links to my pages.

    Yes you can, you have to add the code into your template anyway, it doesn’t sit as part of the content, this is more a replacement for the custom field approach (or at least it seems that way to me)..

    Did you check out the write up above, on Justin’s site? It’s dead easy …

    Thread Starter orbital2000

    (@orbital2000)

    I just upgraded to 2.9 – so far so good.

    The link provided by t310s is still down. I’m searching for other relevant tutorials, so if anyone has a good one, let me know.

    I’d still like to know how to get my original code working, so I’d love for someone to have a look to see where I went wrong.

    Thanks…

    You can get the key information from the post using google’s cache..
    Click

    And some additional info:
    wpengineer.com/wordpress-2-9-add_theme_support-and-has_post_image/

    Alternative blog post:
    kremalicious.com/2009/12/wordpress-post-thumbnails/

    Thread Starter orbital2000

    (@orbital2000)

    resolved-

    i used the following tutorial: https://markjaquith.wordpress.com/2009/12/23/new-in-wordpress-2-9-post-thumbnail-images/

    1. add coding to functions.php to enable post image functionality
    2. add coding to the loop in your blog file
    3. specify “thumbnail” image at bottom right of new post admin page…there should be a link to “set thumbnail”
    4. make sure to click “as thumbnail” under “Image Size” —DO NOT select “insert in post”!
    5. save changes, update post and you’re done

    This is an awesome feature and literally took me 5 minutes to figure out and initialize the functionality.

    Thread Starter orbital2000

    (@orbital2000)

    For step #3 – I meant to write “use as thumbnail”…typo

    Good stuff mate… ??

    Hopefully this will cut down the amount of repeat custom field image questions.

    I also tagged this post with the single word tags, it should help anyone searching for information.

    Might want to mark the topic ‘Resolved’ so those looking for a solution will see that you found one.

    I don’t keep up on new features as much as I should obviously…this is very cool.

    You guys helped me implement this on my WP site, which is neat, but even cooler….I throw up excerpts of my post on my non-WP homepage, which was neat and all, but this is a really easy way to include images over there!

    Thread Starter orbital2000

    (@orbital2000)

    Sorry folks – RESOLVED

    Please mark the topic ‘Resolved’ in the right column dropdown. Thanks.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Issues displaying post images with custom fields’ is closed to new replies.