Moved & Locked topics at the bottom of the topiclist

A perfect place for code snippets to small to be a MOD or a library.
Or for examples on how to use our libraries.
Post Reply
Elglobo
Past Contributor
Past Contributor
Posts: 120
Joined: 15 Jul 2008, 19:42

Moved & Locked topics at the bottom of the topiclist

Post by Elglobo »

This post was originally posted by Kenny at 6 String MODs.

By following these edits, the locked and moved topics will move to the bottom of the topiclist.

OPEN:
viewforum.php

FIND:

Code: Select all

        // Grab just the sorted topic ids
        $sql = SELECT t.topic_id

ADD AFTER (in-line):

Code: Select all

        , t.topic_status

FIND:

Code: Select all

while ($row = $db->sql_fetchrow($result))
{
    $topic_list[] = (int) $row['topic_id'];
}&
nbsp;  &nbsp

REPLACE WITH:

Code: Select all

$closed_topics = $move_topics = array();

while ($row = $db->sql_fetchrow($result))
{
    if ( $row['topic_status'] == ITEM_MOVED )
    {
        $move_topics[] = (int) $row['topic_id'];
    }
    elseif ( $row['topic_status'] == ITEM_LOCKED )
    {
        $closed_topics[] = (int) $row['topic_id'];
    }
    else
    
{
        $topic_list[] = (int) $row['topic_id'];
    }
}
$topic_list = array_merge($topic_list, $move_topics, $closed_topics);   &nbsp


To hold the moved topics, and let the closed ones only go to the bottom of the topiclist, use the following code (you should follow the code steps, and use the code below instead of the last "Replace With") :)

Code: Select all

$closed_topics = array();
while ($row = $db->sql_fetchrow($result))
{
   if ( $row['topic_status'] == ITEM_LOCKED )
   {
      $closed_topics[] = (int) $row['topic_id'];
   }
   else
   
{
      $topic_list[] = (int) $row['topic_id'];
   }
}
$topic_list = array_merge($topic_list, $closed_topics);   &nbsp
Last edited by Elglobo on 13 Jan 2015, 00:00, edited 2 times in total.
Reason: Minor bug fix
[viziouz]
New member
New member
Posts: 3
Joined: 02 Sep 2009, 21:45

Re: Moved & Locked topics at the bottom of the topiclist

Post by [viziouz] »

One little thing I noticed with this, is that it moves sticky topics too. I have installed the categorize announcements and stickies installed on my board and when I lock a sticky, it moves it under the open topics. Is there a way to prevent this?
User avatar
tumba25
Supporter
Supporter
Posts: 1058
Joined: 24 Oct 2007, 13:10
Real name: Jari Kanerva
Location: Kokkola, Finland.
Contact:

Re: Moved & Locked topics at the bottom of the topiclist

Post by tumba25 »

If you want to keep stickies and announcements on the top, do these edits instead.
Not really tested but it should work. :P

OPEN:
viewforum.php

FIND:

Code: Select all

// Grab just the sorted topic ids
$sql = SELECT t.topic_id

ADD AFTER (in-line):

Code: Select all

, t.topic_status , t.topic_type

FIND:

Code: Select all

while ($row = $db->sql_fetchrow($result))
{
    $topic_list[] = (int) $row['topic_id'];
}&
nbsp;  &nbsp

REPLACE WITH:

Code: Select all

$closed_topics = $move_topics = array();

while ($row = $db->sql_fetchrow($result))
{
    if ( $row['topic_status'] == ITEM_MOVED && $row['topic_type'] == POST_NORMAL )
    {
        $move_topics[] = (int) $row['topic_id'];
    }
    elseif ( $row['topic_status'] == ITEM_LOCKED && $row['topic_type'] == POST_NORMAL )
    {
        $closed_topics[] = (int) $row['topic_id'];
    }
    else
    
{
        $topic_list[] = (int) $row['topic_id'];
    }
}
$topic_list = array_merge($topic_list, $move_topics, $closed_topics);   &nbsp


To hold the moved topics, and let the closed ones only go to the bottom of the topiclist, use the following code (you should follow the code steps, and use the code below instead of the last "Replace With") :)

Code: Select all

$closed_topics = array();
while ($row = $db->sql_fetchrow($result))
{
   if ( $row['topic_status'] == ITEM_LOCKED && $row['topic_type'] == POST_NORMAL )
   {
      $closed_topics[] = (int) $row['topic_id'];
   }
   else
   
{
      $topic_list[] = (int) $row['topic_id'];
   }
}
$topic_list = array_merge($topic_list, $closed_topics);   &nbsp
[viziouz]
New member
New member
Posts: 3
Joined: 02 Sep 2009, 21:45

Re: Moved & Locked topics at the bottom of the topiclist

Post by [viziouz] »

It worked like a charm, tumba25. Sticky moved back to the top of forumview :beer:
Post Reply