dsqdpn31467 2013-02-23 21:15
浏览 56

Wordpress更改后缩略图属性

I'm trying to change the post thumbnail's attributes to support Lazy Load. This requires me to add a class of lazy, change the source to a placeholder image, and place the image source to into a data-original attribute.

I've done research and have referenced the documentation, but am still running into issues.

Here's the code I'm trying to use:

<?php
    $tempimg = get_bloginfo('template_url') . "/img/grey.gif";
    $default_attr = array(
        'src' => $tempimg,
        'data-original' => $src,
        'class' => "lazy attachment-$size",
    );
    the_post_thumbnail('project-thumbnail', $default_attr);
?>

You'd think it would work, but once I use those attributes, the $src and $size variables don't work. They're just blank. Is there something I am missing?

Thanks in advanced.

  • 写回答

2条回答 默认 最新

  • dongpi9480 2013-02-23 23:40
    关注

    Is there something I am missing?

    Yes. You haven't set either $src or $size in that block of code. They are blank because the variables are not set. They are, in fact, blank-- arguably less than blank. If you were to set those two values-- something like this--

    $size = 123;
    $tempimg = $src = get_bloginfo('template_url') . "/img/grey.gif";
    $default_attr = array(
        'src' => $tempimg,
        'data-original' => $src,
        'class' => "lazy attachment-$size",
    );
    the_post_thumbnail('project-thumbnail', $default_attr);
    

    ... it works just fine.

    评论

报告相同问题?