| Author |
Message |
Torstein
Joined: 03 Aug 2006 Posts: 106
|
|
Sort by latest reply |
|
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:
 |  |
<?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 |
|
 |
Guest
|
|
|
Please login to hide the ads.
|
|
|
|
 |
FI-DD
Admin

Joined: 22 Sep 2005 Posts: 2801 Location: Germany |
|
|
|
1. Put this in a new file in the main CuteNews.RU directory and run in once:
 |  | <?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:
 |  | $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:
 |  | $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:
 |  | 'category' => $category, |
to this:
 |  | '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 |
|
 |
Torstein
Joined: 03 Aug 2006 Posts: 106
|
|
|
|
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 |
|
 |
FI-DD
Admin

Joined: 22 Sep 2005 Posts: 2801 Location: Germany |
|
|
|
Yep, that's the way it works now.
|
|
| Fri Jun 22, 2007 1:27 pm |
|
 |
erlendfl
Joined: 10 Jan 2007 Posts: 29
|
|
|
|
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 |
|
 |
FI-DD
Admin

Joined: 22 Sep 2005 Posts: 2801 Location: Germany |
|
|
|
You need to do step #3 in quest.php as well.
|
|
| Fri Oct 31, 2008 2:13 pm |
|
 |
erlendfl
Joined: 10 Jan 2007 Posts: 29
|
|
|
|
 |  | 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 |
|
 |
scottdallas

Joined: 04 May 2006 Posts: 1943 Location: US |
|
|
|
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.
_________________ www.scottdizzle.com uses cnr
last update: 07-22-08: 8:30 pm |
|
| Sun Nov 02, 2008 11:11 pm |
|
 |
erlendfl
Joined: 10 Jan 2007 Posts: 29
|
|
|
|
 |  | 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 
|
|
| Wed Nov 05, 2008 1:51 am |
|
 |
scottdallas

Joined: 04 May 2006 Posts: 1943 Location: US |
|
|
|
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
last update: 07-22-08: 8:30 pm |
|
| Thu Nov 06, 2008 5:51 am |
|
 |
|