Author Topic: How to call up topics from a selected board, using smf simple portal block  (Read 3438 times)

0 Members and 1 Guest are viewing this topic.

Offline mfoniso

How to call up topics from a selected board, using smf simple portal block.
This is a simple tutorial that will show you how you can call up topics from any discussion board of your choice in your forum,
using smf simple portal block.
To do this, you will have to create a php block on your simple portal, and then copy the code bellow into it. Note this work with smf 2.0.X series.
Code: [Select]
global $smcFunc, $scripturl, $modSettings;

$id_board = 1;

$request = $smcFunc['db_query']('', '
SELECT t.id_topic, m.subject
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
WHERE t.id_board = {int:board}' . ($modSettings['postmod_active'] ? '
AND t.approved = {int:approved}
AND m.approved = {int:approved}' : '') . '
ORDER BY m.subject',
array(
'board' => $id_board,
'approved' => 1,
)
);
$topics = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$topics[$row['id_topic']] = $row['subject'];
$smcFunc['db_free_result']($request);

echo '
<ul>';

if (empty($topics))
{
echo '
<li>There aren\'t any topics.</li>';
}
else
{
foreach ($topics as $id => $subject)
echo '
<li><a href="', $scripturl, '?topic=', $id, '.0">', $subject, '</a></li>';
}

echo '
</ul>';


Once you have don this, remember to change the $id_board as the id of the board you want to fetch topics from.

1. If you want to limit the topics:
(Find)
Code: [Select]
 
ORDER BY m.subject',

(Replace)
Code: [Select]
ORDER BY m.subject
LIMIT {int:limit}',

 (Find)
Code: [Select]

'approved' => 1,

(Replace)
Code: [Select]
'approved' => 1,
'limit' => 10,

2. If you want to change the sort order to the newest first:
(Find)
Code: [Select]
 
ORDER BY m.subject

(Replace)
Code: [Select]
ORDER BY t.id_topic DESC

I hope this was useful,
« Last Edit: January 29, 2014, 01:59:05 PM by mfoniso »


Please do not PM me questions, ask all your questions in the forum, for others to learn from.

All Student Forum


Offline lola

i tried this code.... and the posts appeared from a particular board.....

Please is there a way to make the posts go to the middle..... and also is there a way to add my own topics without the post published on the particular board
Nobody is Useless

Offline mfoniso

Quote
i tried this code.... and the posts appeared from a particular board
Change $id_board = 1; to the number of board you want, for example $id_board = 1, 2, 3, 4, 5, 6;

Quote
Please is there a way to make the posts go to the middle
Find this code
Code: [Select]
<ul>';

if (empty($topics))
{
echo '
<li>There aren\'t any topics.</li>';
}
else
{
foreach ($topics as $id => $subject)
echo '
<li><a href="', $scripturl, '?topic=', $id, '.0">', $subject, '</a></li>';
}

echo '
</ul>';
Replace it with
Quote
<center><ul>';

if (empty($topics))
{
   echo '
   <li>There aren\'t any topics.</li>';
}
else
{
   foreach ($topics as $id => $subject)
      echo '
   <li><a href="', $scripturl, '?topic=', $id, '.0">', $subject, '</a></li>';
}

echo '
</ul></center>';

Quote
and also is there a way to add my own topics without the post published on the particular board
I dont understand what you mean by the above statement.
Please do not PM me questions, ask all your questions in the forum, for others to learn from.

All Student Forum


Offline lola

 If i used that code up there and ad my board id as '$id_romance' It will display a list of topics from romance board. What am asking is that is it possible that am the one that would push topics there... Instead of displaying just a list of topics from the boards.
Nobody is Useless

Offline mfoniso

Please dont us this
Quote
'$id_romance'
but use this
Quote
$id_board = 1, 2, 3, 4, 5, 6;
Note $id_board can be 1, 2, 3, 4, 5, 6,..........100 till infinity
Please do not PM me questions, ask all your questions in the forum, for others to learn from.

All Student Forum


Offline lola

which board will be 1, or which board will be 2,.... am using RIAST mod and Pretty URL that turned my urls to names.....instead of all these page numbers.....bla bla bla
Nobody is Useless

Offline mfoniso

which board will be 1, or which board will be 2,.... am using RIAST mod and Pretty URL that turned my urls to names.....instead of all these page numbers.....bla bla bla
hmm i have never worked with any of this 2 mod you mention, The original smf forum uses numbers to represent boards, so you will need to figure out how you can use the code with this mod.
Please do not PM me questions, ask all your questions in the forum, for others to learn from.

Offline lola

can i set how many topics i want to display?
Nobody is Useless

Offline mfoniso

Please do not PM me questions, ask all your questions in the forum, for others to learn from.

Offline lola

let me check sir
Nobody is Useless

 

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
Students goes to?:
What letter is missing in this word 'Gogle':

Related Topics

  Subject / Started by Replies Last post
8 Replies
32697 Views
Last post April 30, 2018, 04:46:27 PM
by mfoniso
0 Replies
1183 Views
Last post March 31, 2013, 12:45:30 AM
by debby
0 Replies
889 Views
Last post August 19, 2013, 04:40:16 AM
by mfoniso
7 Replies
1890 Views
Last post May 04, 2015, 07:19:01 PM
by mfoniso
15 Replies
1447 Views
Last post February 21, 2015, 09:27:11 AM
by mfoniso