【问题标题】:Wordpress Post Thumbnail IssueWordpress 帖子缩略图问题
【发布时间】:2015-07-19 14:31:20
【问题描述】:

我可以看到,在我的上传文件夹中,我上传到帖子中的所有图片都有 4 种不同的尺寸。

我没有为帖子设置特色图片,但我想将缩略图大小显示在我的首页上。

我试过把 the_post_thumbnail();在循环中,但没有显示任何内容。

我错过了什么吗?是否有其他方法可以获取已放入帖子中的图像的缩略图大小?

目前我使用捕获图像功能来抓取帖子中的第一张图片并使用此代码将其显示在首页上,是否可以对其进行编辑以获取该缩略图?

function catch_that_image() {
    global $post, $posts;
    $first_img = '';
    ob_start();
    ob_end_clean();
    $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
    $first_img = $matches [1] [0];
    //$first_img = substr($first_img, 0, -4);  

    if(empty($first_img)){ //Defines a default image
    $first_img = bloginfo('template_directory');
    $first_img .= "/images/default.png";
    }
     return $first_img;
}

谢谢

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    the_post_thumbnail 显示帖子中的特色图片,因此如果您没有设置任何内容,它不会显示任何内容。

    【讨论】:

      猜你喜欢
      • 2011-09-04
      • 2011-03-15
      • 1970-01-01
      • 2012-09-15
      • 1970-01-01
      • 2013-07-17
      • 1970-01-01
      • 2017-08-02
      • 2014-04-15
      相关资源
      最近更新 更多