how to display page's attachment image in wordpress custom widget

137 views Asked by At

So I have this custom widget where you can select a page from a drop box and the widget will lead you to this page. The problem is i have no idea how to display the page's attachment image.

wp_get_attachment_image($page, 'full') doesn't work. In the codex there's an example with a loop, but here I need just that one image.

// This is where you run the code and display the output
$page = $instance['selected']; ?>                   
<a href="<?= get_the_permalink($page); ?>">
<?php wp_get_attachment_image( $page, 'full' ); ?>

    <article>
        <h2><?php echo $title; ?></h2>
        <h3><?php echo $instance['content'];  ?></h3>
    </article>
    <div class="readmore">Read more</div>
</a>

<?php
echo $args['after_widget'];

}

1

There are 1 answers

0
Filip Marzec On BEST ANSWER

Okay, I found the solution to my problem

echo get_the_post_thumbnail($page,array(540,260));