From 6a461052f981656378e7eb2bdba9b7c86f94d3c6 Mon Sep 17 00:00:00 2001 From: huyuanxiang <273637057@qq.com> Date: Fri, 27 Feb 2026 11:19:13 +0800 Subject: [PATCH] =?UTF-8?q?[add]=E6=B7=BB=E5=8A=A0=E4=BB=8E=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E8=8E=B7=E5=8F=96=E4=BA=A7=E5=93=81=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../SHORTCODE_DOCUMENTATION.md | 611 ++++++++++++ .../nenghui-energy-theme-4/functions.php | 135 +++ .../nenghui-energy-theme-4/inc/shortcode.php | 28 +- .../inc/theme-setup.php | 473 ++++++---- .../themes/nenghui-energy-theme-4/style.css | 3 +- .../blocks/block-products-list.php | 889 ++++++++++++++++++ 7 files changed, 1951 insertions(+), 189 deletions(-) create mode 100644 wp-content/themes/nenghui-energy-theme-4/SHORTCODE_DOCUMENTATION.md create mode 100644 wp-content/themes/nenghui-energy-theme-4/template-parts/blocks/block-products-list.php diff --git a/.gitignore b/.gitignore index d56272d..e52f08f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ bin-release/ [Bb]in/ wp-admin/ wp-includes/ +html-temp/ wp-content/languages/ wp-content/mu-plugins/ wp-content/plugins/ diff --git a/wp-content/themes/nenghui-energy-theme-4/SHORTCODE_DOCUMENTATION.md b/wp-content/themes/nenghui-energy-theme-4/SHORTCODE_DOCUMENTATION.md new file mode 100644 index 0000000..f01b846 --- /dev/null +++ b/wp-content/themes/nenghui-energy-theme-4/SHORTCODE_DOCUMENTATION.md @@ -0,0 +1,611 @@ +# Nenghui Energy Theme - 短代码使用文档 + +本文档提供了 Nenghui Energy 主题中所有可用短代码的详细说明和使用示例。 + +## 目录 + +1. [产品相关短代码](#产品相关短代码) +2. [新闻相关短代码](#新闻相关短代码) +3. [关于页面短代码](#关于页面短代码) +4. [联系页面短代码](#联系页面短代码) +5. [通用组件短代码](#通用组件短代码) +6. [EPC相关短代码](#epc相关短代码) + +--- + +## 产品相关短代码 + +### `nenghui_products_list` - 产品列表 + +显示产品列表,支持分类筛选和分页。 + +**基本用法:** +```php +[nenghui_products_list] +``` + +**完整参数:** +```php +[nenghui_products_list + per_page="6" + category="residential" + order="date" + orderby="DESC" + category_order=""] +``` + +**参数说明:** +- `per_page` - 每页显示的产品数量(默认:6) +- `category` - 筛选特定分类(留空显示所有) +- `order` - 排序方式(默认:date) +- `orderby` - 排序字段(默认:DESC) +- `category_order` - 自定义分类排序 + +**产品自定义字段:** +- `cate_type` - 产品分类(必需) +- `cate_type_value` - 分类显示名称 +- `efficiency` - 效率值(如:≥93% Efficiency) +- `is_new` - 是否为新产品(true/false) +- `attr_key` - 属性名称(逗号分隔) +- `attr_value` - 属性值(逗号分隔) +- `_product_banner_url` - 产品横幅图片URL +- `_usage_scenario_data` - 使用场景数据(包含bottom_text) + +**示例:** +```php +// 显示所有产品,每页9个 +[nenghui_products_list per_page="9"] + +// 只显示residential分类的产品 +[nenghui_products_list category="residential"] + +// 自定义排序 +[nenghui_products_list order="title" orderby="ASC"] +``` + +--- + +### `nenghui_products_banner` - 产品横幅 + +显示产品页面横幅。 + +**基本用法:** +```php +[nenghui_products_banner] +``` + +或简化版本: +```php +[products_banner] +``` + +--- + +### `nenghui_warehousing_distribution` - 仓储配送 + +显示仓储配送信息。 + +**基本用法:** +```php +[nenghui_warehousing_distribution] +``` + +或简化版本: +```php +[warehousing_distribution] +``` + +--- + +## 新闻相关短代码 + +### `nenghui_news` - 新闻列表 + +显示新闻文章列表。 + +**基本用法:** +```php +[nenghui_news] +``` + +**完整参数:** +```php +[nenghui_news + title="最新资讯" + category_id="1" + posts_count="6" + order_by="date" + order="DESC"] +``` + +**参数说明:** +- `title` - 模块标题 +- `category_id` - 分类ID +- `posts_count` - 显示文章数量 +- `order_by` - 排序字段 +- `order` - 排序方向 + +--- + +### `nenghui_news_grid` - 新闻网格 + +以网格布局显示新闻。 + +**基本用法:** +```php +[nenghui_news_grid] +``` + +--- + +## 关于页面短代码 + +### `nenghui_about_nav` - 关于导航 + +显示关于页面的导航菜单。 + +**基本用法:** +```php +[nenghui_about_nav] +``` + +**自定义参数:** +```php +[nenghui_about_nav menu_id="123"] +``` + +**参数说明:** +- `menu_id` - 指定菜单ID(留空使用自定义器设置的默认菜单) + +--- + +### `nenghui_about_company` - 关于公司 + +显示公司介绍信息。 + +**基本用法:** +```php +[nenghui_about_company] +``` + +**自定义参数:** +```php +[nenghui_about_company show_animation="true"] +``` + +**参数说明:** +- `show_animation` - 是否显示动画效果 + +--- + +### `nenghui_development_history` - 发展历程 + +显示公司发展历程时间线。 + +**基本用法:** +```php +[nenghui_development_history] +``` + +**自定义参数:** +```php +[nenghui_development_history show_animation="true"] +``` + +--- + +### `nenghui_certification_gallery` - 认证画廊 + +显示公司认证证书画廊。 + +**基本用法:** +```php +[nenghui_certification_gallery] +``` + +**自定义参数:** +```php +[nenghui_certification_gallery + columns="5" + lightbox="true" + animation="true"] +``` + +**参数说明:** +- `columns` - 每行显示列数(1-6) +- `lightbox` - 是否启用灯箱效果 +- `animation` - 是否启用动画效果 + +--- + +### `nenghui_technical_service` - 技术服务 + +显示技术服务信息。 + +**基本用法:** +```php +[nenghui_technical_service] +``` + +**自定义参数:** +```php +[nenghui_technical_service + title="可靠的技术服务" + subtitle="提升客户体验"] +``` + +--- + +### `black_about_company_banner` - 关于公司横幅 + +显示关于页面的横幅。 + +**基本用法:** +```php +[black_about_company_banner] +``` + +--- + +### `nenghui_black_about_info` - 关于信息 + +显示公司详细信息。 + +**基本用法:** +```php +[nenghui_black_about_info] +``` + +或简化版本: +```php +[black_about_info] +``` + +--- + +### `business_process` - 业务流程 + +显示业务流程图。 + +**基本用法:** +```php +[business_process] +``` + +--- + +## 联系页面短代码 + +### `nenghui_contact_form` - 联系表单 + +显示联系表单。 + +**基本用法:** +```php +[nenghui_contact_form] +``` + +**自定义参数:** +```php +[nenghui_contact_form form_id="1" show_animation="true"] +``` + +**参数说明:** +- `form_id` - 表单ID +- `show_animation` - 是否显示动画效果 + +--- + +### `nenghui_contact_map` - 联系地图 + +显示联系地图。 + +**基本用法:** +```php +[nenghui_contact_map] +``` + +--- + +### `nenghui_overseas_services` - 海外服务 + +显示海外服务信息。 + +**基本用法:** +```php +[nenghui_overseas_services] +``` + +--- + +## 通用组件短代码 + +### `nenghui_banner` - 轮播横幅 + +显示轮播横幅。 + +**基本用法:** +```php +[nenghui_banner] +``` + +**自定义参数:** +```php +[nenghui_banner autoplay="true"] +``` + +**参数说明:** +- `autoplay` - 是否自动播放 + +--- + +### `nenghui_futures` - 未来展望 + +显示未来展望内容。 + +**基本用法:** +```php +[nenghui_futures] +``` + +**自定义参数:** +```php +[nenghui_futures title="未来展望" show_animation="true"] +``` + +--- + +### `nenghui_tabs` - 选项卡 + +显示选项卡内容。 + +**基本用法:** +```php +[nenghui_tabs] +``` + +**自定义参数:** +```php +[nenghui_tabs tabs_count="3" show_animation="true"] +``` + +--- + +### `nenghui_flowchart_tabs` - 流程图选项卡 + +显示流程图选项卡。 + +**基本用法:** +```php +[nenghui_flowchart_tabs] +``` + +--- + +### `nenghui_banner_title` - 标题横幅 + +显示带标题的横幅。 + +**基本用法:** +```php +[nenghui_banner_title title="关于我们" description="我们致力于提供最优质的服务"] +``` + +**完整参数:** +```php +[nenghui_banner_title + title="关于我们" + description="我们致力于提供最优质的服务" + bg_image="https://example.com/image.jpg" + height="70vh" + overlay_opacity="0.6" + show_animation="true"] +``` + +**参数说明:** +- `title` - 标题 +- `description` - 描述 +- `bg_image` - 背景图片URL +- `height` - 高度(支持px、vh、%) +- `overlay_opacity` - 遮罩透明度(0-1) +- `show_animation` - 是否显示动画 + +--- + +### `black_maps` - 黑色地图 + +显示交互式地图。 + +**基本用法:** +```php +[black_maps] +``` + +**自定义参数:** +```php +[black_maps height="100vh" show_loading="true"] +``` + +**参数说明:** +- `height` - 地图高度 +- `show_loading` - 是否显示加载动画 + +--- + +### `nenghui_video` - 视频 + +显示视频播放器。 + +**基本用法:** +```php +[nenghui_video video_url="https://example.com/video.mp4"] +``` + +**完整参数:** +```php +[nenghui_video + video_url="https://example.com/video.mp4" + cover_image="https://example.com/cover.jpg" + title="我们的企业视频" + description="了解我们的产品和服务" + play_button_text="立即播放" + show_overlay="true" + overlay_opacity="0.5" + height="80vh" + autoplay="false" + muted="true" + controls="true"] +``` + +**参数说明:** +- `video_url` - 视频URL(必需) +- `cover_image` - 封面图片URL +- `title` - 视频标题 +- `description` - 视频描述 +- `play_button_text` - 播放按钮文字 +- `show_overlay` - 是否显示遮罩 +- `overlay_opacity` - 遮罩透明度 +- `height` - 视频高度 +- `autoplay` - 是否自动播放 +- `muted` - 是否静音 +- `controls` - 是否显示控制栏 + +--- + +### `nenghui_download_center` - 下载中心 + +显示下载中心。 + +**基本用法:** +```php +[nenghui_download_center] +``` + +--- + +### `nenghui_faq` - 常见问题 + +显示常见问题列表。 + +**基本用法:** +```php +[nenghui_faq] +``` + +--- + +### `nenghui_cases` - 案例展示 + +显示案例展示。 + +**基本用法:** +```php +[nenghui_cases] +``` + +--- + +## EPC相关短代码 + +### `nenghui_epc` - EPC解决方案 + +显示EPC解决方案。 + +**基本用法:** +```php +[nenghui_epc] +``` + +**自定义参数:** +```php +[nenghui_epc + title="EPC Solutions" + subtitle="Beyond Hardware: Total EPC Solutions from NengHui Design Institute" + bg_image="https://example.com/epc-bg.jpg"] +``` + +--- + +### `nenghui_epc_banner` - EPC横幅 + +显示EPC横幅。 + +**基本用法:** +```php +[nenghui_epc_banner] +``` + +--- + +## 使用技巧 + +### 1. 在页面编辑器中使用 + +在WordPress页面编辑器中,直接输入短代码即可: + +``` +[nenghui_products_list per_page="9"] +``` + +### 2. 在模板文件中使用 + +在主题模板文件中使用 `do_shortcode()` 函数: + +```php + +``` + +### 3. 组合使用多个短代码 + +可以在同一个页面中使用多个短代码: + +``` +[nenghui_banner_title title="我们的产品"] +[nenghui_products_list per_page="9"] +[nenghui_contact_form] +``` + +### 4. 响应式设计 + +所有短代码都支持响应式设计,会自动适应不同屏幕尺寸。 + +### 5. 深色模式 + +所有短代码都支持深色模式,会自动根据系统设置切换主题。 + +## 常见问题 + +### Q: 短代码不显示怎么办? + +A: 请确保: +1. 短代码名称拼写正确 +2. 主题已正确激活 +3. 没有PHP错误(检查调试日志) + +### Q: 如何自定义短代码样式? + +A: 可以通过以下方式自定义: +1. 在自定义器中修改相关设置 +2. 使用CSS覆盖默认样式 +3. 修改对应的模板文件 + +### Q: 短代码参数不生效怎么办? + +A: 请确保: +1. 参数名称拼写正确 +2. 参数值格式正确 +3. 没有特殊字符冲突 + +### Q: 如何添加新的短代码? + +A: 可以在 `inc/shortcode.php` 文件中添加新的短代码函数,参考现有短代码的实现方式。 + +## 技术支持 + +如需技术支持,请联系开发团队或查看主题文档。 + +--- + +**文档版本:** 1.0 +**最后更新:** 2026-02-09 +**主题版本:** nenghui-energy-theme-4 diff --git a/wp-content/themes/nenghui-energy-theme-4/functions.php b/wp-content/themes/nenghui-energy-theme-4/functions.php index af6aa5b..5a48930 100644 --- a/wp-content/themes/nenghui-energy-theme-4/functions.php +++ b/wp-content/themes/nenghui-energy-theme-4/functions.php @@ -334,4 +334,139 @@ class Nenghui_Walker_Nav_Menu extends Walker_Nav_Menu { } } +function get_post_meta_by_key($key, $cate_type) { + global $wpdb; + $table = $wpdb->postmeta; + $result = $wpdb->get_var($wpdb->prepare( + "SELECT meta_value FROM $table WHERE meta_key = %s AND post_id IN ( + SELECT post_id FROM $table WHERE meta_key = 'cate_type' AND meta_value LIKE %s + ) LIMIT 1", + $key, + '%' . $wpdb->esc_like($cate_type) . '%' + )); + return $result; +} + +add_action('wp_ajax_load_more_products', 'load_more_products_callback'); +add_action('wp_ajax_nopriv_load_more_products', 'load_more_products_callback'); + +function load_more_products_callback() { + check_ajax_referer('load_more_products_nonce', 'nonce'); + + $offset = intval($_POST['offset']); + $per_page = intval($_POST['per_page']); + $category = isset($_POST['category']) ? sanitize_text_field($_POST['category']) : ''; + + $meta_query = array(); + + if (!empty($category) && $category !== 'all') { + $meta_query[] = array( + 'key' => 'cate_type', + 'value' => $category, + 'compare' => 'LIKE' + ); + } + + $query_args = array( + 'post_type' => 'products', + 'posts_per_page' => $per_page, + 'offset' => $offset, + 'meta_query' => $meta_query, + 'post_status' => 'publish' + ); + + $products_query = new WP_Query($query_args); + $products = array(); + + if ($products_query->have_posts()) { + while ($products_query->have_posts()) { + $products_query->the_post(); + $post_id = get_the_ID(); + $cate_type = get_post_meta($post_id, 'cate_type', true); + + $cover_image = get_the_post_thumbnail_url($post_id, 'product-cover-medium'); + if (empty($cover_image)) { + $cover_image = get_post_meta($post_id, '_product_banner_url', true); + } + if (empty($cover_image)) { + $cover_image = get_template_directory_uri() . '/assets/images/products-1.webp'; + } + + $usage_scenario_data = get_post_meta($post_id, '_usage_scenario_data', true); + $description = ''; + if (!empty($usage_scenario_data) && isset($usage_scenario_data['bottom_text'])) { + $description = $usage_scenario_data['bottom_text']; + } + $attr_keys = get_post_meta($post_id, 'attr_key', true); + $attr_values = get_post_meta($post_id, 'attr_value', true); + $attr_keys_array = !empty($attr_keys) ? explode(',', $attr_keys) : array(); + $attr_values_array = !empty($attr_values) ? explode(',', $attr_values) : array(); + $attrs = array(); + for ($i = 0; $i < min(4, count($attr_keys_array)); $i++) { + if (isset($attr_keys_array[$i]) && isset($attr_values_array[$i])) { + $attrs[] = array( + 'key' => trim($attr_keys_array[$i]), + 'value' => trim($attr_values_array[$i]) + ); + } + } + $efficiency = get_post_meta($post_id, 'efficiency', true); + $is_new = get_post_meta($post_id, 'is_new', true); + $is_new_value = filter_var($is_new, FILTER_VALIDATE_BOOLEAN); + + ob_start(); + ?> +
+
+ +
+ NEW +
+ + +
+ +
+ +
+
+
+
+
+

+ + NEW + +
+
+
+ +
+

+

+
+ +
+

+ +

+ + + +
+
+ ob_get_clean() + ); + } + wp_reset_postdata(); + } + + wp_send_json_success(array('products' => $products)); +} + ?> \ No newline at end of file diff --git a/wp-content/themes/nenghui-energy-theme-4/inc/shortcode.php b/wp-content/themes/nenghui-energy-theme-4/inc/shortcode.php index 7fd5b6b..3d4c490 100644 --- a/wp-content/themes/nenghui-energy-theme-4/inc/shortcode.php +++ b/wp-content/themes/nenghui-energy-theme-4/inc/shortcode.php @@ -1693,4 +1693,30 @@ function nenghui_business_process_shortcode($atts) { return $output; } -add_shortcode('business_process', 'nenghui_business_process_shortcode'); \ No newline at end of file +add_shortcode('business_process', 'nenghui_business_process_shortcode'); + +function nenghui_products_list_shortcode($atts) { + if (!is_array($atts)) { + $atts = array(); + } + + $atts = shortcode_atts(array( + 'id' => 'nenghui-products-list-shortcode', + 'class' => '', + 'per_page' => '3', + 'category' => '', + 'order' => 'date', + 'orderby' => 'DESC', + 'category_order' => '' + ), $atts); + + ob_start(); + + global $products_list_shortcode_atts; + $products_list_shortcode_atts = $atts; + + include get_template_directory() . '/template-parts/blocks/block-products-list.php'; + + return ob_get_clean(); +} +add_shortcode('nenghui_products_list', 'nenghui_products_list_shortcode'); diff --git a/wp-content/themes/nenghui-energy-theme-4/inc/theme-setup.php b/wp-content/themes/nenghui-energy-theme-4/inc/theme-setup.php index 8af5c95..f14afc4 100644 --- a/wp-content/themes/nenghui-energy-theme-4/inc/theme-setup.php +++ b/wp-content/themes/nenghui-energy-theme-4/inc/theme-setup.php @@ -16,18 +16,23 @@ if (!defined('ABSPATH')) { function nenghui_theme_setup() { // 启用文章特色图像(缩略图)支持 add_theme_support('post-thumbnails'); - + // 启用文章和页面的特色图像 add_theme_support('post-thumbnails', array('post', 'page')); - + // 设置特色图像的默认尺寸 set_post_thumbnail_size(800, 600, true); - + // 添加自定义图像尺寸 add_image_size('nenghui-large', 1200, 800, true); add_image_size('nenghui-medium', 600, 400, true); add_image_size('nenghui-small', 300, 200, true); - + + // 添加产品封面图尺寸 + add_image_size('product-cover-large', 1200, 800, true); + add_image_size('product-cover-medium', 600, 400, true); + add_image_size('product-cover-small', 300, 200, true); + // 启用HTML5支持 add_theme_support('html5', array( 'search-form', @@ -36,10 +41,10 @@ function nenghui_theme_setup() { 'gallery', 'caption' )); - + // 启用自动feed链接 add_theme_support('automatic-feed-links'); - + // 启用标题标签支持 add_theme_support('title-tag'); } @@ -102,16 +107,16 @@ function disable_comments_functionality() { // 移除评论支持 remove_post_type_support('post', 'comments'); remove_post_type_support('page', 'comments'); - + // 移除评论相关的菜单项 remove_menu_page('edit-comments.php'); - + // 移除评论相关的管理栏项目 remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60); - + // 禁用评论feed remove_action('wp_head', 'feed_links_extra', 3); - + // 重定向评论页面 if (is_admin() && isset($_GET['page']) && $_GET['page'] === 'edit-comments.php') { wp_redirect(admin_url()); @@ -127,7 +132,7 @@ add_action('admin_init', 'disable_comments_functionality'); function close_existing_comments() { // 关闭新文章的评论 update_option('default_comment_status', 'closed'); - + // 关闭新页面的评论 update_option('default_ping_status', 'closed'); } @@ -183,7 +188,7 @@ function disable_comments_rest_api($endpoints) { if (!is_array($endpoints) || empty($endpoints)) { return is_array($endpoints) ? $endpoints : array(); } - + // 安全地移除评论相关的端点 if (isset($endpoints['/wp/v2/comments'])) { unset($endpoints['/wp/v2/comments']); @@ -236,7 +241,7 @@ function register_download_center_post_type() { 'items_list_navigation' => '下载列表导航', 'filter_items_list' => '筛选下载列表', ); - + $args = array( 'label' => '下载中心', 'description' => '管理下载中心的文件和资源', @@ -258,7 +263,7 @@ function register_download_center_post_type() { 'capability_type' => 'post', 'show_in_rest' => true, ); - + register_post_type('download_center', $args); } add_action('init', 'register_download_center_post_type', 0); @@ -289,7 +294,7 @@ function register_download_category_taxonomy() { 'items_list' => '分类列表', 'items_list_navigation' => '分类列表导航', ); - + $args = array( 'labels' => $labels, 'hierarchical' => true, @@ -300,7 +305,7 @@ function register_download_category_taxonomy() { 'show_tagcloud' => true, 'show_in_rest' => true, ); - + register_taxonomy('download_category', array('download_center'), $args); } add_action('init', 'register_download_category_taxonomy', 0); @@ -313,7 +318,7 @@ function create_default_download_categories() { if (get_option('nenghui_download_categories_created')) { return; } - + // 创建 Company profile 分类 if (!term_exists('Company profile', 'download_category')) { wp_insert_term( @@ -325,7 +330,7 @@ function create_default_download_categories() { ) ); } - + // 创建 Product series 分类 if (!term_exists('Product series', 'download_category')) { wp_insert_term( @@ -337,7 +342,7 @@ function create_default_download_categories() { ) ); } - + // 标记已创建默认分类 update_option('nenghui_download_categories_created', true); } @@ -363,7 +368,7 @@ add_action('add_meta_boxes', 'add_download_center_meta_boxes'); */ function enqueue_download_center_admin_scripts($hook) { global $post; - + // 在下载中心和产品的编辑页面加载 if ($hook == 'post-new.php' || $hook == 'post.php') { if ('download_center' === $post->post_type || 'products' === $post->post_type) { @@ -380,12 +385,12 @@ add_action('admin_enqueue_scripts', 'enqueue_download_center_admin_scripts'); function download_file_info_callback($post) { // 添加nonce字段用于安全验证 wp_nonce_field('download_file_info_nonce', 'download_file_info_nonce'); - + // 获取现有值 $download_url = get_post_meta($post->ID, '_download_url', true); $file_size = get_post_meta($post->ID, '_file_size', true); $file_type = get_post_meta($post->ID, '_file_type', true); - + echo ''; echo ''; echo ''; @@ -404,23 +409,23 @@ function download_file_info_callback($post) { echo ''; echo ''; echo '
'; - + echo '

请填写下载文件的相关信息。如果不填写下载链接,将使用特色图像作为下载文件。

'; - + // 添加JavaScript代码用于媒体库选择 echo ' + ID, '_product_description', true); ?>
@@ -896,7 +997,7 @@ function product_description_meta_box_callback($post) { 'buttons' => 'strong,em,ul,ol,li,link,close' ) ); - + // 输出富文本编辑器 wp_editor($product_description, 'product_description', $editor_settings); ?> @@ -912,15 +1013,15 @@ function save_product_description($post_id) { if (!isset($_POST['product_description_nonce']) || !wp_verify_nonce($_POST['product_description_nonce'], 'save_product_description')) { return; } - + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } - + if (!current_user_can('edit_post', $post_id)) { return; } - + if (isset($_POST['product_description'])) { // 使用wp_kses_post来保留安全的HTML标签 update_post_meta($post_id, '_product_description', wp_kses_post($_POST['product_description'])); @@ -933,18 +1034,18 @@ add_action('save_post', 'save_product_description'); */ function product_features_meta_box_callback($post) { wp_nonce_field('save_product_features', 'product_features_nonce'); - + // 获取产品特性显示开关和特性数据 $show_features = get_post_meta($post->ID, '_show_product_features', true); if ($show_features === '') { $show_features = '1'; // 默认显示 } - + $features = get_post_meta($post->ID, '_product_features', true); if (!is_array($features)) { $features = array(); } - + // 默认特性数据(与前端硬编码内容保持一致) $default_features = array( array( @@ -984,16 +1085,16 @@ function product_features_meta_box_callback($post) { 'alt' => 'Ultimate Safety' ) ); - + // 如果没有保存的数据,使用默认数据 if (empty($features)) { $features = $default_features; } - + ?>

产品特性板块设置:

- +

勾选此选项将在前端显示产品特性卡片,取消勾选将隐藏整个板块。

- +

产品特性卡片管理

- +
$feature): ?>
@@ -1023,7 +1124,7 @@ function product_features_meta_box_callback($post) { - 可以使用 <br> 标签换行 @@ -1031,7 +1132,7 @@ function product_features_meta_box_callback($post) { - 可以使用 <br> 标签换行 @@ -1040,14 +1141,14 @@ function product_features_meta_box_callback($post) {
-
图标文件名或完整URL
- - 图片的Alt属性,用于无障碍访问和SEO @@ -1073,10 +1174,10 @@ function product_features_meta_box_callback($post) {
- +

注意:修改后需要点击"更新"按钮保存设置。

- + - + \ No newline at end of file