PDA

View Full Version : Show most popular thread on index page


Scott MacVicar
08-17-2001, 10:00 PM
This is probably too small to qualify has a hack but i've seen one or two posts looking for it. This finds the most popular thread on the board.

Open index.php and before
// get total posts
$countposts=$DB_site->query_first('SELECT COUNT(*) AS posts FROM post');

add either of the following depending on what you want to be picked as most popular.

//Most Popular Thread by Replies
$popular=$DB_site->query_first("SELECT * FROM thread ORDER by replycount DESC LIMIT 1");

//Most Popular Thread by Views
$popular=$DB_site->query_first("SELECT * FROM thread ORDER by views DESC LIMIT 1");

then below that add the following
eval("\$popularthread = \"".gettemplate("popular_thread")."\";");

save index.php and upload.

Then within the control panel click add templates.

Template name is popular_thread
and the code should be this
Most popular thread is <a href="showthread.php?s=$session[sessionhash]&threadid=$popular[threadid]">$popular[title]</a>

Then in either of your forumhome templates place $popularthread and the text "Most populat thread is THREADTITLE"
the threadtitle will be a link to the title.

maverick1236
08-19-2001, 12:00 AM
doesnt show up in forum home :(

Reef Board
08-19-2001, 07:16 AM
Same here - doesn't work for me, either.

Phil~

Mobile
08-19-2001, 10:20 AM
nice one PPN works fine, take a look http://www.skytronic-forums.com/forum/

ltr Mobile

inetd
08-19-2001, 10:37 AM
don't work...
please fix bug's... :(

Scott MacVicar
08-19-2001, 11:06 AM
Are you getting any error messages at all?

i've installed it twice on other boards and it worked fine. Another person pasted in both lines for getting most popular. Ie the one for popular by reply and the popular by views. Make sure you only paste one of them in.

inetd
08-19-2001, 12:00 PM
Ok. Thx! All work! Fine work!
You could not make Show most popular thread on index page at present (at the rate of 24 hours)?

dwh
08-22-2001, 06:02 AM
Not a bad idea but I think I'll skip this one. The one weakness to the linear style bulletin board is that once you go beyond one page it's much harder to read and manage than threaded bbs'es or some other style bbs'es (it does exist). On my board this would just encourage people to make those monster threads even more unmanageable.

maverick1236
08-25-2001, 12:55 PM
all code is correct

just doesnt show up!?

weird....

:)

pgowder
11-05-2001, 02:56 PM
How can I use this on a non vb page?

Scott MacVicar
11-05-2001, 03:04 PM
Is the nonvb page Perl, PHP or ASP??
or are you wishing to call it via SSI.

pgowder
11-05-2001, 03:15 PM
I would prefer a ssi call, but I can make the page php if I need to.

Scott MacVicar
11-05-2001, 04:04 PM
simpliest way is if the page is php


//connect to database
mysql_connect("localhost", "YOURUSERNAME", "YOURPASS");
mysql_select_db("YOURFORUMSDATABASE");
//select thread information
$popular=mysql_fetch_array(mysql_query("SELECT * FROM thread ORDER by replycount DESC LIMIT 1"));
mysql_close();

$popular="Most popular thread is <a href=\"http://forums.site.com/showthread.php?s=$session[sessionhash]&threadid=$popular[threadid]\">$popular[title]</a>";


then just place $popular somewhere on your page and it will say like
Most popular thread is Some Title Here and the title will be a link to the thread.

pgowder
11-05-2001, 05:23 PM
That did it.

Now, how could I have it include the top 5 most popular??

I want to have a box on my front page with the top 5 threads.

thanks

Scott MacVicar
11-05-2001, 06:05 PM
//connect to database
mysql_connect("localhost", "YOURUSERNAME", "YOURPASS");
mysql_select_db("YOURFORUMSDATABASE");
//select thread information
$query=mysql_query("SELECT * FROM thread ORDER by replycount DESC LIMIT 5");
while($pop=mysql_fetch_array($query)) {
$popular.="<a href=\"http://forums.site.com/showthread.php?s=&threadid=$pop[threadid]\">$pop[title]</a><br>";
}
mysql_close();


Use $popular list the top 5 threads with a line break seperating them adjust as you wish.

cityofangelus
12-10-2001, 01:12 PM
Great hack really like this one.

Work perfectly thanks :)

Lesane
12-13-2001, 02:39 PM
Great Hack PPN, i luv it but i had the "Show most popular thread" in a table and my most popular thread has a very long title, more then 40 characters so i reduced it 2 25. If someone is interested, here it is: :)

root/index.php

find:
$popular=$DB_site->query_first("SELECT * FROM thread ORDER by replycount DESC LIMIT 1");

Under that add:
if (strlen($popular[title]) > 25) {
$title = substr($popular[title],0,25);
$title .= "...";
} else {
$title = $popular[title];
}

Then find in popular_thread thread:
Most popular thread is <a href="showthread.php?s=$session[sessionhash]&threadid=$popular[threadid]">$popular[title]</a>

and change it to:
Most popular thread is <a href="showthread.php?s=$session[sessionhash]&threadid=$popular[threadid]">$title</a>

Now with this there will be 25 characters displayed of the Most Popular thread, ofcourse you can change that to your size.

musicfreak12399
06-21-2002, 10:29 PM
Is there a way to do this hack for any specific forum? Because that would be really great for my board if there was a way to do that

Chris M
06-22-2002, 11:05 AM
Sounds like a great hack!!!

Nice PPN...

And great idea Lesane!!!

Definately installing this one...

Satan

musicfreak12399
06-22-2002, 11:29 PM
no one has ansewer to my question? im sure there is a way to do it, but i do not know how...

Is there a way to do this hack for any specific forum? Because that would be really great for my board if there was a way to do that

Boofo
06-22-2002, 11:56 PM
Can you do both of these at the same time?

Originally posted by PPN
//Most Popular Thread by Replies
$popular=$DB_site->query_first("SELECT * FROM thread ORDER by replycount DESC LIMIT 1");

//Most Popular Thread by Views
$popular=$DB_site->query_first("SELECT * FROM thread ORDER by views DESC LIMIT 1");

Exactly how would you insert this?

Then in either of your forumhome templates place $popularthread and the text "Most populat thread is THREADTITLE"
the threadtitle will be a link to the title.

musicfreak12399
06-23-2002, 03:25 AM
have it like this

//Most Popular Thread by Replies
$popularreply=$DB_site->query_first("SELECT * FROM thread ORDER by replycount DESC LIMIT 1");


//Most Popular Thread by Views
$popularview=$DB_site->query_first("SELECT * FROM thread ORDER by views DESC LIMIT 1");


Template Change
Most popular thread by reply is <a href="showthread.php?s=$session[sessionhash]&threadid=$popularreply[threadid][threadid]">$popularreply[title]</a>


Most popular thread by views is <a href="showthread.php?s=$session[sessionhash]&threadid=$popularview[threadid][threadid]">$popularview[title]</a>

Boofo
06-23-2002, 03:39 AM
Thanks but I still don't understand quite yet. What about the eval part that goes under it? Don't I need 2 of them? And what do I call the templates? Can you give me the complete code with this stuff in it, please? :) And is there any way to incorporate Lesane's addon for the character limit in these?

Originally posted by musicfreak12399
have it like this

//Most Popular Thread by Replies
$popularreply=$DB_site->query_first("SELECT * FROM thread ORDER by replycount DESC LIMIT 1");


//Most Popular Thread by Views
$popularview=$DB_site->query_first("SELECT * FROM thread ORDER by views DESC LIMIT 1");


Template Change
Most popular thread by reply is <a href="showthread.php?s=$session[sessionhash]&threadid=$popularreply[threadid][threadid]">$popularreply[title]</a>


Most popular thread by views is <a href="showthread.php?s=$session[sessionhash]&threadid=$popularview[threadid][threadid]">$popularview[title]</a>

Boofo
06-23-2002, 05:42 AM
How could I do this for the following code?

//Most Popular Thread by Replies
$popularreply=$DB_site->query_first("SELECT * FROM thread ORDER by replycount DESC LIMIT 1");

//Most Popular Thread by Views
$popularview=$DB_site->query_first("SELECT * FROM thread ORDER by views DESC LIMIT 1");

Originally posted by Lesane
Great Hack PPN, i luv it but i had the "Show most popular thread" in a table and my most popular thread has a very long title, more then 40 characters so i reduced it 2 25.

Boofo
06-23-2002, 05:45 AM
musicfreak12399,

I figured it out. Instead of making any templates, I just used the template code you gave directly in the forum home template. I put the first 2 parts in the index.php and that last 2 lines of code in the forumhome template. Is that what you meant?

Boofo
08-03-2002, 09:33 PM
Is there any way to make these so they won't show a private forum or thread?

Snapperhaed
03-27-2003, 02:12 AM
Nice Hack thanks. Installed on v2.3 #3 Easily. The code I used was that which was posted by 'musicfreak12399' above. There is a slight code difference.

On the forum home template, you will note that his code has an extra: '[threadid]' on it - While it will work that way, its not correct. Just remove it from the end and you should be fine.

Thanks!