-
Notifications
You must be signed in to change notification settings - Fork 0
/
single.php
114 lines (81 loc) · 3.2 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
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
<?php
/**
* The template for displaying all single posts.
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post
*
* @package regnsky
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
while ( have_posts() ) : the_post();
get_template_part( 'template-parts/content', get_post_format() ); ?>
<?php
$related_by_author = get_field('related_posts');
$tags = wp_get_post_tags($post->ID);
// Set $related_posts to related posts chosen by author
if ($related_by_author) :
$related_posts = $related_by_author;
// Set $related_posts to posts based on tags
elseif ($tags) :
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
$tag_args=array(
'tag__in' => $tag_ids,
'post__not_in' => array($post->ID),
'posts_per_page' => 3, // Number of related posts to display.
'caller_get_posts' => 1
);
$related_by_tags = get_posts($tag_args);
$related_posts = $related_by_tags;
endif; ?>
<?php // If there are related posts
if ( $related_posts ): ?>
<div class="related-posts">
<div class="container">
<div class="flex">
<h4 class="col col-xs-12">Nu kunne du læse...</h4>
<ul class="col col-xs-12">
<?php foreach( $related_posts as $post): ?>
<?php setup_postdata($post); ?>
<?php
$category_array = get_the_category($post->post_ID);
$category = $category_array[0];
$category_name = $category->cat_name;
?>
<li class="related-post <?php echo 'post-' . strtoLower($category_name) ?>">
<!-- Title -->
<h2 class="related-post_title col col-xs-12 col-sm-10 offset-sm-1 col-lg-8 offset-lg-2">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h2>
<!-- Author and post date -->
<div class="related-post_meta entry-meta col col-xs-12">
<?php echo regnsky_posted_on(); ?>
</div>
<!-- Category and excerpt -->
<div class="related-post_content col col-xs-12 col-sm-10 offset-sm-1 col-md-8 offset-md-2 col-xl-6 offset-xl-3">
<span class="related-post_category">
<?php
if ($category_name == 'Opdagelser') :
$category_name = 'Opdagelse';
endif;
echo $category_name; ?>
</span>
<p><?php echo get_excerpt(160); ?></p>
</div>
</li>
<?php endforeach; ?>
</ul>
<?php wp_reset_postdata(); ?>
</div> <!-- /.flex -->
</div> <!-- /.container -->
</div> <!-- /.related-posts -->
<?php endif; ?>
<?php
endwhile; // End of the loop. ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
get_footer();