Forums

Pulling single post content with image into front page (4 posts)

  1. stoz
    Member
    Posted 1 year ago #

    Hi,

    I'm working on a site for a charity my friend is raising money for. He has a list of donors (added to the site using portfolio items) and what we wanted to do is have a box on the front page that would feature a donor based on a query string that has been added to the url. I've had a lot of success so far implementing this feature, except I can't seem to get the image attachment to pull through to the front page. Here's what I have so far:

    <?php
    $page_id = $_GET['id'];
    $page_data = get_page( $page_id );
    $title = $page_data->post_title;
    echo "<h3>" . $title . "</h3>";
    echo apply_filters('the_content' , $page_data->post_content);
    ?>

    So the attached image was added to the post using the featured image, and I was wondering if there was a way that I could pull that into the front page with the rest of the data.

    Thanks a ton for any help you can give me.
    Steven.

  2. Jarret Cade
    Member
    Posted 1 year ago #

    Have you looked into using wp_get_attachment_image? http://codex.wordpress.org/Function_Reference/wp_get_attachment_image

  3. stoz
    Member
    Posted 1 year ago #

    Thanks for the reply. I have tried wp_get_attachment_image, and ..image_src, and both didn't seem to return anything. I just added to the block like:

    <?php
    $page_id = $_GET['id'];
    $page_data = get_page( $page_id );
    $title = $page_data->post_title;
    echo wp_get_attachment_image_src( 1 );
    echo "<h3>" . $title . "</h3>";
    echo apply_filters('the_content' , $page_data->post_content);
    ?>

    But maybe that was the wrong syntax? Sorry, I'm still just getting into php on a case by case basis, so I'm not super great at it.

    Thanks!

  4. stoz
    Member
    Posted 1 year ago #

    Alright, I think I cracked the code, this seems to work, hopefully it can help someone else out if they are having the same problem:

    <?php
    $page_id = $_GET['id'];
    $page_data = get_page( $page_id );
    $title = $page_data->post_title;
    echo "<h3>" . $title . "</h3>";
    echo apply_filters('the_content' , $page_data->post_content);
    
    $image = wp_get_attachment_image_src( get_post_thumbnail_id( $page_data->ID ), 'index-post-thumbnail-large' );
    echo "<img src=" . $image[0] . ">";
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic