Answer the question
In order to leave comments, you need to log in
How to correctly recognize the links to the previous/next page?
I wrote my blog, it is necessary to display links to the previous \ next post inside each post. How to recognize them? The easiest thing, of course, is to find out the id of the current post, and then find links to other articles by requesting id +1 for the next one and id - 1 for the previous one in the database. But there may not be an article with such an id. Suddenly, it was deleted, and then a new one was added, which means there will be no more ID. How to act correctly? In the search only speech about WordPress.
Answer the question
In order to leave comments, you need to log in
Select 2 records from the table
1. Next post: Date-time is greater than current, and add to this order by post_date asc limit 1
2. Previous post: Date-time is less than current, and add to this order by post_date desc limit 1
Well, of course, statuses published there, etc. must be.
All that you need often and will change rarely / never - write to the database in advance! no need to load it with such nonsense.
Those. get the table or fields corresponding, and with a trigger update fields at base editing.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question