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('&laquo; Previous posts') ?></li>
        <li class="page-item"><?php next_posts_link('Next posts &raquo;') ?></li>

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 1


You’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).

  • I don't think that this will solve my issue. I mean, the sidebar has a list of posts and is being injected into single.php but also other pages. How can I make sure it will serve the navigation for all pages, regardless of whether it's single.php or something else? I mean, if I do what you tell me to do, I don't get the navigation in my sidebar area when I am entering single.php, still.
    – Siyah
    May 28, 2019 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.