如何在wordpress自定义小部件中显示页面的附件图像
how to display page's attachment image in wordpress custom widget
所以我有这个自定义小部件,您可以在其中 select 来自下拉框的页面,小部件会将您带到该页面。问题是我不知道如何显示页面的附件图像。
wp_get_attachment_image($page, 'full'
) 不起作用。在 codex 中有一个带有循环的示例,但在这里我只需要那个图像。
// 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'];
}
好的,我找到了问题的解决方案
echo get_the_post_thumbnail($page,array(540,260));
所以我有这个自定义小部件,您可以在其中 select 来自下拉框的页面,小部件会将您带到该页面。问题是我不知道如何显示页面的附件图像。
wp_get_attachment_image($page, 'full'
) 不起作用。在 codex 中有一个带有循环的示例,但在这里我只需要那个图像。
// 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'];
}
好的,我找到了问题的解决方案
echo get_the_post_thumbnail($page,array(540,260));