Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: JayBachatero on July 19, 2006, 01:01:05 AM

Title: Limit Recent Posts on BoardIndex to certain boards.
Post by: JayBachatero on July 19, 2006, 01:01:05 AM
If you want to limit the recent posts on the board index this is how to do it.

In Recent.php find
Code: [Select]
$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

Code: [Select]
// 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 ,
Title: Re: Limit Recent Posts on BoardIndex to certain boards.
Post by: Stuart on July 20, 2006, 02:41:19 PM
This is very useful, thanks Jay  ;D
Title: Re: Limit Recent Posts on BoardIndex to certain boards.
Post by: Stüldt Håjt on September 29, 2006, 08:12:00 AM
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.
Title: Re: Limit Recent Posts on BoardIndex to certain boards.
Post by: JayBachatero on September 29, 2006, 11:20:23 AM
Ok you can try this

Code: [Select]
$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__);
Title: Re: Limit Recent Posts on BoardIndex to certain boards.
Post by: Stüldt Håjt on September 29, 2006, 02:27:05 PM
This comes with 1.1RC3. No mods installed..

Code: [Select]
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:

Code: [Select]
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

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

Code: [Select]
8: Undefined variable: board_to_hide
Tiedosto: /var/www/Sources/Recent.php
Rivi: 101
Title: Re: Limit Recent Posts on BoardIndex to certain boards.
Post by: JayBachatero on September 29, 2006, 02:35:12 PM
Oops small typeo.

Code: [Select]
$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__);
Title: Re: Limit Recent Posts on BoardIndex to certain boards.
Post by: Stüldt Håjt on September 29, 2006, 03:52:47 PM
Thanks alot. Works great!
Title: Re: Limit Recent Posts on BoardIndex to certain boards.
Post by: pisdoktor on November 26, 2006, 10:30:14 PM
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?
Title: Re: Limit Recent Posts on BoardIndex to certain boards.
Post by: JayBachatero on November 26, 2006, 10:32:24 PM
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.
Title: Re: Limit Recent Posts on BoardIndex to certain boards.
Post by: Saku on January 10, 2007, 04:12:26 PM
How to do the same on unread posts
http://www.simplemachines.org/community/index.php?action=unread
Title: Re: Limit Recent Posts on BoardIndex to certain boards.
Post by: ckgb on March 17, 2007, 03:43:32 PM
I second the previous post.

Also how about the same for Recent topic list?
Title: Re: Limit Recent Posts on BoardIndex to certain boards.
Post by: JayBachatero on March 19, 2007, 08:55:32 AM
Do a search.  I think someone posted how to do it.
Title: Re: Limit Recent Posts on BoardIndex to certain boards.
Post by: Vandetta on August 15, 2009, 08:47:01 PM
Oops small typeo.

Code: [Select]
$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?
Title: Re: Limit Recent Posts on BoardIndex to certain boards.
Post by: Arantor on September 21, 2009, 04:58:21 AM
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?
Title: Re: Limit Recent Posts on BoardIndex to certain boards.
Post by: rikmoncur on June 17, 2011, 10:58:54 AM
As Vandetta has asked, I too would like to know how to do this on SMF 2.0 Core theme
Title: Re: Limit Recent Posts on BoardIndex to certain boards.
Post by: retroturk on January 12, 2014, 05:06:02 AM
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...