View a random topic

Looking for a MOD? Have a MOD request? Post here for help. (Note: This forum is community supported; phpBB does not have official MOD authors)
Suggested Hosts
Locked
halinagold
Registered User
Posts: 11
Joined: Thu Nov 09, 2006 12:23 pm
Contact:

View a random topic

Post by halinagold »

I'm looking for a mod that would enable me to pick and view a random topic from my entire board index.
So that a visitor can click on a link saying "View random topic" somewhere in the header of the board, and then be led to a random topic.
I recall there has been a discussion of such a mod in phpbb2 but I don't see any such mod here.
I understand that using a random search in the topics database can be heavy on the system, so perhaps the solution would be to create a string with a random number between 1 and the number of the latest topic.

Your response and support is much appreciated -

Halina
Halina
User avatar
imkingdavid
Former Team Member
Posts: 2673
Joined: Sun Jul 26, 2009 7:59 pm
Location: EST
Name: David King

Re: View a random topic

Post by imkingdavid »

EDIT: Disregard this post; I have posted a working solution in the next post!
---------------------
Well, maybe do the following on your index.php, and then in the styles/{name}/template/index_body.html file, add {RAND_TOPIC_LINK} near the link to viewing recent topics (don't know what it is called off the top of my head):

Code: Select all

$sql = 'SELECT topic_id FROM ' . TOPICS_TABLE;
$result = $db->sql_query($sql);
$row = $db->sql_fetchrowset($result);
$randtopicid = array_rand($row);
$template->assign_var('RAND_TOPIC_LINK', '<a href="viewtopic.php?t=' . $randtopicid . '">View a random topic</a>');
That's it in theory. But I haven't tried it so I have no idea if it actually works. The worst thing that happens is that it doesn't and you have to look some more for such a MOD. But if you want to, try it out and let me know if it works.
Last edited by imkingdavid on Thu Aug 27, 2009 3:37 am, edited 1 time in total.
Don't forget to smile today. :)
Please do NOT contact for support via PM or email.
User avatar
imkingdavid
Former Team Member
Posts: 2673
Joined: Sun Jul 26, 2009 7:59 pm
Location: EST
Name: David King

Re: View a random topic

Post by imkingdavid »

EDIT: Ok that doesn't work, but after a little bit of looking around, I found out that you can do this by manipulating the SQL command. Here's how I got it to work finally:
OPEN: index.php
FIND:

Code: Select all

display_forums('', $config['load_moderators']);
AFTER, ADD:

Code: Select all

$act = request_var('act', '');
$template->assign_var('RAND_TOPIC_LINK', '<a href="index.php?act=rand">View a random topic</a>');
if($act == 'rand')
{
	$sql = 'SELECT topic_id
		FROM ' . TOPICS_TABLE . '
		ORDER BY RAND()
		LIMIT 1';
	$result = $db->sql_query($sql);
	$row = $db->sql_fetchfield('topic_id');
	redirect('viewtopic.php?t=' . $row);
	
}
SAVE, CLOSE, AND UPLOAD

OPEN: styles/{style name}/template/index_body.html
FIND: ~ Line 9 in proSilver

Code: Select all

<li><a href="{U_SEARCH_UNANSWERED}">
REPLACE WITH:

Code: Select all

<li>{RAND_TOPIC_LINK} &bull; <li><a href="{U_SEARCH_UNANSWERED}">
SAVE, CLOSE AND UPLOAD

Go to ACP and Purge cache in order to refresh your template.

Realize that it is unofficial to not make a lang value and call it using the $user->lang function, but I was lazy and if you don't do it, it requires one less file edit, so no biggie. If you want to, though, and don't know how, I can show you how.
Don't forget to smile today. :)
Please do NOT contact for support via PM or email.
halinagold
Registered User
Posts: 11
Joined: Thu Nov 09, 2006 12:23 pm
Contact:

Re: View a random topic

Post by halinagold »

Thanks a lot!!!
I'm going to apply this in a couple of day (am very busy until then).
I'm very excited about it and so appreciate your support!

Best wishes

Halina
Halina
User avatar
imkingdavid
Former Team Member
Posts: 2673
Joined: Sun Jul 26, 2009 7:59 pm
Location: EST
Name: David King

Re: View a random topic

Post by imkingdavid »

By the way, if you want to see it in live working action, just click here. You should see "View a random topic" at the top. Click that and it should take you to a random topic. :)
Don't forget to smile today. :)
Please do NOT contact for support via PM or email.
halinagold
Registered User
Posts: 11
Joined: Thu Nov 09, 2006 12:23 pm
Contact:

Re: View a random topic

Post by halinagold »

Yes! it works perfectly on my private forum as well.

Joyful greetings -

Halina
Halina
User avatar
imkingdavid
Former Team Member
Posts: 2673
Joined: Sun Jul 26, 2009 7:59 pm
Location: EST
Name: David King

Re: View a random topic

Post by imkingdavid »

You're very welcome. :) If you need any more help, feel free to ask.
-David
Don't forget to smile today. :)
Please do NOT contact for support via PM or email.
kwiatek
Registered User
Posts: 4
Joined: Sat Aug 08, 2009 4:54 pm

Re: View a random topic

Post by kwiatek »

Can you modify this modification to the main page display 50 random topics as links?
User avatar
imkingdavid
Former Team Member
Posts: 2673
Joined: Sun Jul 26, 2009 7:59 pm
Location: EST
Name: David King

Re: View a random topic

Post by imkingdavid »

Hmm... that's not really the purpose of this MOD. This MOD's aim is simply to provide a way for a user to click a link and show up at a random topic. You would need another MOD to do what you're asking.

As far as your request, I'm sure it can be done. I'm not sure exactly how to go about implementing it. And I'm not sure that 50 topics is really a practical number Maybe you meant 5? Or maybe you actually have a reason for needing 50.

In any case, I can look into it, but no promises. :)
Don't forget to smile today. :)
Please do NOT contact for support via PM or email.
kwiatek
Registered User
Posts: 4
Joined: Sat Aug 08, 2009 4:54 pm

Re: View a random topic

Post by kwiatek »

imkingdavid wrote:Hmm... that's not really the purpose of this MOD. This MOD's aim is simply to provide a way for a user to click a link and show up at a random topic. You would need another MOD to do what you're asking.

As far as your request, I'm sure it can be done. I'm not sure exactly how to go about implementing it. And I'm not sure that 50 topics is really a practical number Maybe you meant 5? Or maybe you actually have a reason for needing 50.

In any case, I can look into it, but no promises. :)
Thanks. I need minimum display 15 topics on the main page.
User avatar
all4phone
Registered User
Posts: 593
Joined: Fri Mar 18, 2011 11:56 am
Location: Poland
Name: Piotr
Contact:

Re: View a random topic

Post by all4phone »

I know, old topic, but I haven't found a mod as was requested above.

Some time ago I found a similar mod for phpbb2. So, now I'll try to adjust it to the latest phpbb3 version.
More info in this topic: viewtopic.php?f=70&t=2264576
Locked

Return to “[3.0.x] MOD Requests”