TinyPortal
Development => Support => Topic started by: Inge Jones on February 08, 2013, 12:18:23 PM
My front page is front-type = forum_selected_articles. I can see that the list of topics promoted to front page is in den_tp_settings in an entry named frontpage_topics.
I would like to change the code so they display last added first displayed.
I am editing TPortal.php which is the file that appears to deal with the retrieving and sorting of these. I have removed "Order by date DESC" from several places. I have also commented out ksort($posts, SORT_NUMERIC); in the hopes of preserving the order held in the database.
They're still being shown newest first :D So that I can check whether I've missed a sort or order by, would it be possible to let me know how many places this happens? I am purely interested in code affecting topics promoted from within the forum, although I don't mind at all if this also affects other listings (apart from recent posts from SSI which I do prefer sorted by date)
I think in TPortal.php all you have to change is the first query that grabs the topics. It's sorting them descending by the id of the first message in the topic. If you remove the DESC then it should automatically sort by ASC.
This is the relevant code I think.
$request = $smcFunc['db_query']('', '
SELECT t.id_first_msg as ID_FIRST_MSG
FROM ({db_prefix}topics as t, {db_prefix}boards as b)
WHERE t.id_board = b.id_board
AND t.id_topic IN(' . (empty($context['TPortal']['frontpage_topics']) ? 0 : '{raw:topics}') .')
' . ($context['TPortal']['allow_guestnews'] == 0 ? 'AND {query_see_board}' : '') . '
ORDER BY t.id_first_msg DESC',
array(
'topics' => $context['TPortal']['frontpage_topics']
)
);
Sorry was on wrong line... will post again
Later: Actually that snippet you took wasn't in the right "if" for forum_selected_articles. But I adjusted the right one and it wasn't enough as it gets sorted in date order and message order loads more times before it displays. What I am planning to do therefore is store the frontpage_topics database entry and also Select topic id with the messages, and then reorder them at the last moment. Hope it works...
This works:
$promotedList = explode(',',$context['TPortal']['frontpage_topics']);
$ijposts = array();
foreach($promotedList as $topic)
{
$row = $posts[$topic];
$ijposts[$row['date'].'0' . sprintf("%06s", $posts[$topic])] = $row;
}
$all = array_reverse($ijposts);
instead of the final ksort.