SimplePortal

Customization => Blocks and Modifications => Topic started by: jelence on April 16, 2011, 06:00:40 AM

Title: Block with links to topics of chosen board
Post 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!
Title: Re: Block with links to topics of chosen board
Post by: AngelinaBelle on April 18, 2011, 08:42:15 AM
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.
Title: Re: Block with links to topics of chosen board
Post by: jelence on April 18, 2011, 11:23:02 AM

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?
Title: Re: Block with links to topics of chosen board
Post by: AngelinaBelle on April 19, 2011, 08:22:10 AM
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?
Title: Re: Block with links to topics of chosen board
Post by: jelence on April 19, 2011, 03:50:28 PM

He is using  smf1 and it does not work for smf2.

I get this error message when I try his code:

Quote
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  :'(.
Title: Re: Block with links to topics of chosen board
Post by: [SiNaN] on April 21, 2011, 05:48:58 AM
You can use this in a Custom PHP block:

Code: [Select]
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.
Title: Re: Block with links to topics of chosen board
Post by: jelence on April 22, 2011, 02:04:19 AM

Hello [SiNaN], thanks for responding!

I tried code you gave me and I get this error :

Quote
Fatal error: Call to undefined function db_query() in /home8/asekonom/public_html/Sources/PortalBlocks.php(3351) : eval()'d code on line 5

 :(...
Title: Re: Block with links to topics of chosen board
Post by: [SiNaN] on April 22, 2011, 09:37:34 AM
Sorry. For some weird reason I thought you were using SMF 1.1. Try this one:

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>';
Title: Re: Block with links to topics of chosen board
Post by: jelence on April 22, 2011, 11:47:14 AM
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!




Title: Re: Block with links to topics of chosen board
Post by: [SiNaN] on April 22, 2011, 12:06:57 PM
If you want to limit the topics:

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

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

If you want to change the sort order to the newest first:

Code: (Find) [Select]
ORDER BY m.subject
Code: (Replace) [Select]
ORDER BY t.id_topic DESC
Title: Re: Block with links to topics of chosen board
Post by: jelence on April 23, 2011, 02:34:13 AM
 
 This solved a lot of my 'problems', thanks again  :applause:!
Title: Re: Block with links to topics of chosen board
Post by: [SiNaN] on April 24, 2011, 07:54:45 AM
You're welcome. ;)
Title: Re: Block with links to topics of chosen board
Post by: natasa on December 04, 2011, 08:20:31 AM
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.
Title: Re: Block with links to topics of chosen board
Post by: natasa on June 18, 2013, 12:28:17 AM
OK, this can be done like this, for example:

Code: [Select]
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>';
Title: Re: Block with links to topics of chosen board
Post by: natasa on June 23, 2013, 01:08:06 AM
For boards:

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 '
<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>';
Title: Re: Block with links to topics of chosen board
Post by: Tonymura on November 25, 2014, 02:56:54 PM
Hi
I have a similar question to ask as the one posted right here. Should i start a new topic?
Title: Re: Block with links to topics of chosen board
Post by: [SiNaN] on November 28, 2014, 04:47:14 PM
That would be better indeed.
SimplePortal 2.3.8 © 2008-2024, SimplePortal