'主导航菜单' )); } add_action('init', 'register_theme_menus'); /** * 自定义网站底部版权信息和加载时间 * 使用方法: * 1. 此函数会自动在后台底部显示 * 2. 在前台footer.php中显示,需添加以下代码: * */ function footerText() { $year = date('Y'); return '

' . $year . ' © Shang hai Nenghui Energy | 版权所有 | 优化后加载耗时:' . timer_stop(0, 3) . '秒

'; } // 在后台底部显示 add_action('admin_footer_text', 'footerText', 9999); // 在前台底部显示 add_action('wp_footer', 'footerText', 9999); /** * 启用图片懒加载机制 * 为图片添加懒加载属性以提升页面性能 */ add_filter('wp_lazy_loading_enabled', '__return_true'); /** * 为内容中的图片添加懒加载属性 * @param string $content 文章内容 * @return string 处理后的内容 */ function add_lazy_loading_to_images($content) { if (is_feed() || is_preview()) { return $content; } $content = preg_replace('/]*)(?/i', '', $content); return $content; } add_filter('the_content', 'add_lazy_loading_to_images'); add_filter('post_thumbnail_html', 'add_lazy_loading_to_images'); /** * 禁用评论功能 * 完全禁用WordPress的评论系统以避免comments.php弃用警告 */ 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()); exit; } } add_action('init', 'disable_comments_functionality'); add_action('admin_init', 'disable_comments_functionality'); /** * 关闭所有现有文章和页面的评论 */ function close_existing_comments() { // 关闭新文章的评论 update_option('default_comment_status', 'closed'); // 关闭新页面的评论 update_option('default_ping_status', 'closed'); } add_action('admin_init', 'close_existing_comments'); /** * 移除评论相关的元框 */ function remove_comment_metaboxes() { remove_meta_box('commentsdiv', 'post', 'normal'); remove_meta_box('commentstatusdiv', 'post', 'normal'); remove_meta_box('trackbacksdiv', 'post', 'normal'); remove_meta_box('commentsdiv', 'page', 'normal'); remove_meta_box('commentstatusdiv', 'page', 'normal'); remove_meta_box('trackbacksdiv', 'page', 'normal'); } add_action('admin_menu', 'remove_comment_metaboxes'); /** * 隐藏评论相关的设置选项 */ function hide_comment_settings() { echo ''; } add_action('admin_head-options-discussion.php', 'hide_comment_settings'); /** * 移除评论相关的REST API端点 */ function disable_comments_rest_api($endpoints) { // 确保 $endpoints 是数组且不为空 if (!is_array($endpoints) || empty($endpoints)) { return is_array($endpoints) ? $endpoints : array(); } // 安全地移除评论相关的端点 if (isset($endpoints['/wp/v2/comments'])) { unset($endpoints['/wp/v2/comments']); } if (isset($endpoints['/wp/v2/comments/(?P[\d]+)'])) { unset($endpoints['/wp/v2/comments/(?P[\d]+)']); } return $endpoints; } add_filter('rest_endpoints', 'disable_comments_rest_api'); /** * 移除评论相关的小工具 */ function remove_comment_widgets() { unregister_widget('WP_Widget_Recent_Comments'); } add_action('widgets_init', 'remove_comment_widgets'); /** * 注册下载中心自定义文章类型 */ function register_download_center_post_type() { $labels = array( 'name' => '下载中心', 'singular_name' => '下载项目', 'menu_name' => '下载中心', 'name_admin_bar' => '下载项目', 'archives' => '下载归档', 'attributes' => '下载属性', 'parent_item_colon' => '父级下载项目:', 'all_items' => '所有下载', 'add_new_item' => '添加新下载', 'add_new' => '添加新下载', 'new_item' => '新下载项目', 'edit_item' => '编辑下载', 'update_item' => '更新下载', 'view_item' => '查看下载', 'view_items' => '查看下载', 'search_items' => '搜索下载', 'not_found' => '未找到下载项目', 'not_found_in_trash' => '回收站中未找到下载项目', 'featured_image' => '特色图像', 'set_featured_image' => '设置特色图像', 'remove_featured_image' => '移除特色图像', 'use_featured_image' => '使用特色图像', 'insert_into_item' => '插入到下载项目', 'uploaded_to_this_item' => '上传到此下载项目', 'items_list' => '下载列表', 'items_list_navigation' => '下载列表导航', 'filter_items_list' => '筛选下载列表', ); $args = array( 'label' => '下载中心', 'description' => '管理下载中心的文件和资源', 'labels' => $labels, 'supports' => array('title', 'editor', 'thumbnail', 'custom-fields'), 'taxonomies' => array('download_category'), 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 20, 'menu_icon' => 'dashicons-download', 'show_in_admin_bar' => true, 'show_in_nav_menus' => true, 'can_export' => true, 'has_archive' => true, 'exclude_from_search' => false, 'publicly_queryable' => true, 'capability_type' => 'post', 'show_in_rest' => true, ); register_post_type('download_center', $args); } add_action('init', 'register_download_center_post_type', 0); /** * 注册下载分类法 */ function register_download_category_taxonomy() { $labels = array( 'name' => '下载分类', 'singular_name' => '下载分类', 'menu_name' => '下载分类', 'all_items' => '所有分类', 'parent_item' => '父级分类', 'parent_item_colon' => '父级分类:', 'new_item_name' => '新分类名称', 'add_new_item' => '添加新分类', 'edit_item' => '编辑分类', 'update_item' => '更新分类', 'view_item' => '查看分类', 'separate_items_with_commas' => '用逗号分隔分类', 'add_or_remove_items' => '添加或移除分类', 'choose_from_most_used' => '从常用分类中选择', 'popular_items' => '热门分类', 'search_items' => '搜索分类', 'not_found' => '未找到分类', 'no_terms' => '无分类', 'items_list' => '分类列表', 'items_list_navigation' => '分类列表导航', ); $args = array( 'labels' => $labels, 'hierarchical' => true, 'public' => true, 'show_ui' => true, 'show_admin_column' => true, 'show_in_nav_menus' => true, 'show_tagcloud' => true, 'show_in_rest' => true, ); register_taxonomy('download_category', array('download_center'), $args); } add_action('init', 'register_download_category_taxonomy', 0); /** * 创建默认下载分类 */ 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( 'Company profile', 'download_category', array( 'description' => '公司简介相关下载文件', 'slug' => 'company-profile', ) ); } // 创建 Product series 分类 if (!term_exists('Product series', 'download_category')) { wp_insert_term( 'Product series', 'download_category', array( 'description' => '产品系列相关下载文件', 'slug' => 'product-series', ) ); } // 标记已创建默认分类 update_option('nenghui_download_categories_created', true); } add_action('init', 'create_default_download_categories'); /** * 为下载中心添加自定义字段 */ function add_download_center_meta_boxes() { add_meta_box( 'download_file_info', '下载文件信息', 'download_file_info_callback', 'download_center', 'normal', 'high' ); } 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) { // 加载媒体库脚本 wp_enqueue_media(); } } } 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 ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
'; echo ''; echo ''; echo '
可以直接输入链接,或点击"选择文件"从媒体库选择'; echo '
'; echo '

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

'; // 添加JavaScript代码用于媒体库选择 echo ''; } /** * 保存下载文件信息 */ function save_download_file_info($post_id) { // 验证nonce if (!isset($_POST['download_file_info_nonce']) || !wp_verify_nonce($_POST['download_file_info_nonce'], 'download_file_info_nonce')) { return; } // 检查用户权限 if (!current_user_can('edit_post', $post_id)) { return; } // 检查是否为自动保存 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } // 保存字段 if (isset($_POST['download_url'])) { update_post_meta($post_id, '_download_url', sanitize_url($_POST['download_url'])); } if (isset($_POST['file_size'])) { update_post_meta($post_id, '_file_size', sanitize_text_field($_POST['file_size'])); } if (isset($_POST['file_type'])) { update_post_meta($post_id, '_file_type', sanitize_text_field($_POST['file_type'])); } } add_action('save_post', 'save_download_file_info'); /** * 注册案例展示自定义文章类型 */ function register_cases_post_type() { $labels = array( 'name' => '案例展示', 'singular_name' => '案例', 'menu_name' => '案例展示', 'name_admin_bar' => '案例', 'archives' => '案例归档', 'attributes' => '案例属性', 'parent_item_colon' => '父级案例:', 'all_items' => '所有案例', 'add_new_item' => '添加新案例', 'add_new' => '添加新案例', 'new_item' => '新案例', 'edit_item' => '编辑案例', 'update_item' => '更新案例', 'view_item' => '查看案例', 'view_items' => '查看案例', 'search_items' => '搜索案例', 'not_found' => '未找到案例', 'not_found_in_trash' => '回收站中未找到案例', 'featured_image' => '案例特色图像', 'set_featured_image' => '设置案例特色图像', 'remove_featured_image' => '移除案例特色图像', 'use_featured_image' => '使用案例特色图像', 'insert_into_item' => '插入到案例', 'uploaded_to_this_item' => '上传到此案例', 'items_list' => '案例列表', 'items_list_navigation' => '案例列表导航', 'filter_items_list' => '筛选案例列表', ); $args = array( 'label' => '案例展示', 'description' => '案例展示文章类型', 'labels' => $labels, 'supports' => array('title', 'editor', 'thumbnail', 'excerpt'), 'taxonomies' => array('case_category'), 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 6, 'menu_icon' => 'dashicons-portfolio', 'show_in_admin_bar' => true, 'show_in_nav_menus' => true, 'can_export' => true, 'has_archive' => true, 'exclude_from_search' => false, 'publicly_queryable' => true, 'capability_type' => 'post', 'show_in_rest' => true, 'rewrite' => array('slug' => 'cases'), ); register_post_type('cases', $args); } add_action('init', 'register_cases_post_type', 0); /** * 注册案例分类法 */ function register_case_category_taxonomy() { $labels = array( 'name' => '案例分类', 'singular_name' => '案例分类', 'menu_name' => '案例分类', 'all_items' => '所有分类', 'parent_item' => '父级分类', 'parent_item_colon' => '父级分类:', 'new_item_name' => '新分类名称', 'add_new_item' => '添加新分类', 'edit_item' => '编辑分类', 'update_item' => '更新分类', 'view_item' => '查看分类', 'separate_items_with_commas' => '用逗号分隔分类', 'add_or_remove_items' => '添加或移除分类', 'choose_from_most_used' => '从最常用的分类中选择', 'popular_items' => '热门分类', 'search_items' => '搜索分类', 'not_found' => '未找到分类', 'no_terms' => '没有分类', 'items_list' => '分类列表', 'items_list_navigation' => '分类列表导航', ); $args = array( 'labels' => $labels, 'hierarchical' => true, 'public' => true, 'show_ui' => true, 'show_admin_column' => true, 'show_in_nav_menus' => true, 'show_tagcloud' => true, 'show_in_rest' => true, 'rewrite' => array('slug' => 'case-category'), ); register_taxonomy('case_category', array('cases'), $args); } add_action('init', 'register_case_category_taxonomy', 0); /** * 创建默认案例分类 */ function create_default_case_categories() { // 检查是否已经创建过默认分类 if (get_option('nenghui_case_categories_created')) { return; } // 创建 Power Station 分类 if (!term_exists('Power Station', 'case_category')) { wp_insert_term( 'Power Station', 'case_category', array( 'description' => '电站项目案例', 'slug' => 'power-station', ) ); } // 创建 PV Project 分类 if (!term_exists('PV Project', 'case_category')) { wp_insert_term( 'PV Project', 'case_category', array( 'description' => '光伏项目案例', 'slug' => 'pv-project', ) ); } // 创建 Agricultural Solar 分类 if (!term_exists('Agricultural Solar', 'case_category')) { wp_insert_term( 'Agricultural Solar', 'case_category', array( 'description' => '农业太阳能项目案例', 'slug' => 'agricultural-solar', ) ); } // 标记已创建默认分类 update_option('nenghui_case_categories_created', true); } add_action('init', 'create_default_case_categories'); /** * 注册产品自定义文章类型 */ function register_products_post_type() { $labels = array( 'name' => '产品管理', 'singular_name' => '产品', 'menu_name' => '产品管理', 'name_admin_bar' => '产品', 'archives' => '产品归档', 'attributes' => '产品属性', 'parent_item_colon' => '父级产品:', 'all_items' => '所有产品', 'add_new_item' => '添加新产品', 'add_new' => '添加新产品', 'new_item' => '新产品', 'edit_item' => '编辑产品', 'update_item' => '更新产品', 'view_item' => '查看产品', 'view_items' => '查看产品', 'search_items' => '搜索产品', 'not_found' => '未找到产品', 'not_found_in_trash' => '回收站中未找到产品', 'featured_image' => '产品特色图像', 'set_featured_image' => '设置产品特色图像', 'remove_featured_image' => '移除产品特色图像', 'use_featured_image' => '使用产品特色图像', 'insert_into_item' => '插入到产品', 'uploaded_to_this_item' => '上传到此产品', 'items_list' => '产品列表', 'items_list_navigation' => '产品列表导航', 'filter_items_list' => '筛选产品列表', ); $args = array( 'label' => '产品管理', 'description' => '产品展示和管理', 'labels' => $labels, 'supports' => array('title', 'thumbnail', 'custom-fields'), 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 5, 'menu_icon' => 'dashicons-products', 'show_in_admin_bar' => true, 'show_in_nav_menus' => true, 'can_export' => true, 'has_archive' => true, 'exclude_from_search' => false, 'publicly_queryable' => true, 'capability_type' => 'post', 'show_in_rest' => true, 'rewrite' => array('slug' => 'products'), ); register_post_type('products', $args); } add_action('init', 'register_products_post_type', 0); /** * 添加产品Banner图片meta box */ function add_products_banner_meta_box() { add_meta_box( 'product_banner_meta_box', '产品Banner图片', 'product_banner_meta_box_callback', 'products', 'normal', 'high' ); } add_action('add_meta_boxes', 'add_products_banner_meta_box'); /** * 添加产品封面图meta box */ function add_product_cover_meta_box() { add_meta_box( 'product_cover_meta_box', '产品封面图', 'product_cover_meta_box_callback', 'products', 'normal', 'high' ); } add_action('add_meta_boxes', 'add_product_cover_meta_box'); /** * 添加产品特性meta box */ function add_products_features_meta_box() { add_meta_box( 'product_features_meta_box', '产品特性设置', 'product_features_meta_box_callback', 'products', 'normal', 'high' ); } add_action('add_meta_boxes', 'add_products_features_meta_box'); /** * 添加使用场景meta box */ function add_products_usage_scenario_meta_box() { add_meta_box( 'product_usage_scenario_meta_box', '使用场景设置', 'product_usage_scenario_meta_box_callback', 'products', 'normal', 'high' ); } add_action('add_meta_boxes', 'add_products_usage_scenario_meta_box'); /** * 添加技术规格meta box */ function add_products_technical_specs_meta_box() { add_meta_box( 'product_technical_specs_meta_box', '技术规格设置', 'product_technical_specs_meta_box_callback', 'products', 'normal', 'high' ); } add_action('add_meta_boxes', 'add_products_technical_specs_meta_box'); /** * 添加产品PDF下载meta box */ function add_products_pdf_downloads_meta_box() { add_meta_box( 'product_pdf_downloads_meta_box', 'PDF下载设置', 'product_pdf_downloads_meta_box_callback', 'products', 'normal', 'high' ); } add_action('add_meta_boxes', 'add_products_pdf_downloads_meta_box'); /** * 添加产品描述meta box */ function add_products_description_meta_box() { add_meta_box( 'product_description_meta_box', '产品描述', 'product_description_meta_box_callback', 'products', 'normal', 'high' ); } add_action('add_meta_boxes', 'add_products_description_meta_box'); /** * 产品Banner图片meta box回调函数 */ function product_banner_meta_box_callback($post) { wp_nonce_field('save_product_banner', 'product_banner_nonce'); $banner_url = get_post_meta($post->ID, '_product_banner_url', true); ?>

建议尺寸:1920x600像素
ID); $cover_url = $cover_id ? wp_get_attachment_image_url($cover_id, 'medium') : ''; ?>

建议尺寸:1200x800像素
ID, '_product_description', true); ?>
'product_description', 'textarea_rows' => 8, 'media_buttons' => true, 'teeny' => false, 'dfw' => false, 'tinymce' => array( 'resize' => false, 'wp_autoresize_on' => true, 'add_unload_trigger' => false, 'toolbar1' => 'bold,italic,underline,strikethrough,|,bullist,numlist,blockquote,|,link,unlink,|,spellchecker,fullscreen,wp_adv', 'toolbar2' => 'formatselect,forecolor,backcolor,|,pastetext,removeformat,charmap,|,outdent,indent,|,undo,redo' ), 'quicktags' => array( 'buttons' => 'strong,em,ul,ol,li,link,close' ) ); // 输出富文本编辑器 wp_editor($product_description, 'product_description', $editor_settings); ?>

此描述将显示在产品页面的标题下方,用于简要介绍产品特点和用途。支持富文本格式。

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( 'title' => 'COMPACT
DESIGN', 'description' => 'Light footprint, easy frame
installation and field installation.', 'icon' => 'product-icon-1.webp', 'alt' => 'Compact Design' ), array( 'title' => 'HIGH
INTEGRATION', 'description' => '20kWh+ energy in one cabinet
with DC/AC power conversion
& thermal cooling.', 'icon' => 'product-icon-2.webp', 'alt' => 'High Integration' ), array( 'title' => 'EFFICIENT
COOLING', 'description' => 'Optimal air-duct design optimizes
airflow for improved cooling with low
energy consumption.', 'icon' => 'product-icon-3.webp', 'alt' => 'Efficient Cooling' ), array( 'title' => 'LONG
CYCLE LIFE', 'description' => 'Over 6,000 times cycle life, excellent
performance of battery system.', 'icon' => 'product-icon-4.webp', 'alt' => 'Long Cycle Life' ), array( 'title' => 'FLEXIBLE
EXPANSION', 'description' => 'Modular design, simplified panel
for expansion.', 'icon' => 'product-icon-5.webp', 'alt' => 'Flexible Expansion' ), array( 'title' => 'ULTIMATE
SAFETY', 'description' => 'Comprehensive safety protection
with NOVEC1230 thermal prevent
heat diffusion and spreading.', 'icon' => 'product-icon-6.webp', 'alt' => 'Ultimate Safety' ) ); // 如果没有保存的数据,使用默认数据 if (empty($features)) { $features = $default_features; } ?>

产品特性板块设置:

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

产品特性卡片管理

$feature): ?>

特性

可以使用 <br> 标签换行
可以使用 <br> 标签换行
图标文件名或完整URL
图片的Alt属性,用于无障碍访问和SEO

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

sanitize_text_field($feature['title']), 'description' => sanitize_textarea_field($feature['description']), 'icon' => sanitize_text_field($feature['icon']), 'alt' => sanitize_text_field($feature['alt']) ); } update_post_meta($post_id, '_product_features', $features); } } add_action('save_post', 'save_product_features'); /** * 使用场景meta box回调函数 */ function product_usage_scenario_meta_box_callback($post) { wp_nonce_field('save_product_usage_scenario', 'product_usage_scenario_nonce'); // 获取使用场景显示开关和数据 $show_usage_scenario = get_post_meta($post->ID, '_show_usage_scenario', true); if ($show_usage_scenario === '') { $show_usage_scenario = '1'; // 默认显示 } $usage_scenario_data = get_post_meta($post->ID, '_usage_scenario_data', true); if (!is_array($usage_scenario_data)) { $usage_scenario_data = array(); } // 默认使用场景数据 $default_data = array( 'title' => 'USAGE SCENARIO', 'description' => 'Off-grid PV, energy storage, diesel generation, and charging post', 'image' => 'Usage scenario.webp', 'bottom_text' => 'Nenghui all-in-one liquid-cooled ESS cabinet adopts advanced cabinet-level liquid cooling and temperature balancing strategy. The cell temperature difference is less than 3°C, which further improves the consistency of cell temperature and extends the battery life. The modular design makes the parallel solution more flexible and has a higher energy density, which significantly improves the economy, safety and construction convenience of ESS projects.' ); // 如果没有保存的数据,使用默认数据 if (empty($usage_scenario_data)) { $usage_scenario_data = $default_data; } ?>

使用场景板块设置:

勾选此选项将在前端显示使用场景板块,取消勾选将隐藏整个板块。

使用场景板块的主标题
使用场景的简短描述

图片URL或文件名(如:Usage scenario.webp),如果是文件名,文件应放在 /assets/images/ 目录下
使用场景图片下方的详细说明文字

注意:修改后需要点击"更新"按钮保存设置。图片文件需要手动上传到主题的 assets/images 目录。

ID, '_show_technical_specs', true); if ($show_technical_specs === '') { $show_technical_specs = '1'; // 默认显示 } $technical_specs_data = get_post_meta($post->ID, '_technical_specs_data', true); if (!is_array($technical_specs_data)) { $technical_specs_data = array(); } // 默认技术规格数据 $default_specs = array( array( 'title' => 'DC Side', 'content' => '
Cell TypeLFP280Ah
PACK46.592kWh/IP25S
Battery System232.96kWh/IP260S
Rated Voltage832Vdc
Voltage Range728-936Vdc
Pack Ingress RatingIP65
', 'expanded' => true ), array( 'title' => 'AC Side', 'content' => '
Rated Power100kW
Max. Power110kW
THDi≤3%
DC Ratio≤0.5%lon
Nominal Voltage400Vac/3P+N+PE
Power Factor-1lagging~1leading
Nominal Frequency50Hz/60Hz
', 'expanded' => false ) ); // 如果没有保存的数据,使用默认数据 if (empty($technical_specs_data)) { $technical_specs_data = $default_specs; } ?>

技术规格板块设置:

勾选此选项将在前端显示技术规格折叠面板,取消勾选将隐藏整个板块。

技术规格面板:

$spec): ?>

面板

/> 勾选此项,该面板将默认展开显示
'technical_specs_data[' . $index . '][content]', 'media_buttons' => true, 'textarea_rows' => 10, 'teeny' => false, 'tinymce' => array( 'toolbar1' => 'bold,italic,underline,strikethrough,|,bullist,numlist,|,link,unlink,|,undo,redo', 'toolbar2' => '', 'plugins' => 'link,lists' ) ); wp_editor($spec['content'], $editor_id, $settings); ?> 可以使用富文本编辑器编辑内容,支持文本格式化、列表和链接

注意:修改后需要点击"更新"按钮保存设置。第一个面板默认展开,其他面板默认折叠。

$spec) { if (!empty($spec['title'])) { $technical_specs_data[] = array( 'title' => sanitize_text_field($spec['title']), 'content' => wp_kses_post($spec['content']), 'expanded' => !empty($spec['expanded']) ); } } update_post_meta($post_id, '_technical_specs_data', $technical_specs_data); } } add_action('save_post', 'save_product_technical_specs'); /** * 产品PDF下载meta box回调函数 */ function product_pdf_downloads_meta_box_callback($post) { wp_nonce_field('save_product_pdf_downloads', 'product_pdf_downloads_nonce'); // 获取显示开关 $show_pdf_downloads = get_post_meta($post->ID, '_show_pdf_downloads', true); if ($show_pdf_downloads === '') { $show_pdf_downloads = '1'; // 默认显示 } // 获取PDF下载数据 $pdf_downloads_data = get_post_meta($post->ID, '_pdf_downloads_data', true); if (empty($pdf_downloads_data)) { $pdf_downloads_data = array( array( 'title' => 'Nenghui\'s innovative 40', 'file_url' => '', 'file_size' => '', 'description' => '' ) ); } ?>
/> 勾选此项将在产品页面显示PDF下载板块

PDF文件列表

$pdf): ?>

PDF文件

仅支持PDF格式文件

$pdf) { if (!empty($pdf['title']) || !empty($pdf['file_url'])) { $pdf_downloads_data[] = array( 'title' => sanitize_text_field($pdf['title']), 'file_url' => esc_url_raw($pdf['file_url']), 'file_size' => sanitize_text_field($pdf['file_size']), 'description' => sanitize_textarea_field($pdf['description']) ); } } update_post_meta($post_id, '_pdf_downloads_data', $pdf_downloads_data); } } add_action('save_post', 'save_product_pdf_downloads'); ?>