我正在尝试获取页面的特色图片,但我的代码似乎无法正常工作。
<?php echo $image = wp_get_attachment_url( get_post_thumbnail_id($post->ID)); ?>
这是完整的代码。
<div style="margin:0 auto;max-width:660px;">
<div class="responsive-img img-networth-category">
<picture>
<!--[if IE 9]><video style="display: none;"><![endif]-->
<source media="(min-width: 768px) and (-webkit-min-device-pixel-ratio: 1.25), (min-width: 768px) and (min-resolution: 120dpi)" sizes="245px" data-srcset="<?php echo $image = wp_get_attachment_url( get_post_thumbnail_id($post->ID)); ?>
?q=50&fit=crop&w=245&h=245&dpr=1.5 367w" srcset="<?php echo $image = wp_get_attachment_url( get_post_thumbnail_id($post->ID)); ?>
?q=50&fit=crop&w=245&h=245&dpr=1.5 367w">
<source media="(min-width: 768px)" sizes="245px" data-srcset="<?php echo $image = wp_get_attachment_url( get_post_thumbnail_id($post->ID)); ?>
?q=50&fit=crop&w=245&h=245 245w" srcset="<?php echo $image = wp_get_attachment_url( get_post_thumbnail_id($post->ID)); ?>
?q=50&fit=crop&w=245&h=245 245w">
<source media="(min-width: 481px) and (-webkit-min-device-pixel-ratio: 1.25), (min-width: 481px) and (min-resolution: 120dpi)" sizes="295px" data-srcset="<?php echo $image = wp_get_attachment_url( get_post_thumbnail_id($post->ID)); ?>
?q=50&fit=crop&w=295&h=295&dpr=1.5 442w" srcset="<?php echo $image = wp_get_attachment_url( get_post_thumbnail_id($post->ID)); ?>
?q=50&fit=crop&w=295&h=295&dpr=1.5 442w">
<source media="(min-width: 481px)" sizes="295px" data-srcset="<?php echo $image = wp_get_attachment_url( get_post_thumbnail_id($post->ID)); ?>
?q=50&fit=crop&w=295&h=295 295w" srcset="<?php echo $image = wp_get_attachment_url( get_post_thumbnail_id($post->ID)); ?>
?q=50&fit=crop&w=295&h=295 295w">
<source media="(min-width: 0px) and (-webkit-min-device-pixel-ratio: 1.25), (min-width: 0px) and (min-resolution: 120dpi)" sizes="180px" data-srcset="<?php echo $image = wp_get_attachment_url( get_post_thumbnail_id($post->ID)); ?>
?q=50&fit=crop&w=180&h=180&dpr=1.5 270w" srcset="<?php echo $image = wp_get_attachment_url( get_post_thumbnail_id($post->ID)); ?>
?q=50&fit=crop&w=180&h=180&dpr=1.5 270w">
<source media="(min-width: 0px)" sizes="180px" data-srcset="<?php echo $image = wp_get_attachment_url( get_post_thumbnail_id($post->ID)); ?>
?q=50&fit=crop&w=180&h=180 180w" srcset="<?php echo $image = wp_get_attachment_url( get_post_thumbnail_id($post->ID)); ?>
?q=50&fit=crop&w=180&h=180 180w">
<!--[if IE 9]></video><![endif]-->
<img class=" lazyloaded">
</picture>
</div>
</div>