DUX主题不显示首页缩略图的解决办法

首页不显示缩略图的问题,只存在与1.8版本。

DUX1.9已经修复了此功能,以下解决办法可以使用在1.8版本中。

解决办法

一、修改主题根目录的functions-theme.php文件

二、Ctrl+F查找:function _get_post_thumbnail($size = \'thumbnail\', $class = \'thumb\') {

在589行开始,639行结束;

function _get_post_thumbnail($size = \'thumbnail\', $class = \'thumb\') {
    global $post;
    $html = \'\';
    if (has_post_thumbnail()) {
        /*$domsxe = simplexml_load_string(get_the_post_thumbnail());
        $src = $domsxe->attributes()->src;
 
        $src_array = wp_get_attachment_image_src(_get_attachment_id_from_src($src), $size);
        $html = sprintf(\'<img class=\"%s\" data-src=\"%s\" />\', $src_array[0], $class);*/
        $domsxe = get_the_post_thumbnail();
        // print_r($domsxe);
        preg_match_all(\'/&lt;img.*?(?: |\\\\t|\\\\r|\\\\n)?src=[\\\'\"]?(.+?)[\\\'\"]?(?:(?: |\\\\t|\\\\r|\\\\n)+.*?)?&gt;/sim\', $domsxe, $strResult, PREG_PATTERN_ORDER);
        $images = $strResult[1];
        foreach($images as $src){
            $html = sprintf(\'<img class=\"thumb\" data-src=\"%s\" />\', $src);
            break;
        }
    }else {
        $post_thumbnail_src = \'\';
        ob_start();
    ob_end_clean();
    $output = preg_match_all(\'/&lt;img.+src=[\\\'\"]([^\\\'\"]+)[\\\'\"].*&gt;/i\', $post-&gt;post_content, $matches);
    $post_thumbnail_src = $matches [1] [0];   //获取该图片 src
    if(empty($post_thumbnail_src)){
        $random = mt_rand(1, 10);
        $post_thumbnail_src = get_bloginfo(\'template_url\').\'https://img.huliku.com/pic/pic/\'.$random.\'.jpg\';
        }
        $html = sprintf(\'<img class=\"thumb\" data-src=\"%s\" />\', $post_thumbnail_src);
    }
    return $html;
}

三、把以上代码修改以下代码;

function _get_post_thumbnail($size = \'thumbnail\', $class = \'thumb\') {
    global $post;
    $html = \'\';
    if (has_post_thumbnail()) {
        /*$domsxe = simplexml_load_string(get_the_post_thumbnail());
        $src = $domsxe-&gt;attributes()-&gt;src;
        $src_array = wp_get_attachment_image_src(_get_attachment_id_from_src($src), $size);
        $html = sprintf(\'<img class=\"%s\" data-src=\"%s\" />\', $src_array[0], $class);*/
        $domsxe = get_the_post_thumbnail();
        // print_r($domsxe);
        preg_match_all(\'/&lt;img.*?(?: |\\\\t|\\\\r|\\\\n)?src=[\\\'\"]?(.+?)[\\\'\"]?(?:(?: |\\\\t|\\\\r|\\\\n)+.*?)?&gt;/sim\', $domsxe, $strResult, PREG_PATTERN_ORDER);
        $images = $strResult[1];
        foreach($images as $src){
            $html = sprintf(\'<img class=\"thumb\" data-src=\"%s\" />\', $src);
            break;
        }
    }else {
        $post_thumbnail_src = \'\';
        ob_start();
    ob_end_clean();
    $output = preg_match_all(\'/&lt;img.+src=[\\\'\"]([^\\\'\"]+)[\\\'\"].*&gt;/i\', $post-&gt;post_content, $matches);
    $post_thumbnail_src = $matches [1] [0];   //获取该图片 src
    if(empty($post_thumbnail_src)){
        $random = mt_rand(1, 10);
        $post_thumbnail_src = get_bloginfo(\'template_url\').\'https://img.huliku.com/pic/pic/\'.$random.\'.jpg\';
        }
        $html = sprintf(\'<img class=\"thumb\" data-src=\"%s\" />\', $post_thumbnail_src);
    }
    return $html;
}

修改后保存更新缓存即可解决

温馨提示: 本文最后更新于2022/10/20 04:46:32若文章内容或图片失效,请留言联系站长反馈!
!
也想出现在这里? 联系我们
创意广告
© 版权声明
THE END
点赞0赞赏 分享
评论 抢沙发

请登录后发表评论

    请登录后查看评论内容