alexkodr
alexkodr

Reputation: 543

Wordpress - Hiding 'Next' article link on latest post and 'Prev' article link on the oldest post

I'm using the previous_post_link & next_post_link to display links to next & prev articles on a post single page. This works fine and the code I'm using is like this:

<div class="previous-article">
    <h4>Previous Article</h4>
    <?php previous_post_link('%link'); ?>
</div>

<div class="next-article">
    <h4>Next Article</h4>
    <?php next_post_link('%link'); ?>
</div>

Is there a statement I can use to hide / not display the 'Next' article link on the latest blog post because there is no 'next' so it display a blank entry (meaning that I can also hide the h4 headings I have in place) e.g.

enter image description here

So it looks like this:

enter image description here

And visa versa for the oldest post showing the 'Previous' article. Another solution would be to incorporate the heading into the php previous_post_link / next_post_link code. Maybe add class 'latest', 'oldest' to the body tag and I can hide using css. Is this possible?

Thanks

Upvotes: 0

Views: 436

Answers (1)

alexkodr
alexkodr

Reputation: 543

I should have searched better. For anyone else looking here is the solution to this how to get next/previous post hrefs and titles in wordpress

Upvotes: 0

Related Questions