所以我有这个自定义小部件,您可以从下拉框中选择一个页面,小部件将引导您进入此页面。问题是我不知道如何显示页面的附件图像。
wp_get_attachment_image($page, 'full'
)不起作用。在手抄本中有一个循环的例子,但在这里我只需要一个图像。
// 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'];
}
答案 0 :(得分:0)
好的,我找到了解决问题的方法
echo get_the_post_thumbnail($page,array(540,260));