fix: 深度修复懒加载问题
- 移除 argon_lazyload 函数中的 !is_home() 限制,允许首页也使用懒加载 - 新增 argon_get_post_thumbnail_html 辅助函数,统一处理缩略图懒加载 - 更新所有文章预览模板(content-preview-1/2/3.php)使用新的懒加载函数 - 确保缩略图也能正确应用懒加载和加载动画 - 修复首页文章列表图片不显示的问题
This commit is contained in:
@@ -1105,6 +1105,33 @@ function argon_get_post_thumbnail($postID = 0){
|
|||||||
}
|
}
|
||||||
return apply_filters("argon_post_thumbnail", argon_get_first_image_of_article());
|
return apply_filters("argon_post_thumbnail", argon_get_first_image_of_article());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成带懒加载的缩略图 HTML
|
||||||
|
* @param int $postID 文章 ID
|
||||||
|
* @param string $class 额外的 CSS 类
|
||||||
|
* @param string $alt 图片 alt 属性
|
||||||
|
* @return string 图片 HTML 标签
|
||||||
|
*/
|
||||||
|
function argon_get_post_thumbnail_html($postID = 0, $class = 'post-thumbnail', $alt = 'thumbnail'){
|
||||||
|
$thumbnail_url = argon_get_post_thumbnail($postID);
|
||||||
|
if (!$thumbnail_url) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查是否启用懒加载
|
||||||
|
if (get_option('argon_enable_lazyload', 'true') == 'false') {
|
||||||
|
// 未启用懒加载,直接输出图片
|
||||||
|
return "<img class='" . esc_attr($class) . "' src='" . esc_url($thumbnail_url) . "' alt='" . esc_attr($alt) . "' loading='lazy'>";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 启用懒加载
|
||||||
|
$loading_style = get_option('argon_lazyload_loading_style', '1');
|
||||||
|
$style_class = ($loading_style !== 'none') ? ' lazyload-style-' . $loading_style : '';
|
||||||
|
$placeholder = 'data:image/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPg==';
|
||||||
|
|
||||||
|
return "<img class='" . esc_attr($class) . " lazyload" . $style_class . "' src='" . $placeholder . "' data-src='" . esc_url($thumbnail_url) . "' alt='" . esc_attr($alt) . "' loading='lazy'>";
|
||||||
|
}
|
||||||
//文末附加内容
|
//文末附加内容
|
||||||
function get_additional_content_after_post(){
|
function get_additional_content_after_post(){
|
||||||
global $post;
|
global $post;
|
||||||
@@ -3229,7 +3256,8 @@ function get_banner_background_url(){
|
|||||||
}
|
}
|
||||||
//懒加载:对 <img> 标签添加懒加载支持
|
//懒加载:对 <img> 标签添加懒加载支持
|
||||||
function argon_lazyload($content){
|
function argon_lazyload($content){
|
||||||
if (!is_feed() && !is_robots() && !is_home()) {
|
// 移除 !is_home() 限制,允许在首页也使用懒加载
|
||||||
|
if (!is_feed() && !is_robots()) {
|
||||||
$loading_style = get_option('argon_lazyload_loading_style', '1');
|
$loading_style = get_option('argon_lazyload_loading_style', '1');
|
||||||
// 占位图 base64(用于触发 CSS 加载动画)
|
// 占位图 base64(用于触发 CSS 加载动画)
|
||||||
$placeholder = 'data:image/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPg==';
|
$placeholder = 'data:image/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPg==';
|
||||||
|
|||||||
@@ -6,9 +6,7 @@
|
|||||||
|
|
||||||
if (argon_has_post_thumbnail()){
|
if (argon_has_post_thumbnail()){
|
||||||
|
|
||||||
$thumbnail_url = argon_get_post_thumbnail();
|
echo argon_get_post_thumbnail_html(0, 'post-thumbnail', 'thumbnail');
|
||||||
|
|
||||||
echo "<img class='post-thumbnail' src='" . $thumbnail_url . "' alt='thumbnail' loading='lazy'>";
|
|
||||||
|
|
||||||
echo "<div class='post-header-text-container'>";
|
echo "<div class='post-header-text-container'>";
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,7 @@
|
|||||||
|
|
||||||
if (argon_has_post_thumbnail()){
|
if (argon_has_post_thumbnail()){
|
||||||
|
|
||||||
$thumbnail_url = argon_get_post_thumbnail();
|
echo argon_get_post_thumbnail_html(0, 'post-thumbnail', 'thumbnail');
|
||||||
|
|
||||||
echo "<img class='post-thumbnail' src='" . $thumbnail_url . "' alt='thumbnail' loading='lazy'>";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,7 @@
|
|||||||
|
|
||||||
echo "<header class='post-header post-header-with-thumbnail'>";
|
echo "<header class='post-header post-header-with-thumbnail'>";
|
||||||
|
|
||||||
$thumbnail_url = argon_get_post_thumbnail();
|
echo argon_get_post_thumbnail_html(0, 'post-thumbnail', 'thumbnail');
|
||||||
|
|
||||||
echo "<img class='post-thumbnail' src='" . $thumbnail_url . "' alt='thumbnail' loading='lazy'>";
|
|
||||||
|
|
||||||
echo "</header>";
|
echo "</header>";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user