Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

379 строки
14 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 decoration or not
  46. if ( isset($post_meta['_image-decoration']) ) {
  47. $post_class .= ' thumbnail-' . $post_meta['_image-decoration'];
  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. $section_linked_id = 0;
  189. $section_linked = false;
  190. $post_class = 'no-download';
  191. $content_meta_args = array();
  192. // Linked section
  193. if ( isset($post_meta['_section-linked']) ) {
  194. $section_linked_id = intval($post_meta['_section-linked'][0]);
  195. $section_linked = get_post($section_linked_id);
  196. }
  197. // post style attribute
  198. $post_style = '';
  199. $color_hex_pattern = '/#([a-f0-9]{3}){1,2}\b/i';
  200. $has_background_color = isset($post_meta['_background-color']) && preg_match($color_hex_pattern, $post_meta['_background-color']);
  201. $has_post_style = $has_background_color;
  202. if ( $has_post_style ) {
  203. $post_style = ' style="';
  204. }
  205. // background-color
  206. if ( $has_background_color ) {
  207. $post_style .= 'background-color:' . $post_meta['_background-color'] . ';';
  208. $post_class .= ' has-background-color';
  209. }
  210. if ( $has_post_style ) {
  211. $post_style .= '"';
  212. }
  213. // Dark or light color scheme
  214. if ( isset($post_meta['_color-scheme']) ) {
  215. $post_class .= ' color-scheme-' . $post_meta['_color-scheme'];
  216. }
  217. // Show image before or after the content
  218. if ( isset($post_meta['_image-position']) ) {
  219. $post_class .= ' image-position-' . $post_meta['_image-position'];
  220. }
  221. // Show image with decoration or not
  222. if ( isset($post_meta['_image-decoration']) ) {
  223. $post_class .= ' thumbnail-' . $post_meta['_image-decoration'];
  224. }
  225. // Post type "page" fields
  226. $subheadline = isset($post_meta['_subheadline']) ? apply_filters('the_content', $post_meta['_subheadline']) : '';
  227. // Post type "page"
  228. if ( $post_type === 'page' ) {
  229. $content_meta_args = false;
  230. }
  231. // Post type "service"
  232. if ( $post_type === 'service' ) {
  233. $content_meta_args = false;
  234. }
  235. // Post type "product" fields
  236. $produkt_pdf = isset($post_meta['_pdf-download']) ? $post_meta['_pdf-download'] : '';
  237. $produkt_url = isset($post_meta['_product-url']) ? $post_meta['_product-url'] : '';
  238. if ( !empty($produkt_pdf) ) {
  239. $produkt_url = wp_get_attachment_url($produkt_pdf);
  240. }
  241. if ( $post_type === 'produkt' ) {
  242. $content_meta_args = false;
  243. }
  244. // Download button
  245. $download_url = !empty($produkt_pdf) ? $produkt_pdf : '';
  246. $download_target = '';
  247. if ( !empty($download_url) ) {
  248. if ( parse_url($download_url, PHP_URL_HOST) !== $site_host ) {
  249. $download_target = ' target="_blank" rel="noopener"';
  250. }
  251. $post_class = 'has-download';
  252. }
  253. if ( empty($content) ) {
  254. $content = apply_filters('the_content', get_the_content());
  255. }
  256. ?>
  257. <article id="section-<?php sandbox_the_slug(); ?>" <?php post_class($post_class) ?><?php echo $post_style; ?>>
  258. <?php if ( has_post_thumbnail() ) { ?>
  259. <?php if ( $section_linked_id === 0 ) { ?>
  260. <span class="post-thumbnail"><?php the_post_thumbnail('full'); ?></span>
  261. <?php } else { ?>
  262. <a href="<?php echo get_permalink($section_linked_id); ?>" class="post-thumbnail"><?php the_post_thumbnail('full'); ?></a>
  263. <?php } ?>
  264. <?php } ?>
  265. <div class="content inner">
  266. <?php if ( !has_term('testimonials', 'sectiongroup') ) { ?>
  267. <header class="content-header">
  268. <div class="inner">
  269. <?php if ( !empty($subheadline) ) { ?>
  270. <div class="subheadline">
  271. <?php echo $subheadline; ?>
  272. </div>
  273. <?php } ?>
  274. <?php if ( $section_linked_id === 0 ) { ?>
  275. <h2 class="title"><?php the_title(); ?></h2>
  276. <?php } else { ?>
  277. <h2 class="title"><a href="<?php echo get_permalink($section_linked_id); ?>"><?php the_title(); ?></a></h2>
  278. <?php } ?>
  279. <?php if ( !empty($download_url) ) { ?>
  280. <a class="download" href="<?php echo $download_url; ?>"<?php echo $download_target; ?>><?php echo __('Download', 'sandbox'); ?></a>
  281. <?php } ?></h1>
  282. <?php if ( has_excerpt() ) { ?>
  283. <div class="intro">
  284. <?php the_excerpt(); ?>
  285. </div>
  286. <?php } ?>
  287. <?php if ( $meta = sandbox_get_meta_data($content_meta_args) ) { ?>
  288. <ul class="meta">
  289. <?php echo $meta; ?>
  290. </ul>
  291. <?php } ?>
  292. </div>
  293. </header>
  294. <?php } ?>
  295. <?php if ( !empty($content) ) { ?>
  296. <?php echo $content; ?>
  297. <?php } ?>
  298. <?php if ( $section_linked_id > 0 ) { ?>
  299. <p><a class="button" href="<?php echo get_permalink($section_linked_id); ?>"><?php echo apply_filters('post_title', $section_linked->post_title); ?></a></p>
  300. <?php } ?>
  301. </div>
  302. <?php if ( isset($post_taxonomies['benefit']) && !empty($post_taxonomies['benefit']) ) { ?>
  303. <div class="<?php echo esc_attr(sanitize_html_class(strtolower($post_taxonomies['benefit']['label']))); ?>">
  304. <?php foreach ( $post_taxonomies['benefit']['terms'] as $benefit ) { ?>
  305. <?php
  306. $benefit_meta = get_term_meta($benefit['term_id']);
  307. $benefit_thumbnail = $benefit_meta['_benefit-image'] !== false ? wp_get_attachment_image($benefit_meta['_benefit-image'][0], 'full') : false;
  308. $benefit_icon_name = $benefit_meta['_benefit-icon'] !== false ? $benefit_meta['_benefit-icon'][0] : false;
  309. ?>
  310. <div class="term-<?php echo esc_attr($post_taxonomies['benefit']['slug']); ?>">
  311. <div class="term-thumbnail content">
  312. <?php if ( $benefit_thumbnail ) { ?>
  313. <?php echo $benefit_thumbnail; ?>
  314. <?php } else if ( $benefit_icon_name ) { ?>
  315. <span class="material-icon"><?php echo $benefit_icon_name; ?></span>
  316. <?php } ?>
  317. </div>
  318. <div class="inner content">
  319. <?php echo apply_filters('the_content', $benefit['description']); ?>
  320. </div>
  321. </div>
  322. <?php } ?>
  323. </div>
  324. <?php } ?>
  325. <?php // If comments are open or we have at least one comment, load up the comment template. ?>
  326. <?php if ( comments_open() || get_comments_number() ) { ?>
  327. <?php comments_template('/comments.php'); ?>
  328. <?php } ?>
  329. </article><!-- .post -->
  330. <?php } ?>
  331. <?php } ?>
  332. <?php wp_reset_postdata(); ?>
  333. <?php } ?>
  334. <?php } ?>
  335. <?php } ?>
  336. <?php } ?>
  337. <?php get_footer() ?>