将图片“ alt”添加到自定义主题

时间:2019-03-23 22:17:51

标签: php wordpress wordpress-theming themes custom-wordpress-pages

我正在尝试获取页面的特色图片,但我的代码似乎无法正常工作。

<?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&amp;fit=crop&amp;w=245&amp;h=245&amp;dpr=1.5 367w" srcset="<?php echo $image = wp_get_attachment_url( get_post_thumbnail_id($post->ID)); ?>
?q=50&amp;fit=crop&amp;w=245&amp;h=245&amp;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&amp;fit=crop&amp;w=245&amp;h=245 245w" srcset="<?php echo $image = wp_get_attachment_url( get_post_thumbnail_id($post->ID)); ?>
?q=50&amp;fit=crop&amp;w=245&amp;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&amp;fit=crop&amp;w=295&amp;h=295&amp;dpr=1.5 442w" srcset="<?php echo $image = wp_get_attachment_url( get_post_thumbnail_id($post->ID)); ?>
?q=50&amp;fit=crop&amp;w=295&amp;h=295&amp;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&amp;fit=crop&amp;w=295&amp;h=295 295w" srcset="<?php echo $image = wp_get_attachment_url( get_post_thumbnail_id($post->ID)); ?>
?q=50&amp;fit=crop&amp;w=295&amp;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&amp;fit=crop&amp;w=180&amp;h=180&amp;dpr=1.5 270w" srcset="<?php echo $image = wp_get_attachment_url( get_post_thumbnail_id($post->ID)); ?>
?q=50&amp;fit=crop&amp;w=180&amp;h=180&amp;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&amp;fit=crop&amp;w=180&amp;h=180 180w" srcset="<?php echo $image = wp_get_attachment_url( get_post_thumbnail_id($post->ID)); ?>
?q=50&amp;fit=crop&amp;w=180&amp;h=180 180w">
<!--[if IE 9]></video><![endif]-->
            <img class=" lazyloaded">
        </picture>
    </div>
</div>

0 个答案:

没有答案