【问题标题】:how to display page's attachment image in wordpress custom widget如何在 wordpress 自定义小部件中显示页面的附件图像
【发布时间】:2015-06-10 11:20:39
【问题描述】:

所以我有这个自定义小部件,您可以在其中从下拉框中选择一个页面,该小部件将引导您进入该页面。问题是我不知道如何显示页面的附件图片。

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'];

}

【问题讨论】:

    标签: php wordpress image widget attachment


    【解决方案1】:

    好的,我找到了解决问题的方法

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

    【讨论】:

      猜你喜欢
      • 2019-05-23
      • 2011-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-26
      • 2011-09-04
      相关资源
      最近更新 更多