News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

New recent posts action pages?

Started by themavesite, April 29, 2017, 09:29:51 AM

Previous topic - Next topic

themavesite

I wish to give users the choice to show all recent posts (default behaviour), or only the new topics or replies.

So the code found in Recent.php to get the most recent posts =

SELECT
m.id_msg, m.subject, m.smileys_enabled, m.poster_time, m.body, m.id_topic, t.id_board, b.id_cat,
b.name AS bname, c.name AS cname, t.num_replies, m.id_member, m2.id_member AS id_first_member,
IFNULL(mem2.real_name, m2.poster_name) AS first_poster_name, t.id_first_msg,
IFNULL(mem.real_name, m.poster_name) AS poster_name, t.id_last_msg
FROM {db_prefix}messages AS m
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
INNER JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
INNER JOIN {db_prefix}messages AS m2 ON (m2.id_msg = t.id_first_msg)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
LEFT JOIN {db_prefix}members AS mem2 ON (mem2.id_member = m2.id_member)
WHERE m.id_msg IN ({array_int:message_list})
ORDER BY m.id_msg DESC
LIMIT ' . count($messages),


I had a look in the database and to only get the new topics I guess you can do

WHERE id_msg = id_last_msg

Or for only the latest replies

WHERE id_first_msg != id_last_msg

This is exactly what I want.. But how do I make these into new actions like action=recentreplies and action=recenttopics?
TMS Forums
Since 2008 and still going strong! Join today! http://forums.themavesite.com/index.php

Kindred

You need to build a new function, a new template,  and add the action into the action array in index.php
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

DreadPirateRoberts

How do you set this code so I can block a board from showing up on "recent posts"
Welcome to Agora Road's Macintosh Cafe || A retro design vaporwave community forum! Enjoy your stay!

vii

You would need to modify the query above it, which fetches the id_msg list that the next query uses for getting the actual content:

Find in Recent.php:


            // Find the 10 most recent messages they can *view*.
            // !!!SLOW This query is really slow still, probably?
            $request = $smcFunc['db_query']('', '
                SELECT m.id_msg
                FROM {db_prefix}messages AS m
                    INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
                WHERE ' . $query_this_board . '
                    AND m.approved = {int:is_approved}
                ORDER BY m.id_msg DESC
                LIMIT {int:offset}, {int:limit}',
                array_merge($query_parameters, array(
                    'is_approved' => 1,
                    'offset' => $_REQUEST['start'],
                    'limit' => 10,
                ))
            );


Change to:


            // Find the 10 most recent messages they can *view*.
            // !!!SLOW This query is really slow still, probably?
            $hideBoards = array(1, 2, 3);
            $request = $smcFunc['db_query']('', '
                SELECT m.id_msg
                FROM {db_prefix}messages AS m
                    INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
                WHERE ' . $query_this_board . '
                    AND m.approved = {int:is_approved}
                    AND m.id_board NOT IN ({array_int:hideBoards})
                ORDER BY m.id_msg DESC
                LIMIT {int:offset}, {int:limit}',
                array_merge($query_parameters, array(
                    'is_approved' => 1,
                    'offset' => $_REQUEST['start'],
                    'limit' => 10,
                    'hideBoards' => $hideBoards,
                ))
            );


Change the numbers in $hideBoards = array(...) to the IDs of whatever boards you wish to hide the posts of.

Advertisement: