'nenghui-banner-shortcode', 'class' => '', 'autoplay' => 'true' ), $atts); // 开始输出缓冲 ob_start(); // 设置全局变量供模板使用 global $banner_shortcode_atts; $banner_shortcode_atts = $atts; // 包含banner模板 include get_template_directory() . '/template-parts/blocks/block-banner.php'; // 返回缓冲的内容 return ob_get_clean(); } add_shortcode('nenghui_banner', 'nenghui_banner_shortcode'); // 注册nenghui_futures短代码 function nenghui_futures_shortcode($atts) { // 确保 $atts 是数组 if (!is_array($atts)) { $atts = array(); } // 设置默认参数 $atts = shortcode_atts(array( 'id' => 'nenghui-futures-shortcode', 'class' => '', 'title' => '', 'show_animation' => 'true' ), $atts); // 开始输出缓冲 ob_start(); // 设置全局变量供模板使用 global $futures_shortcode_atts; $futures_shortcode_atts = $atts; // 包含futures模板 include get_template_directory() . '/template-parts/blocks/block-futures.php'; // 返回缓冲的内容 return ob_get_clean(); } add_shortcode('nenghui_futures', 'nenghui_futures_shortcode'); // 注册nenghui_news短代码 function nenghui_news_shortcode($atts) { // 确保 $atts 是数组 if (!is_array($atts)) { $atts = array(); } // 设置默认参数 $atts = shortcode_atts(array( 'id' => 'nenghui-news-shortcode', 'class' => '', 'title' => '', 'category_id' => '', 'posts_count' => '', 'order_by' => '', 'order' => '' ), $atts); // 开始输出缓冲 ob_start(); // 设置全局变量供模板使用 global $news_shortcode_atts; $news_shortcode_atts = $atts; // 包含news模板 include get_template_directory() . '/template-parts/blocks/block-home-news.php'; // 返回缓冲的内容 return ob_get_clean(); } add_shortcode('nenghui_news', 'nenghui_news_shortcode'); function nenghui_epc_shortcode($atts) { if (!is_array($atts)) { $atts = array(); } $atts = shortcode_atts(array( 'id' => 'nenghui-epc', 'class' => '', 'title' => 'EPC Solutions', 'subtitle' => 'Beyond Hardware: Total EPC Solutions from NengHui Design Institute', 'bg_image' => get_template_directory_uri() . '/assets/images/epc-bg.jpg' ), $atts); wp_enqueue_style('epc-style', get_template_directory_uri() . '/assets/css/epc.css', array(), '1.0.0'); ob_start(); global $epc_shortcode_atts; $epc_shortcode_atts = $atts; include get_template_directory() . '/template-parts/blocks/block-epc.php'; return ob_get_clean(); } add_shortcode('nenghui_epc', 'nenghui_epc_shortcode'); // feature-module 模块 function nenghui_epc_banner_shortcode($atts) { if (!is_array($atts)) { $atts = array(); } $atts = shortcode_atts(array( 'id' => 'nenghui-epc-banner', 'class' => '' ), $atts); wp_enqueue_style('feature-module', get_template_directory_uri() . '/assets/css/feature-module.css', array(), '1.0.0'); ob_start(); global $epc_banner_shortcode_atts; $epc_banner_shortcode_atts = $atts; include get_template_directory() . '/template-parts/blocks/block-epc-banner.php'; return ob_get_clean(); } add_shortcode('nenghui_epc_banner', 'nenghui_epc_banner_shortcode'); // 注册black_maps短代码 function nenghui_black_maps_shortcode($atts) { // 确保 $atts 是数组 if (!is_array($atts)) { $atts = array(); } // 设置默认参数 $atts = shortcode_atts(array( 'id' => 'nenghui-black-maps-shortcode', 'class' => '', 'height' => '100vh' ), $atts); // 加载必要的脚本和样式 // 确保jQuery先加载 wp_enqueue_script('jquery'); // 加载ECharts库 - 在header中加载以避免时序问题 wp_enqueue_script('echarts', get_template_directory_uri() . '/assets/js/echarts.min.js', array('jquery'), '5.4.0', false); wp_enqueue_script('echarts-world', get_template_directory_uri() . '/assets/js/world.js', array('echarts'), '1.0.0', false); // 加载地图样式 wp_enqueue_style('black-maps-style', get_template_directory_uri() . '/assets/css/black-maps.css', array(), '1.0.0'); // 开始输出缓冲 ob_start(); // 设置全局变量供模板使用 global $black_maps_shortcode_atts; $black_maps_shortcode_atts = $atts; // 包含地图模板 include get_template_directory() . '/template-parts/blocks/black-maps.php'; // 返回缓冲的内容 return ob_get_clean(); } add_shortcode('black_maps', 'nenghui_black_maps_shortcode'); // 注册nenghui_tabs短代码 function nenghui_tabs_shortcode($atts) { // 确保 $atts 是数组 if (!is_array($atts)) { $atts = array(); } // 设置默认参数 $atts = shortcode_atts(array( 'id' => 'nenghui-tabs-shortcode', 'class' => '', 'tabs_count' => '', // 可以覆盖自定义器设置的选项卡数量 'show_animation' => 'true' ), $atts); // 开始输出缓冲 ob_start(); // 设置全局变量供模板使用 global $tabs_shortcode_atts; $tabs_shortcode_atts = $atts; // 包含tabs模板 include get_template_directory() . '/template-parts/blocks/block-tabs.php'; // 返回缓冲的内容 return ob_get_clean(); } add_shortcode('nenghui_tabs', 'nenghui_tabs_shortcode'); // 注册nenghui_flowchart_tabs短代码 function nenghui_flowchart_tabs_shortcode($atts) { // 确保 $atts 是数组 if (!is_array($atts)) { $atts = array(); } // 设置默认参数 $atts = shortcode_atts(array( 'id' => 'nenghui-flowchart-tabs-shortcode', 'class' => '' ), $atts); // 开始输出缓冲 ob_start(); // 设置全局变量供模板使用 global $flowchart_tabs_shortcode_atts; $flowchart_tabs_shortcode_atts = $atts; // 包含flowchart-tabs模板 include get_template_directory() . '/template-parts/blocks/block-flowchart-tab.php'; // 返回缓冲的内容 return ob_get_clean(); } add_shortcode('nenghui_flowchart_tabs', 'nenghui_flowchart_tabs_shortcode'); // 注册nenghui_banner_title短代码 (重构版本) function nenghui_banner_title_shortcode($atts) { // 确保 $atts 是数组 if (!is_array($atts)) { $atts = array(); } // 设置默认参数 $atts = shortcode_atts(array( 'id' => '', // 如果为空,将自动生成唯一ID 'class' => '', 'title' => '', 'description' => '', 'bg_image' => '', 'height' => '', 'overlay_opacity' => '', 'show_animation' => 'true' ), $atts); // 验证和清理参数 if (!empty($atts['height'])) { // 验证高度格式 if (!preg_match('/^\d+(\.\d+)?(px|vh|%)$/', $atts['height'])) { $atts['height'] = '60vh'; // 默认值 } } if (!empty($atts['overlay_opacity'])) { // 验证透明度值 $opacity = floatval($atts['overlay_opacity']); if ($opacity < 0 || $opacity > 1) { $atts['overlay_opacity'] = '0.4'; // 默认值 } } // 开始输出缓冲 ob_start(); // 设置全局变量供模板使用 global $banner_title_shortcode_atts; $banner_title_shortcode_atts = $atts; // 包含banner-title模板 include get_template_directory() . '/template-parts/blocks/block-banner-title.php'; // 返回缓冲的内容 return ob_get_clean(); } add_shortcode('nenghui_banner_title', 'nenghui_banner_title_shortcode'); // 注册black_maps短代码 function black_maps_shortcode($atts) { // 确保 $atts 是数组 if (!is_array($atts)) { $atts = array(); } // 设置默认参数 $atts = shortcode_atts(array( 'id' => 'echartsMap-' . uniqid(), 'class' => '', 'height' => '100vh', 'show_loading' => 'true' ), $atts); // 引入必要的资源文件 wp_enqueue_script('echarts', get_template_directory_uri() . '/assets/js/echarts.min.js', array('jquery'), '5.4.0', true); wp_enqueue_script('echarts-world', get_template_directory_uri() . '/assets/js/world.js', array('echarts'), '1.0.0', true); wp_enqueue_style('black-maps', get_template_directory_uri() . '/assets/css/black-maps.css', array(), '1.0.0'); // 开始输出缓冲 ob_start(); // 设置全局变量供模板使用 global $black_maps_shortcode_atts; $black_maps_shortcode_atts = $atts; // 包含地图模板 include get_template_directory() . '/template-parts/blocks/black-maps.php'; // 返回缓冲的内容 return ob_get_clean(); } add_shortcode('black_maps', 'black_maps_shortcode'); /** * Banner Title 短代码使用示例: * * 基本用法: * [nenghui_banner_title title="关于我们" description="我们致力于提供最优质的服务"] * * 完整参数: * [nenghui_banner_title * id="custom-banner" * class="custom-class" * title="关于我们" * description="我们致力于提供最优质的服务" * bg_image="https://example.com/image.jpg" * height="70vh" * overlay_opacity="0.6" * show_animation="true"] */ // Banner轮播现在使用原生JavaScript实现,无需额外加载库 // 注册nenghui_about_nav短代码 function nenghui_about_nav_shortcode($atts) { // 确保 $atts 是数组 if (!is_array($atts)) { $atts = array(); } // 设置默认参数 $atts = shortcode_atts(array( 'id' => 'nenghui-about-nav-shortcode', 'class' => '', 'menu_id' => '' ), $atts); // 开始输出缓冲 ob_start(); // 设置全局变量供模板使用 global $about_nav_shortcode_atts; $about_nav_shortcode_atts = $atts; // 包含about-nav模板 include get_template_directory() . '/template-parts/blocks/block-about-nav.php'; // 返回缓冲的内容 return ob_get_clean(); } add_shortcode('nenghui_about_nav', 'nenghui_about_nav_shortcode'); /** * About 导航短代码使用示例: * * 基本用法: * [nenghui_about_nav] * * 自定义参数: * [nenghui_about_nav * id="custom-about-nav" * class="custom-class" * menu_id="123"] */ // 注册nenghui_about_company短代码 function nenghui_about_company_shortcode($atts) { // 确保 $atts 是数组 if (!is_array($atts)) { $atts = array(); } // 设置默认参数 $atts = shortcode_atts(array( 'id' => 'nenghui-about-company-shortcode', 'class' => '', 'show_animation' => 'true' ), $atts); // 开始输出缓冲 ob_start(); // 设置全局变量供模板使用 global $about_company_shortcode_atts; $about_company_shortcode_atts = $atts; // 包含about-company模板 include get_template_directory() . '/template-parts/blocks/block-about-company.php'; // 返回缓冲的内容 return ob_get_clean(); } add_shortcode('nenghui_about_company', 'nenghui_about_company_shortcode'); /** * About Company 短代码使用示例: * * 基本用法: * [nenghui_about_company] * * 自定义参数: * [nenghui_about_company * id="custom-about-company" * class="custom-class" * show_animation="true"] */ // 注册nenghui_development_history短代码 function nenghui_development_history_shortcode($atts) { // 确保 $atts 是数组 if (!is_array($atts)) { $atts = array(); } // 设置默认参数 $atts = shortcode_atts(array( 'id' => 'nenghui-development-history-shortcode', 'class' => '', 'show_animation' => 'true' ), $atts); // 开始输出缓冲 ob_start(); // 设置全局变量供模板使用 global $development_history_shortcode_atts; $development_history_shortcode_atts = $atts; // 包含development-history模板 include get_template_directory() . '/template-parts/blocks/block-development-history.php'; // 返回缓冲的内容 return ob_get_clean(); } add_shortcode('nenghui_development_history', 'nenghui_development_history_shortcode'); /** * Development History 短代码使用示例: * * 基本用法: * [nenghui_development_history] * * 自定义参数: * [nenghui_development_history * id="custom-development-history" * class="custom-class" * show_animation="true"] */ // 注册nenghui_certification_gallery短代码 function nenghui_certification_gallery_shortcode($atts) { // 确保 $atts 是数组 if (!is_array($atts)) { $atts = array(); } // 设置默认参数 $atts = shortcode_atts(array( 'id' => 'nenghui-certification-gallery-shortcode', 'class' => '', 'images' => '', // 图片ID列表,逗号分隔 'columns' => '', // 每行显示列数 'lightbox' => '', // 是否启用灯箱效果 'animation' => '' // 是否启用动画效果 ), $atts); // 验证和清理参数 if (!empty($atts['columns'])) { $columns = intval($atts['columns']); if ($columns < 1 || $columns > 6) { $atts['columns'] = '5'; // 默认值 } } if (!empty($atts['lightbox'])) { $atts['lightbox'] = filter_var($atts['lightbox'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); if ($atts['lightbox'] === null) { $atts['lightbox'] = 'true'; // 默认值 } else { $atts['lightbox'] = $atts['lightbox'] ? 'true' : 'false'; } } if (!empty($atts['animation'])) { $atts['animation'] = filter_var($atts['animation'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); if ($atts['animation'] === null) { $atts['animation'] = 'true'; // 默认值 } else { $atts['animation'] = $atts['animation'] ? 'true' : 'false'; } } // 开始输出缓冲 ob_start(); // 设置全局变量供模板使用 global $certification_shortcode_atts; $certification_shortcode_atts = $atts; // 包含certification模板 include get_template_directory() . '/template-parts/blocks/block-certification.php'; // 返回缓冲的内容 return ob_get_clean(); } add_shortcode('nenghui_certification_gallery', 'nenghui_certification_gallery_shortcode'); /** * Certification Gallery 短代码使用示例: * * 基本用法: * [nenghui_certification_gallery] * * 常用参数: * [nenghui_certification_gallery columns="4" lightbox="true"] */ // 注册nenghui_technical_service短代码 function nenghui_technical_service_shortcode($atts) { // 确保 $atts 是数组 if (!is_array($atts)) { $atts = array(); } // 设置默认参数 $atts = shortcode_atts(array( 'id' => 'nenghui-technical-service-shortcode', 'class' => '', 'title' => 'Reliable Technical Service', 'subtitle' => 'Enhance Experience for Customers', 'show_animation' => 'true' ), $atts); // 开始输出缓冲 ob_start(); // 设置全局变量供模板使用 global $technical_service_shortcode_atts; $technical_service_shortcode_atts = $atts; // 包含technical-service模板 include get_template_directory() . '/template-parts/blocks/block-technical-service.php'; // 返回缓冲的内容 return ob_get_clean(); } add_shortcode('nenghui_technical_service', 'nenghui_technical_service_shortcode'); /** * Technical Service 短代码使用示例: * * 基本用法: * [nenghui_technical_service] * * 自定义参数: * [nenghui_technical_service * id="custom-technical-service" * class="custom-class" * title="可靠的技术服务" * subtitle="提升客户体验" * show_animation="true"] */ // 注册nenghui_video短代码 function nenghui_video_shortcode($atts) { // 确保 $atts 是数组 if (!is_array($atts)) { $atts = array(); } // 只处理实际传递的参数,空值将在模板中使用自定义器默认值 $processed_atts = array(); // 处理传递的参数 if (isset($atts['id']) && !empty($atts['id'])) { $processed_atts['id'] = $atts['id']; } if (isset($atts['class']) && !empty($atts['class'])) { $processed_atts['class'] = $atts['class']; } if (isset($atts['video_url']) && !empty($atts['video_url'])) { $processed_atts['video_url'] = $atts['video_url']; } if (isset($atts['cover_image']) && !empty($atts['cover_image'])) { $processed_atts['cover_image'] = $atts['cover_image']; } if (isset($atts['title']) && !empty($atts['title'])) { $processed_atts['title'] = $atts['title']; } if (isset($atts['description']) && !empty($atts['description'])) { $processed_atts['description'] = $atts['description']; } if (isset($atts['play_button_text']) && !empty($atts['play_button_text'])) { $processed_atts['play_button_text'] = $atts['play_button_text']; } if (isset($atts['height']) && !empty($atts['height'])) { $processed_atts['height'] = $atts['height']; } if (isset($atts['show_overlay']) && $atts['show_overlay'] !== '') { $processed_atts['show_overlay'] = $atts['show_overlay']; } if (isset($atts['overlay_opacity']) && $atts['overlay_opacity'] !== '') { $processed_atts['overlay_opacity'] = $atts['overlay_opacity']; } if (isset($atts['autoplay']) && $atts['autoplay'] !== '') { $processed_atts['autoplay'] = $atts['autoplay']; } if (isset($atts['muted']) && $atts['muted'] !== '') { $processed_atts['muted'] = $atts['muted']; } if (isset($atts['controls']) && $atts['controls'] !== '') { $processed_atts['controls'] = $atts['controls']; } $atts = $processed_atts; // 开始输出缓冲 ob_start(); // 设置全局变量供模板使用 global $video_shortcode_atts; $video_shortcode_atts = $atts; // 包含video模板 include get_template_directory() . '/template-parts/blocks/block-video.php'; // 返回缓冲的内容 return ob_get_clean(); } add_shortcode('nenghui_video', 'nenghui_video_shortcode'); /** * Video 短代码使用示例: * * 基本用法: * [nenghui_video video_url="https://example.com/video.mp4"] * * 完整参数: * [nenghui_video * id="custom-video" * class="custom-class" * 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"] * * 常用参数: * [nenghui_video video_url="video.mp4" title="企业介绍" height="60vh"] */ // 注册nenghui_contact_form短代码 function nenghui_contact_form_shortcode($atts) { // 确保 $atts 是数组 if (!is_array($atts)) { $atts = array(); } // 设置默认参数 $atts = shortcode_atts(array( 'id' => 'nenghui-contact-form-shortcode', 'class' => '', 'form_id' => '1', 'show_animation' => 'true' ), $atts); // 开始输出缓冲 ob_start(); // 设置全局变量供模板使用 global $contact_form_shortcode_atts; $contact_form_shortcode_atts = $atts; // 包含contact-form模板 include get_template_directory() . '/template-parts/blocks/block-contact-form.php'; // 返回缓冲的内容 return ob_get_clean(); } add_shortcode('nenghui_contact_form', 'nenghui_contact_form_shortcode'); /** * Contact Form 短代码使用示例: * * 基本用法: * [nenghui_contact_form] * * 自定义参数: * [nenghui_contact_form * id="custom-contact-form" * class="custom-class" * form_id="2" * show_animation="true"] */ // 注册black_about_company_banner短代码 function black_about_company_banner_shortcode($atts) { // 确保 $atts 是数组 if (!is_array($atts)) { $atts = array(); } // 设置默认参数 $atts = shortcode_atts(array( 'id' => 'black-about-company-banner-shortcode', 'class' => '', 'show_animation' => 'true' ), $atts); // 开始输出缓冲 ob_start(); // 设置全局变量供模板使用 global $black_about_company_banner_shortcode_atts; $black_about_company_banner_shortcode_atts = $atts; // 包含black-about-company-banner模板 include get_template_directory() . '/template-parts/blocks/black-about-company-banner.php'; // 返回缓冲的内容 return ob_get_clean(); } add_shortcode('black_about_company_banner', 'black_about_company_banner_shortcode'); /** * Black About Company Banner 短代码使用示例: * * 基本用法: * [black_about_company_banner] * * 自定义参数: * [black_about_company_banner * id="custom-black-about-company-banner" * class="custom-class" * show_animation="true"] */ // 在小工具中也支持短代码 add_filter('widget_text', 'do_shortcode'); // 注册nenghui_download_center短代码 function nenghui_download_center_shortcode($atts) { // 确保 $atts 是数组 if (!is_array($atts)) { $atts = array(); } // 设置默认参数 $atts = shortcode_atts(array( 'id' => 'nenghui-download-center-shortcode', 'class' => '', 'title' => 'Download Center', 'show_all_tab' => 'true', 'posts_per_category' => '-1', 'enable_pagination' => 'false', 'posts_per_page' => '6', 'order_by' => 'date', 'order' => 'DESC' ), $atts); // 验证和清理参数 if (!empty($atts['posts_per_category'])) { $posts_count = intval($atts['posts_per_category']); if ($posts_count < -1) { $atts['posts_per_category'] = '-1'; // 默认显示所有 } } if (!empty($atts['show_all_tab'])) { $atts['show_all_tab'] = filter_var($atts['show_all_tab'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); if ($atts['show_all_tab'] === null) { $atts['show_all_tab'] = 'true'; // 默认值 } else { $atts['show_all_tab'] = $atts['show_all_tab'] ? 'true' : 'false'; } } if (!empty($atts['enable_pagination'])) { $atts['enable_pagination'] = filter_var($atts['enable_pagination'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); if ($atts['enable_pagination'] === null) { $atts['enable_pagination'] = 'false'; // 默认值 } else { $atts['enable_pagination'] = $atts['enable_pagination'] ? 'true' : 'false'; } } if (!empty($atts['posts_per_page'])) { $posts_per_page = intval($atts['posts_per_page']); if ($posts_per_page < 1) { $atts['posts_per_page'] = '6'; // 默认值 } } if (!empty($atts['order_by'])) { $valid_orderby = array('date', 'modified', 'title', 'menu_order', 'rand'); if (!in_array($atts['order_by'], $valid_orderby)) { $atts['order_by'] = 'date'; // 默认值 } } if (!empty($atts['order'])) { $atts['order'] = strtoupper($atts['order']); if (!in_array($atts['order'], array('ASC', 'DESC'))) { $atts['order'] = 'DESC'; // 默认值 } } // 开始输出缓冲 ob_start(); // 设置全局变量供模板使用 global $download_center_shortcode_atts; $download_center_shortcode_atts = $atts; // 包含download-center模板 include get_template_directory() . '/template-parts/blocks/block-download-center.php'; // 返回缓冲的内容 return ob_get_clean(); } add_shortcode('nenghui_download_center', 'nenghui_download_center_shortcode'); /** * Download Center 短代码使用示例: * * 基本用法: * [nenghui_download_center] * * 自定义标题: * [nenghui_download_center title="资源下载"] * * 不显示"全部"选项卡: * [nenghui_download_center show_all_tab="false"] * * 限制每个分类显示的文章数量: * [nenghui_download_center posts_per_category="6"] * * 启用分页功能: * [nenghui_download_center enable_pagination="true" posts_per_page="6"] * * 完整参数: * [nenghui_download_center * id="custom-download-center" * class="custom-class" * title="资源下载中心" * show_all_tab="true" * posts_per_category="8" * enable_pagination="true" * posts_per_page="6" * order_by="title" * order="ASC"] * * 参数说明: * - id: 容器ID,默认为 'nenghui-download-center-shortcode' * - class: 额外CSS类 * - title: 区块标题,默认为 'Download Center' * - show_all_tab: 是否显示"全部"选项卡(true/false),默认为 true * - posts_per_category: 每个分类显示的文章数量,-1表示显示所有,默认为 -1(仅在未启用分页时使用) * - enable_pagination: 是否启用分页功能(true/false),默认为 false * - posts_per_page: 每页显示的文章数量,默认为 6(仅在启用分页时使用) * - order_by: 排序字段(date/modified/title/menu_order/rand),默认为 date * - order: 排序方向(ASC/DESC),默认为 DESC * * 注意事项: * - 下载文件通过自定义字段 '_download_url' 设置 * - 如果没有设置下载链接,将使用特色图像作为下载文件 * - 如果没有特色图像,将显示默认的PDF图像 * - 分类通过 'download_category' 分类法管理 * - 支持文件大小和文件类型的显示 * - 自动创建 'Company profile' 和 'Product series' 两个默认分类 * - 启用分页后,每个分类都有独立的分页导航 * - 分页功能支持Tab选项卡切换,每个选项卡显示对应的分页组件 * - 分页参数优先级:enable_pagination=true时使用posts_per_page,否则使用posts_per_category * * 后台使用说明: * 1. 在WordPress后台可以看到"下载中心"菜单 * 2. 点击"添加新下载"创建下载项目 * 3. 设置标题、内容摘要和特色图像 * 4. 在"下载文件信息"元框中设置下载链接、文件大小和文件类型 * 5. 选择对应的下载分类(Company profile 或 Product series) * 6. 发布后即可在前台显示 */ // 注册nenghui_news_grid短代码 - 3行4列卡片布局 function nenghui_news_grid_shortcode($atts) { // 确保 $atts 是数组 if (!is_array($atts)) { $atts = array(); } // 设置默认参数 $atts = shortcode_atts(array( 'id' => 'nenghui-news-grid-shortcode', 'class' => '', 'title' => '', 'category_id' => '', 'posts_count' => '12', 'posts_per_page' => '', 'enable_pagination' => '', 'order_by' => 'date', 'order' => 'DESC' ), $atts); // 开始输出缓冲 ob_start(); // 设置全局变量供模板使用 global $news_shortcode_atts; $news_shortcode_atts = $atts; // 包含3行4列卡片布局模板 include get_template_directory() . '/template-parts/blocks/block-news.php'; // 返回缓冲的内容 return ob_get_clean(); } add_shortcode('nenghui_news_grid', 'nenghui_news_grid_shortcode'); /** * News Grid 短代码使用示例: * * 基本用法: * [nenghui_news_grid] * * 在分类页面使用(自动显示当前分类文章): * [nenghui_news_grid] * * 指定分类使用: * [nenghui_news_grid category_id="5"] * * 在分类页面显示所有文章(覆盖当前分类): * [nenghui_news_grid category_id=""] * * 启用分页功能: * [nenghui_news_grid enable_pagination="true" posts_per_page="6"] * * 完整参数: * [nenghui_news_grid * id="custom-news-grid" * class="custom-class" * title="最新资讯" * category_id="5" * posts_count="12" * posts_per_page="6" * enable_pagination="true" * order_by="date" * order="DESC"] * * 参数说明: * - id: 容器ID * - class: 额外CSS类 * - title: 区块标题 * - category_id: 分类ID,支持以下情况: * * 不设置:在分类页面自动使用当前分类,其他页面显示所有文章 * * 设置数字:显示指定分类的文章 * * 设置多个数字(逗号分隔):显示多个分类的文章(如 "5,6,7") * * 设置空值:强制显示所有文章(即使在分类页面) * - posts_count: 文章数量,默认为12(3行4列),仅在未启用分页时使用 * - posts_per_page: 每页显示文章数量,仅在启用分页时使用 * - enable_pagination: 是否启用分页(true/false) * - order_by: 排序字段(date/modified/title/rand) * - order: 排序方向(ASC/DESC) * * 分类ID优先级:短代码参数 > 当前分类页面 > 自定义器设置 * * 分页功能说明: * - 启用分页后,将显示数字分页组件 * - 分页时网格布局会自动调整为响应式布局 * - 可在自定义器中设置默认的分页参数 */ // 注册nenghui_contact_map短代码 function nenghui_contact_map_shortcode($atts) { // 确保 $atts 是数组 if (!is_array($atts)) { $atts = array(); } // 只处理实际传递的参数,空值将在模板中使用自定义器默认值 $processed_atts = array(); // 处理传递的参数 if (isset($atts['id']) && !empty($atts['id'])) { $processed_atts['id'] = $atts['id']; } if (isset($atts['class']) && !empty($atts['class'])) { $processed_atts['class'] = $atts['class']; } if (isset($atts['title']) && !empty($atts['title'])) { $processed_atts['title'] = $atts['title']; } if (isset($atts['office_address']) && !empty($atts['office_address'])) { $processed_atts['office_address'] = $atts['office_address']; } if (isset($atts['phone']) && !empty($atts['phone'])) { $processed_atts['phone'] = $atts['phone']; } if (isset($atts['email']) && !empty($atts['email'])) { $processed_atts['email'] = $atts['email']; } if (isset($atts['map_embed_code']) && !empty($atts['map_embed_code'])) { $processed_atts['map_embed_code'] = $atts['map_embed_code']; } if (isset($atts['map_height']) && !empty($atts['map_height'])) { // 验证地图高度格式 if (preg_match('/^\d+(\.\d+)?(px|vh|%)$/', $atts['map_height'])) { $processed_atts['map_height'] = $atts['map_height']; } } $atts = $processed_atts; // 开始输出缓冲 ob_start(); // 设置全局变量供模板使用 global $contact_map_shortcode_atts; $contact_map_shortcode_atts = $atts; // 包含contact-map模板 include get_template_directory() . '/template-parts/blocks/block-contact-map.php'; // 返回缓冲的内容 return ob_get_clean(); } add_shortcode('nenghui_contact_map', 'nenghui_contact_map_shortcode'); /** * Contact Map 短代码使用示例: * * 基本用法: * [nenghui_contact_map] * * 自定义标题: * [nenghui_contact_map title="联系我们"] * * 自定义联系信息: * [nenghui_contact_map * title="联系我们" * office_address="上海市长宁区同协路288号" * phone="+86-21-50896255" * email="info@nhet.energy"] * * 完整参数: * [nenghui_contact_map * id="custom-contact-map" * class="custom-class" * title="联系我们" * office_address="上海市长宁区同协路288号" * phone="+86-21-50896255" * email="info@nhet.energy" * map_embed_code="" * map_height="500px"] * * 参数说明: * - id: 容器ID,默认为 'nenghui-contact-map' * - class: 额外CSS类 * - title: 区块标题,默认使用自定义器设置 * - office_address: 办公地址,默认使用自定义器设置 * - phone: 电话/手机,默认使用自定义器设置 * - email: 邮箱地址,默认使用自定义器设置 * - map_embed_code: 地图嵌入代码,默认使用自定义器设置或Google-maps.txt文件 * - map_height: 地图高度,支持px、vh、%单位,默认400px * * 注意事项: * - 如果未设置地图嵌入代码,将自动读取 /docs/Google-maps.txt 文件中的默认地图代码 * - 样式设置(背景色、文字色、图标色)只能通过自定义器设置,短代码不支持覆盖 * - 地图高度必须包含有效的CSS单位(px、vh、%),否则将使用默认值400px * - 联系信息支持换行,在office_address中使用\n表示换行 */ // 注册nenghui_overseas_services短代码 function nenghui_overseas_services_shortcode($atts) { // 确保 $atts 是数组 if (!is_array($atts)) { $atts = array(); } // 设置默认参数 $atts = shortcode_atts(array( 'id' => 'nenghui-overseas-services', 'class' => '', 'title' => 'Overseas Services', 'description' => 'Our service team delivers diversified solutions tailored to client requirements, including product training, installation guidance, and after-sales support. NengHui ESS\'s specialized expert team provides comprehensive on-site services covering Uninterruptible Power Supplies (UPS), modular data centers, solar energy, and Energy Storage Systems (ESS), ensuring your power systems operate at peak performance.', 'height' => '400px', 'show_animation' => 'true' ), $atts); // 开始输出缓冲 ob_start(); // 设置全局变量供模板使用 global $overseas_services_shortcode_atts; $overseas_services_shortcode_atts = $atts; // 包含overseas-services模板 include get_template_directory() . '/template-parts/blocks/block-overseas-services.php'; // 返回缓冲的内容 return ob_get_clean(); } add_shortcode('nenghui_overseas_services', 'nenghui_overseas_services_shortcode'); /** * Overseas Services 短代码使用示例: * * 基本用法: * [nenghui_overseas_services] * * 自定义标题和描述: * [nenghui_overseas_services title="海外服务" description="我们的服务团队..."] * * 完整参数: * [nenghui_overseas_services * id="custom-overseas-services" * class="custom-class" * title="Overseas Services" * description="Our service team delivers..." * height="500px" * show_animation="true"] * * 参数说明: * - id: 容器ID,默认为 'nenghui-overseas-services' * - class: 额外CSS类 * - title: 区块标题,默认为 'Overseas Services' * - description: 服务描述文本 * - height: 区块高度,支持px、vh、%等单位,默认为 '400px' * - show_animation: 是否显示动画效果,默认为 'true' * * 注意事项: * - 背景图片固定使用 Overseas-Services-bg.webp * - 父容器宽度100%,内容容器宽度80% * - 支持响应式布局和动画效果 */ // 注册nenghui_faq短代码 function nenghui_faq_shortcode($atts) { // 确保 $atts 是数组 if (!is_array($atts)) { $atts = array(); } // 设置默认参数 $atts = shortcode_atts(array( 'id' => 'nenghui-faq', 'class' => '', 'title' => 'Frequently Asked Questions', 'posts_per_page' => '-1', // 显示数量,-1表示显示所有 'order_by' => 'menu_order', // 排序字段 'order' => 'ASC', // 排序方向 'show_animation' => 'true' ), $atts); // 验证和清理参数 if (!empty($atts['posts_per_page'])) { $posts_count = intval($atts['posts_per_page']); if ($posts_count < -1) { $atts['posts_per_page'] = '-1'; // 默认显示所有 } } if (!empty($atts['order_by'])) { $valid_orderby = array('date', 'modified', 'title', 'menu_order', 'rand'); if (!in_array($atts['order_by'], $valid_orderby)) { $atts['order_by'] = 'menu_order'; // 默认值 } } if (!empty($atts['order'])) { $atts['order'] = strtoupper($atts['order']); if (!in_array($atts['order'], array('ASC', 'DESC'))) { $atts['order'] = 'ASC'; // 默认值 } } // 开始输出缓冲 ob_start(); // 设置全局变量供模板使用 global $faq_shortcode_atts; $faq_shortcode_atts = $atts; // 包含faq模板 include get_template_directory() . '/template-parts/blocks/block-faq.php'; // 返回缓冲的内容 return ob_get_clean(); } add_shortcode('nenghui_faq', 'nenghui_faq_shortcode'); /** * FAQ 短代码使用示例: * * 基本用法: * [nenghui_faq] * * 限制显示数量: * [nenghui_faq posts_per_page="5"] * * 完整参数: * [nenghui_faq * id="custom-faq" * class="custom-class" * title="常见问题" * posts_per_page="10" * order_by="date" * order="DESC" * show_animation="true"] * * 参数说明: * - id: 容器ID,默认为 'nenghui-faq' * - class: 额外CSS类 * - title: 区块标题,默认为 'Frequently Asked Questions' * - posts_per_page: 显示数量,-1表示显示所有,默认为 -1 * - order_by: 排序字段(date/modified/title/menu_order/rand),默认为 menu_order * - order: 排序方向(ASC/DESC),默认为 ASC * - show_animation: 是否显示动画效果,默认为 'true' * * 注意事项: * - FAQ内容通过后台"FAQ管理"菜单添加和管理 * - 支持手风琴折叠效果 * - 问题标题背景使用 faq-title-bg.webp 图片 * - 支持排序功能 * - 答案内容支持富文本编辑 * - 可通过menu_order字段自定义排序 * * 后台使用说明: * 1. 在WordPress后台可以看到"FAQ管理"菜单 * 2. 点击"添加新FAQ"创建FAQ项目 * 3. 设置问题标题(title)和答案内容(content) * 4. 设置排序值(页面属性中的排序字段) * 5. 发布后即可在前台显示 */ // 注册nenghui_cases短代码 function nenghui_cases_shortcode($atts) { // 确保 $atts 是数组 if (!is_array($atts)) { $atts = array(); } // 设置默认参数 $atts = shortcode_atts(array( 'id' => 'nenghui-cases', 'class' => '', 'title' => 'Cases', 'posts_per_page' => '6', // 每页显示数量 'columns' => '3', // 每行显示列数 'show_pagination' => 'true', // 是否显示分页 'show_tabs' => 'true', // 是否显示选项卡 'default_category' => 'power-station', // 默认显示的分类 'show_animation' => 'true' ), $atts); // 验证和清理参数 if (!empty($atts['posts_per_page'])) { $posts_count = intval($atts['posts_per_page']); if ($posts_count < 1) { $atts['posts_per_page'] = '6'; // 默认值 } } if (!empty($atts['columns'])) { $columns = intval($atts['columns']); if ($columns < 1 || $columns > 4) { $atts['columns'] = '3'; // 默认值 } } // 开始输出缓冲 ob_start(); // 设置全局变量供模板使用 global $cases_shortcode_atts; $cases_shortcode_atts = $atts; // 包含cases模板 include get_template_directory() . '/template-parts/blocks/block-cases.php'; // 返回缓冲的内容 return ob_get_clean(); } add_shortcode('nenghui_cases', 'nenghui_cases_shortcode'); /** * Cases 短代码使用示例: * * 基本用法: * [nenghui_cases] * * 自定义参数: * [nenghui_cases posts_per_page="9" columns="3"] * * 完整参数: * [nenghui_cases * id="custom-cases" * class="custom-class" * title="项目案例" * posts_per_page="6" * columns="3" * show_pagination="true" * show_tabs="true" * default_category="power-station" * show_animation="true"] * * 参数说明: * - id: 容器ID,默认为 'nenghui-cases' * - class: 额外CSS类 * - title: 区块标题,默认为 'Cases' * - posts_per_page: 每页显示数量,默认为 6 * - columns: 每行显示列数(1-4),默认为 3 * - show_pagination: 是否显示分页,默认为 'true' * - show_tabs: 是否显示选项卡,默认为 'true' * - default_category: 默认显示的分类slug,默认为 'power-station' * - show_animation: 是否显示动画效果,默认为 'true' * * 注意事项: * - 案例内容通过后台"案例展示"菜单添加和管理 * - 支持三个默认分类:Power Station、PV Project、Agricultural Solar * - 每个案例需要设置特色图像、标题、摘要 * - 案例详情页使用 cases-content.php 模板 * - 支持响应式布局,自动适应不同屏幕宽度 * - 使用CSS Grid布局,支持auto-fill和auto-fit * * 后台使用说明: * 1. 在WordPress后台可以看到"案例展示"菜单 * 2. 点击"添加新案例"创建案例项目 * 3. 设置案例标题、内容、摘要和特色图像 * 4. 选择案例分类(Power Station/PV Project/Agricultural Solar) * 5. 发布后即可在前台显示 * 6. 案例详情页会自动使用 cases-content.php 模板 */ // AJAX处理函数:加载案例数据 function load_cases_ajax() { // 验证nonce if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'load_cases_nonce')) { wp_die('Security check failed'); } $category = sanitize_text_field($_POST['category']); $page = intval($_POST['page']); $posts_per_page = intval($_POST['posts_per_page']); $columns = intval($_POST['columns']); $show_pagination = $_POST['show_pagination'] === 'true'; // 构建查询参数 $args = array( 'post_type' => 'cases', 'post_status' => 'publish', 'posts_per_page' => $posts_per_page, 'paged' => $page, 'orderby' => 'date', 'order' => 'DESC' ); // 如果指定了分类且不是'all' if ($category !== 'all') { $args['tax_query'] = array( array( 'taxonomy' => 'case_category', 'field' => 'slug', 'terms' => $category ) ); } $query = new WP_Query($args); if ($query->have_posts()) { ob_start(); ?>
max_num_pages > 1) { ob_start(); ?>暂无案例数据