Page 1 of 1

Multiple topic lists on same page

Posted: Thu Nov 22, 2018 10:18 am
by teebling
Hello,

I would like to ask whether the following is possible - to have two topic lists on one page. For example:

Forum 1
--------------------------
topic
topic
topic
topic

Forum 2
--------------------------
topic
topic
topic
topic

Thanks,
Teebling

Re: Multiple topic lists on same page

Posted: Thu Nov 22, 2018 10:21 am
by Senky
Yes, it is possible. Maybe even not very difficult to make when one could alter the query selecting topic_ids and then sort them by forum...

Re: Multiple topic lists on same page

Posted: Thu Nov 22, 2018 10:31 am
by teebling
Senky wrote:
Thu Nov 22, 2018 10:21 am
Yes, it is possible. Maybe even not very difficult to make when one could alter the query selecting topic_ids and then sort them by forum...
Hey Senky, first of all thank you for Relative Dates and User Recent Activity - these are both great exts that I'm using on my forum :)

I only have frontend development knowledge and finding a way to do this has me at my wit's end - I've even been considering using ajax to load the topiclist from an external page which is not the most elegant solution... or iframes (just joking lol).

Would this be something you could do? Even a quick find and replace hack would be a godsend for me.

Re: Multiple topic lists on same page

Posted: Thu Nov 22, 2018 12:59 pm
by Senky
Okay so there is an SQL query in viewforum.php, around line 626:

Code: Select all

$sql_ary = array(
	'SELECT'	=> 't.topic_id',
	'FROM'		=> array(
		TOPICS_TABLE => 't',
	),
	'WHERE'		=> "$sql_where
		AND t.topic_type IN (" . POST_NORMAL . ', ' . POST_STICKY . ")
		$sql_approved
		$sql_limit_time",
	'ORDER_BY'	=> 't.topic_type ' . ((!$store_reverse) ? 'DESC' : 'ASC') . ', ' . $sql_sort_order,
);
See that $sql_where is constructed in condition above the query. You should alter this condition by adding your forum_id to it (in all 3 cases).

So now you have topics from multiple forums, but you need to sort them. This is quite difficult. Depending on the use case, maybe it could be enough to add a condition to viewforum_body.html near line 133:

Code: Select all

	<!-- IF not topicrow.S_TOPIC_TYPE_SWITCH and not topicrow.S_FIRST_ROW -->
this code is what divides announcements from other topics. So you can divide different forums in the same way. But maybe you need to sort topics by forum first must be done before line 864 in viewforum.php where it starts pulling topic data:

Code: Select all

foreach ($topic_list as $topic_id)

Re: Multiple topic lists on same page

Posted: Thu Nov 22, 2018 6:25 pm
by teebling
Senky wrote:
Thu Nov 22, 2018 12:59 pm
Okay so there is an SQL query in viewforum.php, around line 626:

Code: Select all

$sql_ary = array(
	'SELECT'	=> 't.topic_id',
	'FROM'		=> array(
		TOPICS_TABLE => 't',
	),
	'WHERE'		=> "$sql_where
		AND t.topic_type IN (" . POST_NORMAL . ', ' . POST_STICKY . ")
		$sql_approved
		$sql_limit_time",
	'ORDER_BY'	=> 't.topic_type ' . ((!$store_reverse) ? 'DESC' : 'ASC') . ', ' . $sql_sort_order,
);
See that $sql_where is constructed in condition above the query. You should alter this condition by adding your forum_id to it (in all 3 cases).

So now you have topics from multiple forums, but you need to sort them. This is quite difficult. Depending on the use case, maybe it could be enough to add a condition to viewforum_body.html near line 133:

Code: Select all

	<!-- IF not topicrow.S_TOPIC_TYPE_SWITCH and not topicrow.S_FIRST_ROW -->
this code is what divides announcements from other topics. So you can divide different forums in the same way. But maybe you need to sort topics by forum first must be done before line 864 in viewforum.php where it starts pulling topic data:

Code: Select all

foreach ($topic_list as $topic_id)


Hey Senky,
Thanks for getting back to me.

Could you tell how I would insert the code to add my forum IDs to the $sql_where condition in viewforum.php and how I would insert the code for sorting the topics in viewforum.php? The forum IDs I want to show as topic lists are for example: 7, 9 and 11. Also what would the template condition in viewforum_body.html look like?

Re: Multiple topic lists on same page

Posted: Thu Nov 22, 2018 11:03 pm
by teebling
Update:

Been playing around with viewforum.php and managed to get topics from three other forums to display in the main topiclist - woohoo!

I used the following to display all topics from forum IDs 7, 9 and 5.

Code: Select all

'WHERE'	=> '(t.forum_id = ' . 7 . ' OR (t.forum_id = ' . 9 . ') OR (t.forum_id = ' . 5 . '),
They are all sorted in the default way (by date of last post) as far as I can see.

Also I noticed that after editing viewforum.php the unread/read icons do not update after reading any topic, and posts which were read before now appear unread and will not change. This behaviour obviously isn't okay so perhaps I did something wrong with the code in viewforum.php?

So, now that I have fetched topics from these forums, how do I make them display in a completely separate topic list on the same page? What template variable should I use to say: 'Get topic list from forum X only and display it on this page here'?

As you say the following code separates Announcements/Globals from the forum list:

Code: Select all

<!-- IF not topicrow.S_TOPIC_TYPE_SWITCH and not topicrow.S_FIRST_ROW -->
</ul>
</div>
</div>
<!-- ENDIF -->
How do I make a template variable that instead of 'not S.TOPIC_TYPE_SWITCH' says something like 'not S.FORUM_ID=3'? Then I would be able to separate each topic list by forum ID, right?

Re: Multiple topic lists on same page

Posted: Sun Dec 02, 2018 10:46 am
by Senky
teebling, I am sorry, what you are asking is actually writing an extension for you which is too time demanding. I hope you can with a small steps figure it out yourself.