Repository navigation
Expand file tree
/
Copy pathsingle.php
More file actions
75 lines (71 loc) · 2.07 KB
/
Copy pathsingle.php
File metadata and controls
75 lines (71 loc) · 2.07 KB
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
<?php get_template_part('components/header'); ?>
<div class="blog-post">
<div class="single-post-container">
<article id="post-<?php the_ID(); ?>" <?php post_class('single-post'); ?>>
<?php if (has_post_thumbnail()): ?>
<div class="post-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<?php endif; ?>
<div class="post-content">
<h1 class="post-title">
<?php the_title(); ?>
</h1>
<div class="post-text">
<?php the_content(); ?>
</div>
</div>
</article>
</div>
</div>
<?php
//
//START NEXT POST LINK
//
// Get the current post's ID
$current_post = get_the_ID();
// Get the first post (in the order you want)
$first_post = get_posts(array(
'numberposts' => 1,
'order' => 'ASC', // Ensure first post is selected based on your preferred order
'post_type' => 'post',
'fields' => 'ids' // Only fetch the ID
))[0];
// Get the last post
$last_post = get_posts(array(
'numberposts' => 1,
'order' => 'DESC', // Last post in reverse order
'post_type' => 'post',
'fields' => 'ids'
))[0];
// Logic to display the next link
if ($current_post == $last_post) {
// If we're on the last post, link to the first post
$next_post_url = get_permalink($first_post);
$next_post_title = get_the_title($first_post);
} else {
// Otherwise, link to the next post
$next_post = get_next_post();
if ($next_post) {
$next_post_url = get_permalink($next_post->ID);
$next_post_title = get_the_title($next_post->ID);
} else {
// Fallback if no next post is found
$next_post_url = '#';
$next_post_title = __('No next post available', 'your-textdomain');
}
}
// Retrieve the label from the Customizer
$next_post_label = get_theme_mod( 'next_post_label', __( 'Next Post', 'your-textdomain' ) );
?>
<section class="next-post">
<a href="<?php echo esc_url($next_post_url); ?>">
<?php printf( esc_html( $next_post_label . ': %s' ), esc_html( $next_post_title ) ); ?>
</a>
</section>
<?php
//
//END NEXT POST LINK
//
?>
<?php get_template_part('components/footer'); ?>