• Resolved kimmi_baby

    (@kimmi_baby)


    Hi,

    I have the following code displaying the content of a page:

    <?php
    $post_id = 50;
    $my_post = get_post($post_id);
    echo "$my_post->post_content";
     ?>

    I would now like to display the thumbnail of that page. How do I do this?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter kimmi_baby

    (@kimmi_baby)

    great! thank you ??

    I now have this

    <?php
    $post_id = 181;
    $my_post = get_post($post_id);
    echo "$my_post->post_title";
    echo "$my_post->post_content";
     echo get_the_post_thumbnail($my_post->ID);
      ?>

    What if i want to place the content in a div and the image in a div? I seem to get an error if I put a div around the code

    your echo was wrong revome the “” it should be like this
    echo $my_post->post_content;

    in inserting a div around the code these are the ways.

    1. separate the html code in php code by putting end tag in php code.
    <?php code here ?> <div> </div> <?php code here ?>

    2. add a html code inside echo
    echo ‘<div></div>’.$my_post->post_content;

    Thread Starter kimmi_baby

    (@kimmi_baby)

    I’m noticing that it isn’t reading my paragraph tags when it brings in the page content.

    Also this is the code now,

    <?php
    $post_id = 181;
    $my_post = get_post($post_id);
    echo $my_post->post_title;
    echo $my_post->post_content;
     echo '<div class="leftimage"></div>'. get_the_post_thumbnail($my_post->ID);
      ?>

    It’s not working because I haven’t been able to wrap the div around the content… Is there another way?

    I need it to work along the lines of
    echo <div class=”leftimage”>get_the_post_thumbnail($my_post->ID);</div>

    Thread Starter kimmi_baby

    (@kimmi_baby)

    got it to work! thank you

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to display the thumbnail of a post’ is closed to new replies.