-
Notifications
You must be signed in to change notification settings - Fork 0
/
single-recipes.php
237 lines (176 loc) · 8.01 KB
/
single-recipes.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<?php
/**
* The template for displaying a single recipe.
*
* (C) BYMARC
*
*/
?>
<?php get_header(); ?>
<!-- HTML content starts! -->
<!-- LOOP? single-->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<section class="stage single">
<div class="container-fluid">
<div class="row justify-content-center">
<div class="col-12">
<div class="image">
<?php if (is_home()) { ?>
<?php
$page_for_posts = get_option('page_for_posts');
echo get_the_post_thumbnail($page_for_posts, 'large');
?>
<?php }
// Get the recipes inside the current post.
$recipes = WPRM_Recipe_Manager::get_recipe_ids_from_post();
// Access the first recipe, if there is one.
if (isset($recipes[0])) {
$recipe_id = $recipes[0];
$recipe = WPRM_Recipe_Manager::get_recipe($recipe_id);
// Output the recipe name.
?>
<div class="container">
<div class="row">
<div class="col-12">
<?php
echo ("<h1 class=\"h1-recipe\"><span>" . $recipe->name() . "</span></h1>");
?>
</div>
</div>
</div>
<?php
echo ("<div class=\"img_overlay\"></div>");
echo $recipe->image(1920, 1080);
}
?>
<!-- </a> -->
</div>
</div>
</div>
</div>
</div>
</section>
<section>
<?php
// Get the recipes inside the current post.
$recipes = WPRM_Recipe_Manager::get_recipe_ids_from_post();
// Access the first recipe, if there is one.
if (isset($recipes[0])) {
$recipe_id = $recipes[0];
$recipe = WPRM_Recipe_Manager::get_recipe($recipe_id);
if ($recipe->video()) : ?>
<div id="wprm-recipe-video-container-<?php echo $recipe->id(); ?>" class="wprm-recipe-video-container">
<?php echo do_shortcode($recipe->video()) ?>
</div>
<?php endif; // Video.
}
?>
</section>
<?php get_template_part('template-parts/content/breadcrumb') ?>
<section class="recipes">
<div class="container-fluid">
<div class="row justify-content-center">
<div class="col-12">
<div class="content " data-aos="fade">
<?php the_content(); ?>
<?php
//get the taxonomy terms of custom post type
$customTaxonomyTerms = wp_get_object_terms($post->ID, 'your_taxonomy', array('fields' => 'ids'));
//query arguments
$args = array(
'post_type' => 'recipes',
'post_status' => 'publish',
'posts_per_page' => 5,
'orderby' => 'rand',
'tax_query' => array(
array(
'field' => 'id',
)
),
'post__not_in' => array($post->ID),
);
//the query
$relatedPosts = new WP_Query($args);
//loop through query
if ($relatedPosts->have_posts()) {
echo '<ul>';
while ($relatedPosts->have_posts()) {
$relatedPosts->the_post();
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php
}
echo '</ul>';
} else {
//no posts found
}
//restore original post data
wp_reset_postdata();
?>
</div>
</div>
</div>
</div>
</section>
<section class="comments">
<div class="container">
<div class="row">
<div class="col-12">
<?php
// If comments are open or we have at least one comment, load up the comment template.
if (comments_open() || get_comments_number()) :
comments_template();
endif;
?>
</div>
</div>
</div>
</section>
<section class="morerecipes">
<div class="container">
<div class="row">
<div class="col-12" data-aos="fade-right">
<h2>Weitere Rezepte</h2>
</div>
<?php
$related_query = new WP_Query(array(
'post_type' => 'recipes',
'category__in' => wp_get_post_categories(get_the_ID()),
'post__not_in' => array(get_the_ID()),
'posts_per_page' => 3,
'orderby' => 'date',
));
while ($related_query->have_posts()) : $related_query->the_post();
echo ("<div class=\"col-lg-4 col-xxl-3 recipe-card\" data-aos=\"fade\">");
echo ("<a href=\" ");
the_permalink();
echo (" \">");
// Get the recipes inside the current post.
$recipes = WPRM_Recipe_Manager::get_recipe_ids_from_post();
// Access the first recipe, if there is one.
if (isset($recipes[0])) {
$recipe_id = $recipes[0];
$recipe = WPRM_Recipe_Manager::get_recipe($recipe_id);
// Output the recipe name.
echo ("<p>" . $recipe->name() . "</p>");
echo ("<div class=\"img_overlay\"></div>");
echo $recipe->image(1920, 1080);
}
echo("</div></a>");
endwhile;
?>
<?php
?>
<div class=" col-md-12 col-lg-12 col-xxl-3 all-recipes" data-aos="fade">
<div class="all-recipes-inner">
<a href="/rezepte" class="btn btn-secondary">Alle Rezepte</a>
</div>
</div>
</div>
</section>
<?php get_template_part('template-parts/content/ownrecipe') ?>
<?php endwhile;
endif; ?>
<!-- HTML content ends! -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>