Check if there is a next or previous topic

Discussion forum for MOD Writers regarding MOD Development.
User avatar
Stoker 4.0
Registered User
Posts: 1504
Joined: Sun Feb 13, 2011 1:33 pm
Location: Funen, Denmark
Name: Ulrik Christensen

Check if there is a next or previous topic

Post by Stoker 4.0 »

Is there a way to check if there is a next or previous topic?
Subsilver2 has a next and a previous link in viewtopic, but it displays even if there isnt any next or previous topics.
Regards Stoker
User avatar
imkingdavid
Former Team Member
Posts: 2673
Joined: Sun Jul 26, 2009 7:59 pm
Location: EST
Name: David King

Re: Check if there is a next or previous topic

Post by imkingdavid »

Looking at it, it appears that it only checks for a new or previous topic if &view=next or &view=previous is in the URL.
The code to generate the next/previous links is non-conditional:

Code: Select all

	'U_VIEW_OLDER_TOPIC'	=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&view=previous"),
	'U_VIEW_NEWER_TOPIC'	=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id&view=next"),
The reason is that is has to do some extra SQL queries to see if there's another topic, and the goal is to perform as few queries as possible on each page load. To see where it is checked, search in viewtopic.php for:

Code: Select all

else if($view == 'next' || $view == 'previous')
EDIT: If you want to do it for yourself, you can adapt the logic/queries from there.
Don't forget to smile today. :)
Please do NOT contact for support via PM or email.
yaashul
Registered User
Posts: 331
Joined: Mon Apr 17, 2006 3:21 pm
Location: India

Re: Check if there is a next or previous topic

Post by yaashul »

Can some help us making this query and necessary changes?

Return to “[3.0.x] MOD Writers Discussion”