Sort by latest reply

Post your suggestions for the script here.

Sort by latest reply

Postby Torstein » Mon Jun 11, 2007 1:25 pm

I'm thinking of making a forum out of a few categories on my CNR installation, and for it to function as a normal forum, I'd like to sort the news (forum topics) by latest reply.

Something like:
Code: Select all
<?php
$number = "20";
$category = "Forum";
$sort = array ('latest_reply', 'DESC');
include ('show_news.php');
?>


Is there any way to do this?
Torstein
 
Posts: 292
Joined: Thu Aug 03, 2006 11:19 pm

Postby FI-DD » Wed Jun 13, 2007 4:57 pm

1. Put this in a new file in the main CuteNews.RU directory and run in once:
Code: Select all
<?php
include('./head.php');

$sql->altertable(array(
         'table'     => 'news',
         'name'     => 'latest_comment',
         'action'  => 'insert',
         'values'  =>  array(
                         'type'      =>   'int',
                         'default'   =>   '0'
                        )
         ));

?>

Delete this file after running it.

2. Open inc/show.addcomment.php and change this:
Code: Select all
$sql->update(array(
'table'    => 'news',
'where'    => array("id = $id"),
'values' => array('comments' => count($sql->select(array('table' => 'comments', 'where' => array("post_id = $id")))))
));


to this:
Code: Select all
$sql->update(array(
'table'    => 'news',
'where'    => array("id = $id"),
'values' => array('comments' => count($sql->select(array('table' => 'comments', 'where' => array("post_id = $id")))),
               'latest_comment' => $time

            )
));


3. Open inc/mod/addnews.mdu and change this:
Code: Select all
'category' => $category,


to this:
Code: Select all
'category' => $category,
'latest_comment' => $added_time,


4. Now you can use $sort = array('latest_comment', 'DESC'); in your include code.
Last edited by FI-DD on Fri Jun 22, 2007 1:26 pm, edited 1 time in total.
User avatar
FI-DD
Admin
 
Posts: 2971
Joined: Thu Sep 22, 2005 11:27 am
Location: Germany

Postby Torstein » Mon Jun 18, 2007 9:28 pm

Sorry for asking this before actually trying the code, but will this make the initial post count as a reply?

I mean if a thread has no replies, but was posted after the last reply in some other thread, will the thread with no replies still be displayed above the other?
Torstein
 
Posts: 292
Joined: Thu Aug 03, 2006 11:19 pm

Postby FI-DD » Fri Jun 22, 2007 1:27 pm

Yep, that's the way it works now.
User avatar
FI-DD
Admin
 
Posts: 2971
Joined: Thu Sep 22, 2005 11:27 am
Location: Germany

Postby erlendfl » Fri Oct 31, 2008 2:27 am

HellO!
Tried this mod, and it works perfectly.
Only one problem, when I combine this with the guest-can-add-news-hack the guest-added news shows up at the bottom, not on top.
I don't have that problem when I publish new articles from the admin-panel into the same include-code. I've tried figure it out, but all I'm doing is messing up the code.

Thanks for all your help!
erlendfl
 
Posts: 50
Joined: Wed Jan 10, 2007 1:25 pm

Postby FI-DD » Fri Oct 31, 2008 2:13 pm

You need to do step #3 in quest.php as well.
User avatar
FI-DD
Admin
 
Posts: 2971
Joined: Thu Sep 22, 2005 11:27 am
Location: Germany

Postby erlendfl » Sat Nov 01, 2008 12:56 am

FI-DD wrote:You need to do step #3 in quest.php as well.

Yes, I've already done that. But you see the problem is not if I post a comment there, it is when I just post news-articles from guest.php. If I use standard include-codes it is not a problem...
erlendfl
 
Posts: 50
Joined: Wed Jan 10, 2007 1:25 pm

Postby scottdallas » Sun Nov 02, 2008 11:11 pm

This seems to be working/functioning quite well. Thanks FI-DD :)

One thing that might be relevant to keep in mind while adding this to your cutenews.ru installation is that if you already have comments on your website they will not show up using this method of sorting. Only comments made AFTER this patch has been applied will follow these new rules. This is due to the new mysql stuff FI-DD did.
Everyday I'm tumblin http://scodal.tumblr.com
User avatar
scottdallas
 
Posts: 2209
Joined: Thu May 04, 2006 6:46 pm
Location: US

Postby erlendfl » Wed Nov 05, 2008 1:51 am

erlendfl wrote:HellO!
Tried this mod, and it works perfectly.
Only one problem, when I combine this with the guest-can-add-news-hack the guest-added news shows up at the bottom, not on top.
I don't have that problem when I publish new articles from the admin-panel into the same include-code. I've tried figure it out, but all I'm doing is messing up the code.

Thanks for all your help!

Weird, I removed and added som code over and over again, and it suddenly worked. So problem solved :wink:
erlendfl
 
Posts: 50
Joined: Wed Jan 10, 2007 1:25 pm

Postby scottdallas » Thu Nov 06, 2008 5:51 am

Haha I like your approach. Similar to murdering someone. Okay, I've been watching too much CSI. I just imagine you bashing your FTP repeatedly with the same file until it's finally a bloody mess and says okay fine I give up. You win.

Glad it's working.
Everyday I'm tumblin http://scodal.tumblr.com
User avatar
scottdallas
 
Posts: 2209
Joined: Thu May 04, 2006 6:46 pm
Location: US


Return to Suggestions



Who is online

Users browsing this forum: No registered users and 0 guests

cron