使用说明
- 安装模板:
- 将
template-gallery.php
上传到子比主题的模板目录 (通常是/wp-content/themes/zibll/
) - 将 functions.php 中的代码添加到子比主题的 functions.php 文件末尾
- 将
- 创建页面:
- 在WordPress后台创建新页面
- 选择"子比图片库"作为页面模板
- 发布页面
- 配置设置:
- 在媒体 → 图片库设置中配置:
- 图片显示尺寸
- 每行显示数量(1-6)
- 图片间距
- 选择要显示的分类
- 在媒体 → 图片库设置中配置:
- 样式调整:
- 将CSS代码添加到子比主题的自定义CSS设置中
- 可根据需要调整颜色、间距等样式变量
这个解决方案完全适配子比主题,具有以下特点:
- 完善的分类筛选系统
- 响应式网格布局
- 图片懒加载
- 平滑的悬停动画效果
- 与子比主题风格完美融合
- 完整的后台配置界面
在wordpress使用中,项目常因迭代积累大量未使用的图片资源,这些冗余资源会导致:
- 空间体积膨胀(影响网站打开速度)
- 前端加载时间增加
- 资源管理混乱(增加维护成本)
传统手动清理方式效率低下,且易遗漏。本工具通过自动化扫描与清理机制,解决以下核心痛点:
-
-
- 识别图片与代码/布局文件的关联性
- 处理动态加载等特殊引用场景
- 提供安全删除策略
-
template-gallery.php:
functions.php:
CSS代码:
/* 基础样式 */
.gallery-filter-menu {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin-bottom: 30px;
padding-bottom: 15px;
border-bottom: 1px solid #eee;
}
/* 图片网格布局 - 保持不变 */
.gallery-grid {
display: grid;
grid-template-columns: repeat(var(--per-row), 1fr);
gap: var(--spacing);
margin-bottom: 30px;
}
/* 图片项样式 - 修改部分 */
.gallery-item {
position: relative;
overflow: hidden;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
border: 1px solid #e0e0e0;
background-color: #000; /* 黑色背景 */
aspect-ratio: 4/3; /* 保持4:3比例 */
transition: transform 0.3s ease, box-shadow 0.3s ease;
transform: translateY(0);
}
.gallery-image-container {
position: relative;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.gallery-image-container img {
max-width: 100%;
max-height: 100%;
width: auto;
height: auto;
object-fit: contain; /* 原始比例显示 */
}
/* 其他样式保持不变 */
.gallery-title {
padding: 12px;
font-size: 14px;
line-height: 1.4;
color: #fff !important;
background: rgba(0, 0, 0, 0.7); /* 半透明黑色背景 */
text-align: center;
position: absolute;
bottom: 0;
left: 0;
right: 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.gallery-title .DearLicy_prefix.jb-red {
font-weight: bold;
margin-right: 5px;
}
.gallery-item:hover {
transform: translateY(-8px);
box-shadow: 0 12px 20px rgba(0, 0, 0, 0.15);
}
/* 鼠标经过时的标题样式 */
.gallery-item:hover .gallery-title {
background: rgba(0, 115, 170, 0.9); /* 悬停时变成主题蓝色 */
color: #fff !important;
text-shadow: 0 0 3px rgba(0,0,0,0.5); /* 添加文字阴影增强可读性 */
}
/* 筛选菜单容器 */
.gallery-filter-menu {
display: flex;
flex-wrap: wrap;
gap: 18px;
margin: 0 0 30px;
padding: 15px 20px;
background: linear-gradient(145deg, #f8f9fa, #ffffff);
border-radius: 12px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
border: 1px solid rgba(0, 0, 0, 0.05);
}
/* 筛选菜单项基础样式 */
.gallery-filter-menu a {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 10px 20px;
background-color: #f1f3f5;
color: #495057;
text-decoration: none;
border-radius: 30px;
font-size: 14px;
font-weight: 500;
transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
border: 1px solid transparent;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
position: relative;
overflow: hidden;
}
/* 悬停效果 */
.gallery-filter-menu a:hover {
background-color: #e9ecef;
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
color: #212529;
}
/* 激活状态 */
.gallery-filter-menu a.active {
background: linear-gradient(135deg, #4361ee, #3a0ca3);
color: white !important;
font-weight: 600;
box-shadow: 0 4px 14px rgba(67, 97, 238, 0.3);
border-color: rgba(255, 255, 255, 0.2);
}
/* 激活状态悬停 */
.gallery-filter-menu a.active:hover {
background: linear-gradient(135deg, #3a56e0, #2e0b8c);
transform: translateY(-2px);
}
/* 所有图片按钮特殊样式 */
.gallery-filter-menu a:first-child {
background-color: #e9ecef;
font-weight: 600;
border: 1px solid #dee2e6;
}
/* 小屏适配 */
.responsive-grid {
display: grid;
grid-template-columns: repeat(var(--per-row), 1fr);
gap: var(--spacing);
}
@media (max-width: 768px) {
.responsive-grid {
grid-template-columns: repeat(2, 1fr);
}
.gallery-filter-menu {
padding: 12px 15px;
gap: 6px;
}
.gallery-filter-menu a {
padding: 8px 16px;
font-size: 13px;
}
}
/* 微交互效果 */
.gallery-filter-menu a::after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(255, 255, 255, 0.2);
transform: translateY(100%);
transition: transform 0.3s ease;
}
.gallery-filter-menu a:hover::after {
transform: translateY(0);
}
/* 当前选中项标记 */
.gallery-filter-menu a.active::before {
content: '';
position: absolute;
bottom: -5px;
left: 50%;
transform: translateX(-50%);
width: 20px;
height: 3px;
background: white;
border-radius: 3px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
© 版权声明
1 本站文章均为原创,除非另有说明,转载请附上出处链接,谢谢。
2 本站提供的资源(插件或主题)均为网上搜集,如有涉及或侵害到您的版权请立即通知我们。
3 本站所有下载文件,仅用作学习研究使用,请下载后24小时内删除,支持正版,勿用作商业用途。
4 因代码可变性,不保证兼容所有浏览器、不保证兼容所有版本的系统、不保证兼容您安装的其他插件。
5 本站保证所提供资源(插件或主题)的完整性,但不含授权许可、帮助文档、XML文件、PSD、后续升级等。
6 使用该资源(插件或主题)需要用户有一定代码基础知识!由本站提供的资源对您的网站或计算机造成严重后果的本站概不负责。
7 因不同CMS系统不定期升级,导致有时可能会遇到部分源码不兼容,介意勿使用,谢谢!
8 本站资源售价只是赞助和汉化辛苦费,收取费用仅维持本站的日常运营所需。
9 如果喜欢本站资源,欢迎捐助本站开通会员享受优惠折扣,谢谢支持!
10 如果资源地址失效,请在相应资源页面下留言,我们会尽快修复下载地址。
THE END
暂无评论内容