/
snip_adjacentposts.php
69 lines (64 loc) · 3.77 KB
/
snip_adjacentposts.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
<div class="collage responsive">
<?php
//previous post
$in_same_cat = false;
$excluded_categories = '';
$previous = true;
$previous_post = get_adjacent_post($in_same_cat,$excluded_categories,$previous);
//previous post values
$previous_title = $previous_post->post_title;
$previous_link = get_permalink( $previous_post->ID );
$previous_summary = get_post_meta($previous_post->ID, "subtitle_value", $single = true);
$previous_image = wp_get_attachment_image_src( get_post_thumbnail_id($previous_post->ID), 'medium');
$previous_image_large = wp_get_attachment_image_src( get_post_thumbnail_id($previous_post->ID), 'large');
//next post
$in_same_cat = false;
$excluded_categories = '';
$previous = false;
$next_post = get_adjacent_post($in_same_cat,$excluded_categories,$previous);
//next post values
$next_title = $next_post->post_title;
$next_link = get_permalink( $next_post->ID );
$next_summary = get_post_meta($next_post->ID, "subtitle_value", $single = true);
$next_image = wp_get_attachment_image_src( get_post_thumbnail_id($next_post->ID), 'medium');
$next_image_large = wp_get_attachment_image_src( get_post_thumbnail_id($next_post->ID), 'large');
?>
<?php if(get_adjacent_post(false, '', true) and get_adjacent_post(false, '', false)) { //if there is a next & previous post show it ?>
<a href="<?php echo $previous_link; ?>" class="post-item grid-2-square inverse <?php if(has_post_thumbnail($previous_post->ID)) {echo 'bg-image';} else {echo 'bg-image-text';}?>"
style='background-image: url("<?php echo $previous_image[0] ?>");' title="<?php echo $previous_title; ?>">
<span class="subtitle-item">Previous Post</span>
<span class="post-content">
<h3 class="title"><?php echo $previous_title; ?></h3>
<h4 class="subtitle"><?php if($previous_summary !== ''){ ?><?php echo $previous_summary; ?><?php } ?></h4>
</span>
</a>
<a href="<?php echo $next_link; ?>" class="post-item grid-2-square inverse <?php if(has_post_thumbnail($next_post->ID)) {echo 'bg-image';} else {echo 'bg-image-text';}?>"
style='background-image: url("<?php echo $next_image[0] ?>");' title="<?php echo $next_title; ?>">
<span class="subtitle-item">Next Post</span>
<span class="post-content">
<h3 class="title"><?php echo $next_title; ?></h3>
<h4 class="subtitle"><?php if($next_summary !== ''){ ?><?php echo $next_summary; ?><?php } ?></h4>
</span>
</a>
<?php } else { ?>
<?php if(get_adjacent_post(false, '', false)) { //if there is a next post ?>
<a href="<?php echo $next_link; ?>" class="post-item grid-1 inverse <?php if(has_post_thumbnail($next_post->ID)) {echo 'bg-image';} else {echo 'bg-image-text';}?>"
style='background-image: url("<?php echo $next_image_large[0] ?>");' title="<?php echo $next_title; ?>">
<span class="subtitle-item">Next Post</span>
<span class="post-content">
<h3 class="title"><?php echo $next_title; ?></h3>
<h4 class="subtitle"><?php if($next_summary !== ''){ ?><?php echo $next_summary; ?><?php } ?></h4>
</span>
</a>
<?php } else { ?>
<a href="<?php echo $previous_link; ?>" class="post-item grid-1 inverse <?php if(has_post_thumbnail($previous_post->ID)) {echo 'bg-image';} else {echo 'bg-image-text';}?>"
style='background-image: url("<?php echo $previous_image_large[0] ?>");' title="<?php echo $previous_title; ?>">
<span class="subtitle-item">Previous Post</span>
<span class="post-content">
<h3 class="title"><?php echo $previous_title; ?></h3>
<h4 class="subtitle"><?php if($previous_summary !== ''){ ?><?php echo $previous_summary; ?><?php } ?></h4>
</span>
</a>
<?php } ?>
<?php } ?>
</div>