Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Thema gestartet von: JayBachatero in Juli 19, 2006, 01:01:05 VORMITTAG

Titel: Limit Recent Posts on BoardIndex to certain boards.
Beitrag von: JayBachatero in Juli 19, 2006, 01:01:05 VORMITTAG
If you want to limit the recent posts on the board index this is how to do it.

In Recent.php find

$request = db_query("
SELECT
m.posterTime, m.subject, m.ID_TOPIC, m.ID_MEMBER, m.ID_MSG,
IFNULL(mem.realName, m.posterName) AS posterName, t.ID_BOARD, b.name AS bName,
LEFT(m.body, 384) AS body, m.smileysEnabled
FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t, {$db_prefix}boards AS b)
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
WHERE m.ID_MSG >= " . max(0, $modSettings['maxMsgID'] - 20 * $showlatestcount) . "
AND t.ID_TOPIC = m.ID_TOPIC
AND b.ID_BOARD = t.ID_BOARD" . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? "
AND b.ID_BOARD != $modSettings[recycle_board]" : '') . "
AND $user_info[query_see_board]
ORDER BY m.ID_MSG DESC
LIMIT $showlatestcount", __FILE__, __LINE__);


Replace with


// Board to show
$boards_to_show = array(6,7,16);

$request = db_query("
SELECT
m.posterTime, m.subject, m.ID_TOPIC, m.ID_MEMBER, m.ID_MSG,
IFNULL(mem.realName, m.posterName) AS posterName, t.ID_BOARD, b.name AS bName,
LEFT(m.body, 384) AS body, m.smileysEnabled
FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t, {$db_prefix}boards AS b)
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
WHERE m.ID_MSG >= " . max(0, $modSettings['maxMsgID'] - 20 * $showlatestcount) . "
AND t.ID_TOPIC = m.ID_TOPIC
AND b.ID_BOARD = t.ID_BOARD" . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? "
AND b.ID_BOARD != $modSettings[recycle_board]" : '') . "
AND (FIND_IN_SET(" . implode(', t.ID_BOARD) OR FIND_IN_SET(', $boards_to_show) . ", t.ID_BOARD))
AND $user_info[query_see_board]
ORDER BY m.ID_MSG DESC
LIMIT $showlatestcount", __FILE__, __LINE__);


Change $boards_to_show to the id of the boards that you want to show.  Separate each id with a ,
Titel: Re: Limit Recent Posts on BoardIndex to certain boards.
Beitrag von: Stuart in Juli 20, 2006, 02:41:19 NACHMITTAGS
This is very useful, thanks Jay  ;D
Titel: Re: Limit Recent Posts on BoardIndex to certain boards.
Beitrag von: Stüldt Håjt in September 29, 2006, 08:12:00 VORMITTAG
Is it possible to change so I can limit boards not to show? It would be much easier to limit this one board to not to show posts. So when I create a new board I don't have to edit this.
Titel: Re: Limit Recent Posts on BoardIndex to certain boards.
Beitrag von: JayBachatero in September 29, 2006, 11:20:23 VORMITTAG
Ok you can try this


$boards_to_hide = array(6,7,16);

$request = db_query("
SELECT
m.posterTime, m.subject, m.ID_TOPIC, m.ID_MEMBER, m.ID_MSG,
IFNULL(mem.realName, m.posterName) AS posterName, t.ID_BOARD, b.name AS bName,
LEFT(m.body, 384) AS body, m.smileysEnabled
FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t, {$db_prefix}boards AS b)
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
WHERE m.ID_MSG >= " . max(0, $modSettings['maxMsgID'] - 20 * $showlatestcount) . "
AND t.ID_TOPIC = m.ID_TOPIC
AND b.ID_BOARD = t.ID_BOARD" . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? "
AND b.ID_BOARD != $modSettings[recycle_board]" : '') . "
AND t.ID_BOARD NOT IN (" . implode(',', $board_to_hide) . ")
AND $user_info[query_see_board]
ORDER BY m.ID_MSG DESC
LIMIT $showlatestcount", __FILE__, __LINE__);
Titel: Re: Limit Recent Posts on BoardIndex to certain boards.
Beitrag von: Stüldt Håjt in September 29, 2006, 02:27:05 NACHMITTAGS
This comes with 1.1RC3. No mods installed..

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')
AND 1
ORDER BY m.ID_MSG DESC
LIMIT 5' at line 11
Tiedosto: /var/www/Sources/Recent.php
Rivi: 104


And in error log:

Tietokantavirhe: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')
AND (FIND_IN_SET(0, b.memberGroups) OR FIND_IN_SET(6, b.me
Tiedosto: /var/www/Sources/Recent.php
Rivi: 104


2: implode(): Bad arguments.
Tiedosto: /var/www/Sources/Recent.php
Rivi: 101


8: Undefined variable: board_to_hide
Tiedosto: /var/www/Sources/Recent.php
Rivi: 101
Titel: Re: Limit Recent Posts on BoardIndex to certain boards.
Beitrag von: JayBachatero in September 29, 2006, 02:35:12 NACHMITTAGS
Oops small typeo.


$boards_to_hide = array(6,7,16);

$request = db_query("
SELECT
m.posterTime, m.subject, m.ID_TOPIC, m.ID_MEMBER, m.ID_MSG,
IFNULL(mem.realName, m.posterName) AS posterName, t.ID_BOARD, b.name AS bName,
LEFT(m.body, 384) AS body, m.smileysEnabled
FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t, {$db_prefix}boards AS b)
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
WHERE m.ID_MSG >= " . max(0, $modSettings['maxMsgID'] - 20 * $showlatestcount) . "
AND t.ID_TOPIC = m.ID_TOPIC
AND b.ID_BOARD = t.ID_BOARD" . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? "
AND b.ID_BOARD != $modSettings[recycle_board]" : '') . "
AND t.ID_BOARD NOT IN (" . implode(',', $boards_to_hide) . ")
AND $user_info[query_see_board]
ORDER BY m.ID_MSG DESC
LIMIT $showlatestcount", __FILE__, __LINE__);
Titel: Re: Limit Recent Posts on BoardIndex to certain boards.
Beitrag von: Stüldt Håjt in September 29, 2006, 03:52:47 NACHMITTAGS
Thanks alot. Works great!
Titel: Re: Limit Recent Posts on BoardIndex to certain boards.
Beitrag von: pisdoktor in November 26, 2006, 10:30:14 NACHMITTAGS
good works ;) but i want to add time limit. (for example: recent post in last 12 hours, recent posts in today, recent post in yesterday, recent post last week...) what do you do?
Titel: Re: Limit Recent Posts on BoardIndex to certain boards.
Beitrag von: JayBachatero in November 26, 2006, 10:32:24 NACHMITTAGS
Well it wouldn't be as simple as this one but it can be done.  I'll add it to my mod todo list.  Mind you it's a VERY long list so I might not do this one right away.
Titel: Re: Limit Recent Posts on BoardIndex to certain boards.
Beitrag von: Saku in Januar 10, 2007, 04:12:26 NACHMITTAGS
How to do the same on unread posts
http://www.simplemachines.org/community/index.php?action=unread
Titel: Re: Limit Recent Posts on BoardIndex to certain boards.
Beitrag von: ckgb in März 17, 2007, 03:43:32 NACHMITTAGS
I second the previous post.

Also how about the same for Recent topic list?
Titel: Re: Limit Recent Posts on BoardIndex to certain boards.
Beitrag von: JayBachatero in März 19, 2007, 08:55:32 VORMITTAG
Do a search.  I think someone posted how to do it.
Titel: Re: Limit Recent Posts on BoardIndex to certain boards.
Beitrag von: Vandetta in August 15, 2009, 08:47:01 NACHMITTAGS
Zitat von: JayBachatero in September 29, 2006, 02:35:12 NACHMITTAGS
Oops small typeo.


$boards_to_hide = array(6,7,16);

$request = db_query("
SELECT
m.posterTime, m.subject, m.ID_TOPIC, m.ID_MEMBER, m.ID_MSG,
IFNULL(mem.realName, m.posterName) AS posterName, t.ID_BOARD, b.name AS bName,
LEFT(m.body, 384) AS body, m.smileysEnabled
FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t, {$db_prefix}boards AS b)
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
WHERE m.ID_MSG >= " . max(0, $modSettings['maxMsgID'] - 20 * $showlatestcount) . "
AND t.ID_TOPIC = m.ID_TOPIC
AND b.ID_BOARD = t.ID_BOARD" . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? "
AND b.ID_BOARD != $modSettings[recycle_board]" : '') . "
AND t.ID_BOARD NOT IN (" . implode(',', $boards_to_hide) . ")
AND $user_info[query_see_board]
ORDER BY m.ID_MSG DESC
LIMIT $showlatestcount", __FILE__, __LINE__);


I'm a bit of a script kiddie. How do I get this working on SMF 2.0 since the code is different. I spent hours reading though stuff I used notepad++ to see that you added 

  $boards_to_hide = array(6,7,16);


   AND t.ID_BOARD NOT IN (" . implode(',', $boards_to_hide) . ")

This is exactly what I want to do. I'd like to hide or exclude only one board from recent posts.  I understand (6,7,16) refers to 3 boards and that I'd only have to ad one board id there. Where do I add it in SMF 2.0 though?
Titel: Re: Limit Recent Posts on BoardIndex to certain boards.
Beitrag von: Arantor in September 21, 2009, 04:58:21 VORMITTAG
Is this still an issue for you, Vandetta? This may have been covered in another thread for 2.0 by now, but if not what exactly do you want to hide from where?
Titel: Re: Limit Recent Posts on BoardIndex to certain boards.
Beitrag von: rikmoncur in Juni 17, 2011, 10:58:54 VORMITTAG
As Vandetta has asked, I too would like to know how to do this on SMF 2.0 Core theme
Titel: Re: Limit Recent Posts on BoardIndex to certain boards.
Beitrag von: retroturk in Januar 12, 2014, 05:06:02 VORMITTAG
Great little mod...Thanks a lot...I looked for this ages...thanks

ps. I want to show topics intead of posts on recent posts section, but I hope I can solve that...