PDA

View Full Version : Single RANDOM news item from specified forum


Milorad
07-25-2004, 12:58 PM
I would like to display (and reformat) a single RANDOM news item from the specified news forum(s)

How would I go about this?

Of course I can do a single news item, its the randomisation I have a problem with. The choice of what to display really should just be a random selection of any thread in that forum ever (no need for date-based constraint)

Any help or hints greatly appreciated.

Milorad
07-28-2004, 02:34 AM
I just want to give this a gentle nudge...

This would do the equivalent of the quote-it module only allowing multiple sources, and obviously editing!

I'm just wondering what would be involved in randomising the thread from which the first post is taken.

Thanks for any comments/advice on this :)

Our Sponsors
 

lee wilde
01-22-2005, 05:15 AM
Its a good idea but I have no clue. Perhaps have a look at how the Random Quote thingie works?

rbl
01-22-2005, 07:30 AM
The fastest way it to hack the news module of your CMPS. If you don't need it, just edit the config to your liking and change forum/modules/news.php in the following way:
Look for this line:
ORDER BY " . iif($vboptions['stickynewsthreads'], 'sticky DESC,') . " postdateline DESC" . iif($vboptions['shownewsattach'], ', attachmentid') . "
$newslimit");
Change to:
ORDER BY RAND() LIMIT 1");
That should do the trick.

If you need that module, you need to make a new one. You can start by duplicating that news.php module.
To edit the layout for that unique random news item, you need a new template.
To randomize the thread you need to edit the query in the module the way it's done above.

Our Sponsors
 

lee wilde
01-22-2005, 03:19 PM
Thanks rbl! That took a couple of minutes and now I have a "random thread" mod. Brilliant.

Do you know if it would be possible to restrict it to just a certain usergroup? ie. pull a random thread started by a member of a particular usergroup.

rbl
01-22-2005, 05:02 PM
Possible? Yes! If birthdays are required and exist in the database, you can also specify the age of the thread starter =) But there's more to it.

Sometimes we get lucky and the table holds the required info. Unfortunately, this is not the case.
The threads table doesn't keep much more info of the thread starter than the username and the userid. To know if that userid belongs to a specific usergroup, you have to query the users table and ask what usergroupid is associated with that userid.
Because you want a random result, first you have to create a selection of eligible threads (where conditions are met) and then pick a random item of that selection.

In terms of coding is not very easy. In terms of resources seems pretty "expensive" for a random thread. Possible? Yes!

But is it worth it?

lee wilde
01-23-2005, 12:29 AM
Thanks rbl, I actually follow that. OK. Right. Too much mucking around for a minor feature. Still, the random thread thingie is cool the way it is.

The Piper
04-13-2005, 08:59 PM
I use the news.php already. I've copied it to another file, changed the code as suggested above, created a template... Added it as an active module, but nothing shows. Any advice?

Also, how could I choose from which forum I wanted the thread to appear?

Finally, could this be done, through three different modules/blocks for three different forums?

I'm not a programmer, so I'd really appreciate any help on this.

The Piper
04-16-2005, 01:11 PM
Bump?

Brian
04-16-2005, 01:31 PM
Because of the way the news module has to be done to make it work with the archive, it takes more than just copying the file and such. I believe there is a hack in the hacks forum with instructions on how to copy the module though.

The Piper
04-17-2005, 03:55 PM
Thanks, Brian. After searching for a bit, I found this thread (http://www.vbadvanced.com/forum/showthread.php?t=4115), which, combined with the hint above by rbl, works like a charm.