A quick question. So I have created a loop in a new file called sidebar-extra.php
which I include via the header.php
into my single.php
file.
Problem: when I go to a post (single.php), I can't see this navigation, while I can see it on my homepage, where I also include sidebar-extra.php
<ul class="pagination">
<li class="page-item"><?php previous_posts_link('« Previous posts') ?></li>
<li class="page-item"><?php next_posts_link('Next posts »') ?></li>
</ul>
Is there a way I can make sure that my sidebar-extra.php
is showing the post navigation everywhere, including on single.php
?
A quick question. So I have created a loop in a new file called sidebar-extra.php
which I include via the header.php
into my single.php
file.
Problem: when I go to a post (single.php), I can't see this navigation, while I can see it on my homepage, where I also include sidebar-extra.php
<ul class="pagination">
<li class="page-item"><?php previous_posts_link('« Previous posts') ?></li>
<li class="page-item"><?php next_posts_link('Next posts »') ?></li>
</ul>
Is there a way I can make sure that my sidebar-extra.php
is showing the post navigation everywhere, including on single.php
?
1 Answer
Reset to default 0You’re using previous_posts_link
(and next_posts_link
) function in your code.
This function prints a link to the previous set of posts within the current query. So they are meant for posts archives.
But if you’re on single page/post, so there is only one post in the query - the one that is shown. So these links won’t be available.
When seeing a single post, you should be using previous_post_link
instead (singular post and not posts).