1 (edited by 2008-08-14 20:14:51)

Topic: [HACK] Sort By Most Commented/viewed

Name: Sort By most Commented and/or most Viewed.
Author: NyNe
Updated by: FUNimations
CuteNews Compatibility: 1.3.6 - * (no incompatibility reported yet)
Instructions:
Start with installing the Sort By Hack
As these hacks need the sort by hack. http://cutephp.com/forum/style_emoticons/default/wink.gif

find:

}else{ $count_all = count($all_news); }


If you want to sort by most commented news.
add below:

// Top Comments
$comm_count = file($comm_file);
for ($a = 0; $a < sizeof($all_news); $a++) {
    $news_arr = explode("|", $all_news[$a]);
    foreach ($comm_count as $null => $comm_line)
    {
        if (stristr($comm_line, $news_arr[0]))
        {
            $comm_split = explode("|>|", $comm_line);
            $comm_arr = explode("||", $comm_split[1]);
            $com_number = count($comm_arr);
            $news_c[$a] = $com_number-1;
        }
    }
    if( $news_arr[count($news_arr)-1] == "\n" ) unset($news_arr[count($news_arr)-1]);
    $news_arr[count($news_arr)] = $news_c[$a];
    $all_news[$a] = implode( "|", $news_arr);
}
// Top Comments

For the top views sort hack:
Install the following hack Page View Counter
Put the following under the same place as if you where to install the Top Comments, or put it under the top comments hack.

// Top Views
$cn_do = "get";
include_once($cutepath."/counter.php");
for ($a = 0; $a < sizeof($all_news); $a++)
{
    $news_arr = explode("|", $all_news[$a]);
    if( $news_arr[count($news_arr)-1] == "\n" ) unset($news_arr[count($news_arr)-1]);
    if( isset($counter[$news_arr[0]]) )
        $news_arr[count($news_arr)] = implode( "|", $counter[$news_arr[0]]);
    else
        $news_arr[count($news_arr)] = "||||";
    $all_news[$a] = implode( "|", $news_arr);
}
// Top Views


to use thess hacks:
include show_news.php as if you were including headlines
you might want to make a new template that displays {comments-num} that looks just like the headlines template (create a template based on headlines and add {comments-num} to it somewhere)
remember to set $number = "X"; to determine the top X posts that will be shown, and $sortad="d"; to sort in decending order (largest first)
<!--coloro:blue--><span style="color:blue"><!--/coloro-->this part is a bit tricky, because it could be different for everyone[/color]
$sortby is also a parameter you can use now to determine how you must sort.

<? $static=true; $number="5"; $sortby="Y"; $sortad="d"; $template="topcomments"; include("cutenews/show_news.php"); ?>


In this example we used "Y", though this is supposed to be a number. Now if you look back at the sort By hack you see that every number will sort by a different field.

0 = date
1 = sort by author
...
6 = sort by category

6 being the last slot. Though CN add's a 7th empty slot in as well. These hack will add slots. So the first slot on which you can sort will be number 8. If you have the "top comments" hack installed this 8th slot will order by most commented.
The most viewed hack add's 2 slots. view counter & unique views counter.
These would be slot 8 &  9 if you don't have top comments hack. If you do, these slots will move 1 up.
Other hacks that save data in news.txt will have influece on the slots. So note that the slots may move depending on the kind of data saved in news.txt and the order that new data is saved.

Posts: 1

Pages 1

You must login or register to post a reply

CutePHP Forums → Hacks & Tricks / FAQ → [HACK] Sort By Most Commented/viewed