您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

360 行
13 KiB

  1. <?php
  2. /**
  3. * Template Name: Sections
  4. *
  5. * Page template with normal content area including selected sections after the post.
  6. * No Sidebars
  7. *
  8. */
  9. get_header() ?>
  10. <?php the_post() ?>
  11. <?php
  12. $site_host = parse_url(get_site_url(), PHP_URL_HOST);
  13. $post_id = get_the_ID();
  14. $post_type = get_post_type($post_id);
  15. $post_meta = sandbox_get_post_meta($post_id);
  16. if ( !isset($post_meta['_hide']) || !filter_var($post_meta['_hide'], FILTER_VALIDATE_BOOLEAN) ) {
  17. $post_taxonomies = sandbox_get_the_taxonomies_and_terms($post_id);
  18. $content = '';
  19. $post_class = 'no-download';
  20. $content_meta_args = array();
  21. // post style attribute
  22. $post_style = '';
  23. $color_hex_pattern = '/#([a-f0-9]{3}){1,2}\b/i';
  24. $has_background_color = isset($post_meta['_background-color']) && preg_match($color_hex_pattern, $post_meta['_background-color']);
  25. $has_post_style = $has_background_color;
  26. if ( $has_post_style ) {
  27. $post_style = ' style="';
  28. }
  29. // background-color
  30. if ( $has_background_color ) {
  31. $post_style .= 'background-color:' . $post_meta['_background-color'] . ';';
  32. $post_class .= ' has-background-color';
  33. }
  34. if ( $has_post_style ) {
  35. $post_style .= '"';
  36. }
  37. // Dark or light color scheme
  38. if ( isset($post_meta['_color-scheme']) ) {
  39. $post_class .= ' color-scheme-' . $post_meta['_color-scheme'];
  40. }
  41. // Show image before or after the content
  42. if ( isset($post_meta['_image-position']) ) {
  43. $post_class .= ' image-position-' . $post_meta['_image-position'];
  44. }
  45. // Show image with shadow or not
  46. if ( isset($post_meta['_image-shadow']) ) {
  47. $post_class .= ' thumbnail-' . $post_meta['_image-shadow'];
  48. }
  49. // Post type "page" fields
  50. $subheadline = isset($post_meta['_subheadline']) ? apply_filters('the_content', $post_meta['_subheadline']) : '';
  51. // Post type "page"
  52. if ( $post_type === 'page' ) {
  53. $content_meta_args = false;
  54. }
  55. // Post type "service"
  56. if ( $post_type === 'service' ) {
  57. $content_meta_args = false;
  58. }
  59. // Post type "product" fields
  60. $produkt_pdf = isset($post_meta['_pdf-download']) ? $post_meta['_pdf-download'] : '';
  61. $produkt_url = isset($post_meta['_product-url']) ? $post_meta['_product-url'] : '';
  62. if ( !empty($produkt_pdf) ) {
  63. $produkt_url = wp_get_attachment_url($produkt_pdf);
  64. }
  65. if ( $post_type === 'produkt' ) {
  66. $content_meta_args = false;
  67. }
  68. // Download button
  69. $download_url = !empty($produkt_pdf) ? $produkt_pdf : '';
  70. $download_target = '';
  71. if ( !empty($download_url) ) {
  72. if ( parse_url($download_url, PHP_URL_HOST) !== $site_host ) {
  73. $download_target = ' target="_blank" rel="noopener"';
  74. }
  75. $post_class = 'has-download';
  76. }
  77. if ( empty($content) ) {
  78. $content = apply_filters('the_content', get_the_content());
  79. }
  80. ?>
  81. <?php if ( $has_background_color ) { ?>
  82. <style type="text/css">
  83. #main .sections-header .title::before { border-color:<?php echo $post_meta['_background-color']; ?>; }
  84. </style>
  85. <?php } ?>
  86. <article id="content" <?php post_class($post_class) ?><?php echo $post_style; ?>>
  87. <?php if ( has_post_thumbnail() ) { ?>
  88. <span class="post-thumbnail"><?php the_post_thumbnail('full'); ?></span>
  89. <?php } ?>
  90. <div class="content inner">
  91. <header class="content-header">
  92. <div class="inner">
  93. <?php if ( !empty($subheadline) ) { ?>
  94. <div class="subheadline content">
  95. <?php echo $subheadline; ?>
  96. </div>
  97. <?php } ?>
  98. <h1 class="title"><?php the_title(); ?></h1>
  99. <?php if ( !empty($download_url) ) { ?>
  100. <a class="download" href="<?php echo $download_url; ?>"<?php echo $download_target; ?>><?php echo __('Download', 'sandbox'); ?></a>
  101. <?php } ?></h1>
  102. <?php if ( has_excerpt() ) { ?>
  103. <div class="intro">
  104. <?php the_excerpt(); ?>
  105. </div>
  106. <?php } ?>
  107. <?php if ( $meta = sandbox_get_meta_data($content_meta_args) ) { ?>
  108. <ul class="meta">
  109. <?php echo $meta; ?>
  110. </ul>
  111. <?php } ?>
  112. </div>
  113. </header>
  114. <?php if ( !empty($content) ) { ?>
  115. <?php echo $content; ?>
  116. <?php } ?>
  117. </div>
  118. <?php if ( isset($post_taxonomies['benefit']) && !empty($post_taxonomies['benefit']) ) { ?>
  119. <div class="<?php echo esc_attr(sanitize_html_class(strtolower($post_taxonomies['benefit']['label']))); ?>">
  120. <?php foreach ( $post_taxonomies['benefit']['terms'] as $benefit ) { ?>
  121. <?php
  122. $benefit_meta = get_term_meta($benefit['term_id']);
  123. $benefit_thumbnail = $benefit_meta['_benefit-image'] !== false ? wp_get_attachment_image($benefit_meta['_benefit-image'][0], 'full') : false;
  124. $benefit_icon_name = $benefit_meta['_benefit-icon'] !== false ? $benefit_meta['_benefit-icon'][0] : false;
  125. ?>
  126. <div class="term-<?php echo esc_attr($post_taxonomies['benefit']['slug']); ?>">
  127. <div class="term-thumbnail content">
  128. <?php if ( $benefit_thumbnail ) { ?>
  129. <?php echo $benefit_thumbnail; ?>
  130. <?php } else if ( $benefit_icon_name ) { ?>
  131. <span class="material-icon"><?php echo $benefit_icon_name; ?></span>
  132. <?php } ?>
  133. </div>
  134. <div class="inner content">
  135. <?php echo apply_filters('the_content', $benefit['description']); ?>
  136. </div>
  137. </div>
  138. <?php } ?>
  139. </div>
  140. <?php } ?>
  141. <?php // If comments are open or we have at least one comment, load up the comment template. ?>
  142. <?php if ( comments_open() || get_comments_number() ) { ?>
  143. <?php comments_template('/comments.php'); ?>
  144. <?php } ?>
  145. </article><!-- .post -->
  146. <?php
  147. /**
  148. * Sectiongroups
  149. */
  150. if ( isset($post_taxonomies['sectiongroup']) ) {
  151. $sections_terms = $post_taxonomies['sectiongroup']['terms'];
  152. ?>
  153. <?php foreach ( $sections_terms as $sections_term ) { ?>
  154. <?php
  155. /**
  156. * Sections
  157. */
  158. $sections_options = array(
  159. 'post_type' => 'section',
  160. 'tax_query' => array(array(
  161. 'taxonomy' => $post_taxonomies['sectiongroup']['slug'],
  162. 'field' => 'slug',
  163. 'terms' => $sections_term['slug'],
  164. )),
  165. 'orderby' => 'menu_order',
  166. 'order' => 'ASC',
  167. );
  168. $post_class .= ' sections-header';
  169. $sections_query = new WP_Query($sections_options);
  170. ?>
  171. <?php if ( $sections_query->have_posts() ) { ?>
  172. <?php if ( $post_meta['_sectiongroup-title-display'] === 'show' ) { ?>
  173. <header class="<?php echo $post_class; ?>"<?php echo $post_style; ?>>
  174. <div class="inner">
  175. <h2 class="title"><span><?php echo $sections_term['label']; ?></span></h2>
  176. </div>
  177. </header>
  178. <?php } ?>
  179. <?php while ( $sections_query->have_posts() ) {
  180. $sections_query->the_post(); ?>
  181. <?php
  182. $post_id = get_the_ID();
  183. $post_type = get_post_type($post_id);
  184. $post_meta = sandbox_get_post_meta($post_id);
  185. if ( !isset($post_meta['_hide']) || !filter_var($post_meta['_hide'], FILTER_VALIDATE_BOOLEAN) ) {
  186. $post_taxonomies = sandbox_get_the_taxonomies_and_terms($post_id);
  187. $content = '';
  188. $post_class = 'no-download';
  189. $content_meta_args = array();
  190. // post style attribute
  191. $post_style = '';
  192. $color_hex_pattern = '/#([a-f0-9]{3}){1,2}\b/i';
  193. $has_background_color = isset($post_meta['_background-color']) && preg_match($color_hex_pattern, $post_meta['_background-color']);
  194. $has_post_style = $has_background_color;
  195. if ( $has_post_style ) {
  196. $post_style = ' style="';
  197. }
  198. // background-color
  199. if ( $has_background_color ) {
  200. $post_style .= 'background-color:' . $post_meta['_background-color'] . ';';
  201. $post_class .= ' has-background-color';
  202. }
  203. if ( $has_post_style ) {
  204. $post_style .= '"';
  205. }
  206. // Dark or light color scheme
  207. if ( isset($post_meta['_color-scheme']) ) {
  208. $post_class .= ' color-scheme-' . $post_meta['_color-scheme'];
  209. }
  210. // Show image before or after the content
  211. if ( isset($post_meta['_image-position']) ) {
  212. $post_class .= ' image-position-' . $post_meta['_image-position'];
  213. }
  214. // Show image with shadow or not
  215. if ( isset($post_meta['_image-shadow']) ) {
  216. $post_class .= ' thumbnail-' . $post_meta['_image-shadow'];
  217. }
  218. // Post type "page" fields
  219. $subheadline = isset($post_meta['_subheadline']) ? apply_filters('the_content', $post_meta['_subheadline']) : '';
  220. // Post type "page"
  221. if ( $post_type === 'page' ) {
  222. $content_meta_args = false;
  223. }
  224. // Post type "service"
  225. if ( $post_type === 'service' ) {
  226. $content_meta_args = false;
  227. }
  228. // Post type "product" fields
  229. $produkt_pdf = isset($post_meta['_pdf-download']) ? $post_meta['_pdf-download'] : '';
  230. $produkt_url = isset($post_meta['_product-url']) ? $post_meta['_product-url'] : '';
  231. if ( !empty($produkt_pdf) ) {
  232. $produkt_url = wp_get_attachment_url($produkt_pdf);
  233. }
  234. if ( $post_type === 'produkt' ) {
  235. $content_meta_args = false;
  236. }
  237. // Download button
  238. $download_url = !empty($produkt_pdf) ? $produkt_pdf : '';
  239. $download_target = '';
  240. if ( !empty($download_url) ) {
  241. if ( parse_url($download_url, PHP_URL_HOST) !== $site_host ) {
  242. $download_target = ' target="_blank" rel="noopener"';
  243. }
  244. $post_class = 'has-download';
  245. }
  246. if ( empty($content) ) {
  247. $content = apply_filters('the_content', get_the_content());
  248. }
  249. ?>
  250. <article id="section-<?php sandbox_the_slug(); ?>" <?php post_class($post_class) ?><?php echo $post_style; ?>>
  251. <?php if ( has_post_thumbnail() ) { ?>
  252. <span class="post-thumbnail"><?php the_post_thumbnail('full'); ?></span>
  253. <?php } ?>
  254. <div class="content inner">
  255. <?php if ( !has_term('testimonials', 'sectiongroup') ) { ?>
  256. <header class="content-header">
  257. <div class="inner">
  258. <?php if ( !empty($subheadline) ) { ?>
  259. <div class="subheadline">
  260. <?php echo $subheadline; ?>
  261. </div>
  262. <?php } ?>
  263. <h2 class="title"><?php the_title(); ?></h2>
  264. <?php if ( !empty($download_url) ) { ?>
  265. <a class="download" href="<?php echo $download_url; ?>"<?php echo $download_target; ?>><?php echo __('Download', 'sandbox'); ?></a>
  266. <?php } ?></h1>
  267. <?php if ( has_excerpt() ) { ?>
  268. <div class="intro">
  269. <?php the_excerpt(); ?>
  270. </div>
  271. <?php } ?>
  272. <?php if ( $meta = sandbox_get_meta_data($content_meta_args) ) { ?>
  273. <ul class="meta">
  274. <?php echo $meta; ?>
  275. </ul>
  276. <?php } ?>
  277. </div>
  278. </header>
  279. <?php } ?>
  280. <?php if ( !empty($content) ) { ?>
  281. <?php echo $content; ?>
  282. <?php } ?>
  283. </div>
  284. <?php if ( isset($post_taxonomies['benefit']) && !empty($post_taxonomies['benefit']) ) { ?>
  285. <div class="<?php echo esc_attr(sanitize_html_class(strtolower($post_taxonomies['benefit']['label']))); ?>">
  286. <?php foreach ( $post_taxonomies['benefit']['terms'] as $benefit ) { ?>
  287. <?php
  288. $benefit_meta = get_term_meta($benefit['term_id']);
  289. $benefit_thumbnail = $benefit_meta['_benefit-image'] !== false ? wp_get_attachment_image($benefit_meta['_benefit-image'][0], 'full') : false;
  290. $benefit_icon_name = $benefit_meta['_benefit-icon'] !== false ? $benefit_meta['_benefit-icon'][0] : false;
  291. ?>
  292. <div class="term-<?php echo esc_attr($post_taxonomies['benefit']['slug']); ?>">
  293. <div class="term-thumbnail content">
  294. <?php if ( $benefit_thumbnail ) { ?>
  295. <?php echo $benefit_thumbnail; ?>
  296. <?php } else if ( $benefit_icon_name ) { ?>
  297. <span class="material-icon"><?php echo $benefit_icon_name; ?></span>
  298. <?php } ?>
  299. </div>
  300. <div class="inner content">
  301. <?php echo apply_filters('the_content', $benefit['description']); ?>
  302. </div>
  303. </div>
  304. <?php } ?>
  305. </div>
  306. <?php } ?>
  307. <?php // If comments are open or we have at least one comment, load up the comment template. ?>
  308. <?php if ( comments_open() || get_comments_number() ) { ?>
  309. <?php comments_template('/comments.php'); ?>
  310. <?php } ?>
  311. </article><!-- .post -->
  312. <?php } ?>
  313. <?php } ?>
  314. <?php wp_reset_postdata(); ?>
  315. <?php } ?>
  316. <?php } ?>
  317. <?php } ?>
  318. <?php } ?>
  319. <?php get_footer() ?>