'主导航菜单' )); } 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('/| '; 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', '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_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像素 |
此描述将显示在产品页面的标题下方,用于简要介绍产品特点和用途。支持富文本格式。
产品特性板块设置:
勾选此选项将在前端显示产品特性卡片,取消勾选将隐藏整个板块。
| 可以使用 <br> 标签换行 | |
| 可以使用 <br> 标签换行 | |
|
|
|
| 图片的Alt属性,用于无障碍访问和SEO |
注意:修改后需要点击"更新"按钮保存设置。
使用场景板块设置:
勾选此选项将在前端显示使用场景板块,取消勾选将隐藏整个板块。
| 使用场景板块的主标题 | |
| 使用场景的简短描述 | |
|
图片URL或文件名(如:Usage scenario.webp),如果是文件名,文件应放在 /assets/images/ 目录下 |
|
| 使用场景图片下方的详细说明文字 |
注意:修改后需要点击"更新"按钮保存设置。图片文件需要手动上传到主题的 assets/images 目录。
| Cell Type | LFP280Ah |
| PACK | 46.592kWh/IP25S |
| Battery System | 232.96kWh/IP260S |
| Rated Voltage | 832Vdc |
| Voltage Range | 728-936Vdc |
| Pack Ingress Rating | IP65 |
| Rated Power | 100kW |
| Max. Power | 110kW |
| THDi | ≤3% |
| DC Ratio | ≤0.5%lon |
| Nominal Voltage | 400Vac/3P+N+PE |
| Power Factor | -1lagging~1leading |
| Nominal Frequency | 50Hz/60Hz |
技术规格板块设置:
勾选此选项将在前端显示技术规格折叠面板,取消勾选将隐藏整个板块。
技术规格面板:
| /> 勾选此项,该面板将默认展开显示 | |
| '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); ?> 可以使用富文本编辑器编辑内容,支持文本格式化、列表和链接 |
注意:修改后需要点击"更新"按钮保存设置。第一个面板默认展开,其他面板默认折叠。
| /> 勾选此项将在产品页面显示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'); ?>