TinyPortal

Development => Block Codes => Topic started by: khandra on October 26, 2006, 04:54:16 PM

Title: Most rated articles
Post by: khandra on October 26, 2006, 04:54:16 PM
A very quick mod to show a list of the 5 (in this case) most viewed articles. Note that articles must have view count enabled to be shows here. The title is cut to 30 chars of length.
To change the number of articles modify "LIMIT 5" with your number.


$request = db_query("SELECT * FROM smf_tp_articles WHERE approved = 1 AND off = 0 ORDER BY rating DESC LIMIT 5", __FILE__, __LINE__);
if (mysql_num_rows($request) > 0)
{
  while($row = mysql_fetch_assoc($request)){
    if(strstr($row['options'], 'rating') != FALSE)
    {
      echo '<a href="' . $scripturl . '?page='.$row['id'].'">'.substr($row['subject'], 0, 30).'</a>';
      echo "<br>";
    }
  }
}


Hope this helps!
Title: Re: Most rated articles
Post by: Assistance on October 27, 2006, 09:21:40 PM
it dont show the rate tho :(
Title: Re: Most rated articles
Post by: khandra on October 30, 2006, 07:53:34 AM
No, it does not! It just show an hyperlink to the article. I do not need the rate too. But it is easy to add:
Modify this code:
echo '<a href="' . $scripturl . '?page='.$row['id'].'">'.substr($row['subject'], 0, 30).'</a>';
      echo "<br>";

with:

echo '<a href="' . $scripturl . '?page='.$row['id'].'">'.substr($row['subject'], 0, 30).'</a>: '.$row['rating'];
      echo "<br>";

I have not tested this last code, but I hope it works.
Title: Re: Most rated articles
Post by: knat on October 30, 2006, 03:36:12 PM
Where do i enable viewcount for articles ?

I can see inside the article how many viewed it but i cant get the code to show  :-\
Title: Re: Most rated articles
Post by: koolaid on March 02, 2008, 02:32:30 AM
Quote from: khandra on October 30, 2006, 07:53:34 AM
No, it does not! It just show an hyperlink to the article. I do not need the rate too. But it is easy to add:
Modify this code:
echo '<a href="' . $scripturl . '?page='.$row['id'].'">'.substr($row['subject'], 0, 30).'</a>';
      echo "<br>";

with:

echo '<a href="' . $scripturl . '?page='.$row['id'].'">'.substr($row['subject'], 0, 30).'</a>: '.$row['rating'];
      echo "<br>";

I have not tested this last code, but I hope it works.

The above code doesn't show the rating. Anyone know how to get it to show the rating as well?
Title: Re: Most rated articles
Post by: Ken. on March 02, 2008, 03:10:53 AM
koolaid this topic is more than one year old and the information here is no longer valid. Please do a search for your question and you'll find your answer.

Another way would be to simply explore the article controls in your admin panel because that would also give you your answer.



Please Note:
This topic is over one year old so if you have a similar question please do a search or start a new topic.