SimplePortal
Customization => Blocks and Modifications => Topic started by: jelence on April 16, 2011, 06:00:40 AM
-
Hello!
Is it possible to make custom php block (or to change board news or recent posts/topics) to look like list of links from chosen board?
for example, to look like:
Name of block
Link to topic 1
Link to topic 2
Link to topic 3
and so on?
Thanks!
-
Yes. This is essentially creating an index of one board. This idea is very similar to the navigation block, which very much needs updating to SMF 2.0.
-
Thanks.
I suppose that it should be something similar to code in this topic: http://simpleportal.net/index.php?topic=8653.0 (http://simpleportal.net/index.php?topic=8653.0), only for smf2?
-
The poster reported that this solution worked well:
http://simpleportal.net/index.php?topic=8653.msg46252#msg46252 (http://simpleportal.net/index.php?topic=8653.msg46252#msg46252)
Does that work for you?
-
He is using smf1 and it does not work for smf2.
I get this error message when I try his code:
Fatal error: Call to undefined function db_query() in /home8/asekonom/public_html/Sources/PortalBlocks.php(3351) : eval()'d code on line 17
I don't know how to fix that :'(.
-
You can use this in a Custom PHP block:
global $db_prefix, $scripturl;
$id_board = 1;
$request = 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 = {$id_board}
ORDER BY m.subject", __FILE__, __LINE__);
$topics = array();
while ($row = mysql_fetch_assoc($request))
$topics[$row['ID_TOPIC']] = $row['subject'];
mysql_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>';
Change $id_board as the id of the board you want to fetch topics from.
-
Hello [SiNaN], thanks for responding!
I tried code you gave me and I get this error :
Fatal error: Call to undefined function db_query() in /home8/asekonom/public_html/Sources/PortalBlocks.php(3351) : eval()'d code on line 5
:(...
-
Sorry. For some weird reason I thought you were using SMF 1.1. Try this one:
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>';
-
This is working great :thumbsup:!!
Thanks [SiNaN] :)!
Perhaps this should be a part of standard SP installation?
As far as I can see, there is a lot of people trying to use Recent Posts/Topics for this purpose.
With possibility to put 10 or 20 last topics instead of all of them, it should do the job!
-
If you want to limit the topics:
ORDER BY m.subject',
ORDER BY m.subject
LIMIT {int:limit}',
'approved' => 1,
'approved' => 1,
'limit' => 10,
If you want to change the sort order to the newest first:
ORDER BY m.subject
ORDER BY t.id_topic DESC
-
This solved a lot of my 'problems', thanks again :applause:!
-
You're welcome. ;)
-
Hello!
I really like this modification :thumbsup:.
And have a question: how to 'center' it ?
It is a bit moved on right side of menu, so when menu is on the left it does not look so good.
And, how can I put my own images instead of black bullets on the beginning of each item on the list?
I tried to do this on my own, but no luck.
-
OK, this can be done like this, for example:
global $scripturl;
$pages = sportal_get_pages(null, true);
echo '
<p>';
foreach ($pages as $page)
echo '
<p><img src="http://probe.serbianpress.com/Themes/default/images/sp/dot5.png"/> <a href="', $scripturl, '?page=', $page['page_id'], '">', $page['title'], '</a></p>';
echo '
</p>';
-
For boards:
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 '
<p style="list-style-type: none; padding-left:20px;">';
if (empty($topics))
{
echo '
<p>There aren\'t any topics.</p>';
}
else
{
foreach ($topics as $id => $subject)
echo '
<p><img src="http://probe.serbianpress.com/Themes/default/images/sp/dot6.png"/> <a href="', $scripturl, '?topic=', $id, '.0">', $subject, '</a></p>';
}
echo '
</p>';
-
Hi
I have a similar question to ask as the one posted right here. Should i start a new topic?
-
That would be better indeed.