• Resolved sincewelastspoke

    (@sincewelastspoke)


    Hi,

    When making a post in my news category, I do the Upload part and insert an image into the editor. It uploads and displays great in my news page.

    I then display my most recent Post Title and an excerpt of the body text in my home page. Is there also a way to display the ONE image that I uploaded in there?

    Thanks for any help ??

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter sincewelastspoke

    (@sincewelastspoke)

    Hate to *bump* but, any ideas?

    To achieve a similar effect, I added the image’s thumbnail URL to the post’s Custom Fields. Then, when displaying excerpts, I set the template to display the image from the Custom Field too.

    This method has the added advantage that if a post has more than one image, I can control which image is displayed with the excerpt.

    Thread Starter sincewelastspoke

    (@sincewelastspoke)

    Many thanks for the speedy reply.

    I’ve added to the custom field with key thumbnail and html: <img src="images/test-pic.jpg" alt="" />

    In my home page I have:

    <?php query_posts('showposts=1&cat=5'); ?><?php while (have_posts()) : the_post(); ?><div><span><?php the_time('j'); ?></span><span><?php the_time('M'); ?></span></div>
    				<p><php the_title('<span style="font-weight:bold">', '</span>'); ?><?php the_content_rss('', TRUE, '', 14); ?><?php endwhile;?>

    If I want to show my pic in the custom field, in there, how do I do it, how can I use the excerpt like you say?
    Sorry to be so slow.

    Many thanks for your patience and help with this.

    You should find all the information you need at https://codex.www.ads-software.com/Using_Custom_Fields

    Try inserting this code where you want the image to appear.

    <?php
    $supporting_image=get_post_meta( $post->ID, 'thumbnail', true );
    if (''!=$supporting_image)
    {
      echo $supporting_image;
    }
    ?>
    Thread Starter sincewelastspoke

    (@sincewelastspoke)

    Many thanks for the quick reply.

    And this should be [strong]within the while loop[/strong]?

    Thank you.

    Yes, it should.

    Thread Starter sincewelastspoke

    (@sincewelastspoke)

    Thread Starter sincewelastspoke

    (@sincewelastspoke)

    OK, tried the following but with no success:

    <?php query_posts('showposts=1&cat=5'); ?><?php while (have_posts()) : the_post(); ?><?php
    $supporting_image=get_post_meta( $post->ID, 'thumbnail', true );
    if (''!=$supporting_image)
    {
      echo $supporting_image;
    }
    ?><div style="float:left;width:48px;height:45px;background:url('images/calendar.jpg') right no-repeat;padding-top:8px;padding-left:8px"><span style="padding-left:16px;padding-top:18px;font-size:18px;color:#fff;text-align:center"><?php the_time('j'); ?></span><br /><span style="padding-left:11px;padding-top:4px;font-size:10px;color:#fff"><?php the_time('M'); ?></span></div>
    				<p style="padding-left:60px"><?php the_title('<span style="font-weight:bold">', '</span>'); ?><br /><?php the_content_rss('', TRUE, '', 14); ?><?php endwhile;?>

    It displays everything ok, but the picture ??

    Have I done something wrong?

    The key is definitely called ‘thumbnail’.

    Thread Starter sincewelastspoke

    (@sincewelastspoke)

    Thread Starter sincewelastspoke

    (@sincewelastspoke)

    BRILLIANT!!!

    Many, many thanks.

    I’ve unlocked the power of the Custom Field, and it feels great ??

    Thanks again ??

    You’re welcome.

    What was the problem with the code? And, can you mark this thread “resolved” if you’re happy? ??

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Use image in Post on Home Page?’ is closed to new replies.