Forum Index
RegisterSearchFAQMemberlistUsergroupsLog in
Sort by latest reply

 
Reply to topic    Forum Index » Suggestions View previous topic
View next topic
Sort by latest reply
Author Message
Torstein



Joined: 03 Aug 2006
Posts: 106

Post Sort by latest reply Reply with quote
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:

<?php
$number = "20";
$category = "Forum";
$sort = array ('latest_reply', 'DESC');
include ('show_news.php');
?>


Is there any way to do this?
Mon Jun 11, 2007 1:25 pm View user's profile Send private message
Guest








Please login to hide the ads.

FI-DD
Admin


Joined: 22 Sep 2005
Posts: 2801
Location: Germany

Post Reply with quote
1. Put this in a new file in the main CuteNews.RU directory and run in once:
Code:
<?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:
$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:
$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:
'category' => $category,


to this:
Code:
'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
Wed Jun 13, 2007 4:57 pm View user's profile Send private message
Torstein



Joined: 03 Aug 2006
Posts: 106

Post Reply with quote
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?
Mon Jun 18, 2007 9:28 pm View user's profile Send private message
FI-DD
Admin


Joined: 22 Sep 2005
Posts: 2801
Location: Germany

Post Reply with quote
Yep, that's the way it works now.
Fri Jun 22, 2007 1:27 pm View user's profile Send private message
erlendfl



Joined: 10 Jan 2007
Posts: 29

Post Reply with quote
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!
Fri Oct 31, 2008 2:27 am View user's profile Send private message
FI-DD
Admin


Joined: 22 Sep 2005
Posts: 2801
Location: Germany

Post Reply with quote
You need to do step #3 in quest.php as well.
Fri Oct 31, 2008 2:13 pm View user's profile Send private message
erlendfl



Joined: 10 Jan 2007
Posts: 29

Post Reply with quote
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...
Sat Nov 01, 2008 12:56 am View user's profile Send private message
scottdallas



Joined: 04 May 2006
Posts: 1943
Location: US

Post Reply with quote
This seems to be working/functioning quite well. Thanks FI-DD Smile

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.

_________________
www.scottdizzle.com uses cnr Smile
last update: 07-22-08: 8:30 pm
Sun Nov 02, 2008 11:11 pm View user's profile Send private message Visit poster's website AIM Address
erlendfl



Joined: 10 Jan 2007
Posts: 29

Post Reply with quote
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
Wed Nov 05, 2008 1:51 am View user's profile Send private message
scottdallas



Joined: 04 May 2006
Posts: 1943
Location: US

Post Reply with quote
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.

_________________
www.scottdizzle.com uses cnr Smile
last update: 07-22-08: 8:30 pm
Thu Nov 06, 2008 5:51 am View user's profile Send private message Visit poster's website AIM Address
Display posts from previous:    
Reply to topic    Forum Index » Suggestions All times are GMT + 1 Hour
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum



Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Music Lyrics.