-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsingle.php
89 lines (81 loc) · 2.73 KB
/
single.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* The template for displaying all single posts
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post
*
* @package Deary
*/
$post_meta = get_post_meta($post->ID);
// Set accent color, use default black if not set
if (array_key_exists('nm_accent_color', $post_meta) && !empty($post_meta['nm_accent_color'])) {
$accent_color = $post_meta['nm_accent_color'][0];
} else {
$accent_color = '#000';
}
// Use multicolor title if set, regular title if not
if (array_key_exists('nm_multicolor_title', $post_meta) && !empty($post_meta['nm_multicolor_title'])) {
$multicolor_title = $post_meta['nm_multicolor_title'][0];
$title = preg_replace_callback('/%(.*?)%/s', function ($matches) use ($accent_color) {
return '<span style="color:' . $accent_color . ';">' . $matches[1] . '</span>';
}, $multicolor_title);
} else {
$title = $post->post_title;
}
get_header();
?>
<main id="primary" class="site-main">
<article class="nm-product">
<div class="nm-product-top">
<div class="nm-product-top-left">
<div class="nm-product-title">
<h1><?php echo $title;?></h1>
</div>
<div class="nm-product-content">
<?php echo wpautop($post->post_content);?>
</div>
</div>
<div class="nm-product-top-center">
<div class="nm-product-image">
<?php echo get_the_post_thumbnail($post); ?>
</div>
</div>
<div class="nm-product-top-right">
<?php if (array_key_exists('nm_quote', $post_meta)): ?>
<div class="nm-product-quote">
<p style="color:<?php echo $accent_color; ?>"><?php echo "\"" . $post_meta['nm_quote'][0] . "\""; ?></p>
</div>
<?php endif; ?>
</div>
</div>
<?php if (array_key_exists('nm_nutrition_facts', $post_meta)): ?>
<div class="nm-product-bottom">
<?php
$title = get_post_meta($post->ID, 'nm_nutrition_facts')[0]['title'];
$facts = get_post_meta($post->ID, 'nm_nutrition_facts')[0]['facts'];
?>
<div class="nm-product-nutrition-facts">
<?php if(!empty($title) && is_string($title)): ?>
<h2><?php echo $title; ?></h2>
<?php endif; ?>
<?php if (!empty($facts) && is_array($facts)): ?>
<div class="nm-product-nutrition-facts-table">
<?php foreach($facts as $fact): ?>
<div class="nm-product-nutition-facts-col">
<div class="nm-product-nutition-facts-nutrient">
<?php echo $fact['nutrient']; ?>
</div>
<div class="nm-product-nutition-facts-value">
<?php echo $fact['value']; ?>
</div>
</div>
<?php endforeach;?>
</div>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
</article>
</main><!-- #main -->
<?php
get_footer();