Dux 1.3主题添加Featured Image From URL插件后修复首页缩略图显示位置错误的bug修复,
为什么没有缩略图? 你需要编辑文章的时候添加特色图片,这样才会显示在列表的缩略图中;
也就是说不设置特色图片,首页就显示默认的图片。这在主题说明里面已经详细说明啦,亲们,你们不要纠结了,dux主题如何设置如何实现Dux主题文章不设置特色图片或者文章使用外链图片时显示随机缩略图?
用记事本打开 functions.php文件,重新定义_get_post_thumbnail函数,修改如下
<?php
// Require theme functions
require get_stylesheet_directory() . ‘/inc/fn.php’;// Customize your functions
function _get_post_thumbnail($size = ‘thumbnail’, $class = ‘thumb’) {
$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 data-src=”%s” class=”%s”/>’, $src_array[0], $class);*/
$domsxe = get_the_post_thumbnail();
// print_r(“1.2 domsxe = $domsxe <br>”);
if(preg_match_all(‘/<img.*?(?: |\\t|\\r|\\n)?src=[\'”]?(.+?)[\'”]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim’, $domsxe, $strResult, PREG_PATTERN_ORDER)){
$images = $strResult[1];
foreach($images as $src){
// echo “1.2 $src <br>”;
$html = sprintf(‘<img data-src=”%s” class=”thumb”>’, $src);
break;
}
}
else
{
$html = sprintf(‘<img data-src=”%s” class=”thumb”>’, $domsxe);
}} else {
$random = mt_rand(1,10);
$html = sprintf(‘<img data-src=”%s” class=”%s”>’, ‘http://xxxxx.baidu.com/xxxee2%2FFeatured-image%2Frandom%2F’.$random.’.jpg’, $class);
}return $html;
}
return $html;
}
打开 fn.php 文件,屏蔽掉掉DUX 1.3原来的_get_post_thumbnail函数,否则会有函数重定义的错误提示。
/*function _get_post_thumbnail($size = ‘thumbnail’, $class = ‘thumb’) {
$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 data-src=”%s” class=”%s”/>’, $src_array[0], $class);*/$domsxe = get_the_post_thumbnail();
// print_r($domsxe);
preg_match_all(‘/<img.*?(?: |\\t|\\r|\\n)?src=[\'”]?(.+?)[\'”]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim’, $domsxe, $strResult, PREG_PATTERN_ORDER);
$images = $strResult[1];
foreach($images as $src){
$html = sprintf(‘<img data-src=”%s” class=”thumb”>’, $src);
break;
}} else {
$html = sprintf(‘<img data-src=”%s” class=”%s”>’, get_stylesheet_directory_uri() . ‘/img/thumbnail.png’, $class);
}return $html;
}*/
function fifu_replace($html, $post_id) {
$image_url = get_post_meta($post_id, ‘fifu_image_url’, true);if ($image_url) {
// echo “2.1image_url = $image_url <br>”;
//支持DUX.1.3的特征图像预览 20151215 —
if(preg_match_all(‘/<img.*?(?: |\\t|\\r|\\n)?src=[\'”]?(.+?)[\'”]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim’, $html, $strResult, PREG_PATTERN_ORDER)){
//匹配到
$images = $strResult[1];
foreach($images as $src){
$html = str_replace($src,$image_url,$html);
break;
}
}
else{
//没有匹配到
$html = $image_url;
}
/*
$html = fifu_get_html($post_id, $image_url);
if (get_option(‘fifu_backlink’) == ‘toggleon’)
include ‘html/backlink.html’;
*/}
return $html;
}
未经允许,不得转载本站任何文章:诺机械CAD软件 » Dux 1.3主题添加 Featured Image From URL插件后修复文章缩略图显示位置错误的bug