SimplePortal

Customization => Blocks and Modifications => Block Requests => Topic started by: iobit on April 24, 2011, 02:51:18 AM

Title: Category block
Post by: iobit on April 24, 2011, 02:51:18 AM
Hello,
can you create a block for show category forum (like music, game...)in portal?
thanks.

PS: great work simplyportal  ;D
Title: Re: Category block
Post by: grafitus on April 24, 2011, 04:18:42 AM
http://simpleportal.net/index.php?topic=8653.msg46252#msg46252

I did not try it. But you can try and put the result here.
Title: Re: Category block
Post by: iobit on April 24, 2011, 05:00:20 AM
Thanks fantastic!!  8),
is there a way to see the number of posts in each category?
thanks again
Title: Re: Category block
Post by: grafitus on April 24, 2011, 05:13:52 AM
Try this:
Code: (Find) [Select]
', $boards[$boardid]['name'], '</a>
Code: (Replace) [Select]
', $boards[$boardid]['name'], '</a> (', $boards[$boardid]['count_posts'], ')
Title: Re: Category block
Post by: iobit on April 24, 2011, 05:19:35 AM
I view all numbers 1

name category 1
name category 1
name category 1
name category 1
Title: Re: Category block
Post by: grafitus on April 24, 2011, 05:47:53 AM
Sorry, we need to do more operations.

Code: (Find) [Select]
foreach ($boardList[$catid] as $boardid)
{
Code: (Replace) [Select]
foreach ($boardList[$catid] as $boardid)
{
// Sorry this is hard method for server. But easy. :)
$request = db_query("
SELECT numPosts
FROM {$db_prefix}boards
WHERE ID_BOARD = $boardid", __FILE__, __LINE__);
list ($num_posts) = mysql_fetch_row($request);
mysql_free_result($request);

Code: (Find) [Select]
', $boards[$boardid]['name'], '</a>
Code: (Replace) [Select]
', $boards[$boardid]['name'], '</a> (', $num_posts, ')
Title: Re: Category block
Post by: [SiNaN] on April 24, 2011, 07:48:59 AM
Try this:
Code: (Find) [Select]
', $boards[$boardid]['name'], '</a>
Code: (Replace) [Select]
', $boards[$boardid]['name'], '</a> (', $boards[$boardid]['count_posts'], ')

Change 'count_posts' as 'posts' and it should work.
Title: Re: Category block
Post by: iobit on April 24, 2011, 10:16:50 AM
Sorry, we need to do more operations.

Code: (Find) [Select]
foreach ($boardList[$catid] as $boardid)
{
Code: (Replace) [Select]
foreach ($boardList[$catid] as $boardid)
{
// Sorry this is hard method for server. But easy. :)
$request = db_query("
SELECT numPosts
FROM {$db_prefix}boards
WHERE ID_BOARD = $boardid", __FILE__, __LINE__);
list ($num_posts) = mysql_fetch_row($request);
mysql_free_result($request);

Code: (Find) [Select]
', $boards[$boardid]['name'], '</a>
Code: (Replace) [Select]
', $boards[$boardid]['name'], '</a> (', $num_posts, ')

work but i have this: Read Before Posting (1) ()
Title: Re: Category block
Post by: iobit on April 24, 2011, 10:17:57 AM
Try this:
Code: (Find) [Select]
', $boards[$boardid]['name'], '</a>
Code: (Replace) [Select]
', $boards[$boardid]['name'], '</a> (', $boards[$boardid]['count_posts'], ')

Change 'count_posts' as 'posts' and it should work.

instead, this: Read Before Posting  ()
Title: Re: Category block
Post by: [SiNaN] on April 24, 2011, 10:45:07 AM
instead, this: Read Before Posting  ()

Sorry. I thought you were using SMF 2.0 versions. For 1.1 versions, you need this extra edit:

Sources/Subs-Boards.php

Code: (Find) [Select]
b.countPosts,
Code: (Replace) [Select]
b.countPosts, b.numPosts,
Code: (Find) [Select]
'count_posts' => empty($row['countPosts']),
Code: (Replace) [Select]
'count_posts' => empty($row['countPosts']),
'posts' => $row['numPosts'],
Title: Re: Category block
Post by: iobit on April 24, 2011, 10:55:17 AM
now have this: Read Before Posting (1) (1)
Title: Re: Category block
Post by: [SiNaN] on April 24, 2011, 11:23:52 AM
Can you paste here what you have now? (the whole code)
Title: Re: Category block
Post by: iobit on April 24, 2011, 11:35:59 AM
Code: [Select]
global $cat_tree, $boards, $boardList, $scripturl, $sourcedir, $user_info, $db_prefix;

$block_parameters = array(
'num_children' => 'int',
);

if ($return_parameters)
return $block_parameters;

$child_depth = !empty($parameters['num_children']) ? (int) $parameters['num_children'] - 1 : -1;

require_once($sourcedir . '/Subs-Boards.php');
getBoardTree();

// Remobe any boards this user can't actually see.
$temp_boards = $boards;
$request = db_query("
SELECT b.ID_BOARD
FROM {$db_prefix}boards AS b
WHERE !($user_info[query_see_board])", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($request))
unset($temp_boards[$row['ID_BOARD']]);
mysql_free_result($request);

echo '
<div style="padding-left:2px;">';

foreach ($cat_tree as $catid => $tree)
{
echo '
<span class="sp_navigation_block_cat" style="font-weight:bold;"><a href="', $scripturl, '?action=forum#', $tree['node']['id'], '">', $tree['node']['name'], '</a></span><br />';

foreach ($boardList[$catid] as $boardid)
{
// Sorry this is hard method for server. But easy. :)
$request = db_query("
SELECT numPosts
FROM {$db_prefix}boards
WHERE ID_BOARD = $boardid", __FILE__, __LINE__);
list ($num_posts) = mysql_fetch_row($request);
mysql_free_result($request);


$prefix = '';
for ($i=0; $i<=$boards[$boardid]['level']; $i++)
$prefix .= '-';

echo '
', $prefix, '<span class="sp_navigation_block_board"><a href="', $scripturl, '?board=', $boards[$boardid]['id'], '">', $boards[$boardid]['name'], '</a> (', $num_posts, ') (', $boards[$boardid]['posts'], ')</span><br />';
}
}

echo '
</div>';
Title: Re: Category block
Post by: [SiNaN] on April 24, 2011, 11:39:04 AM
Use this one:

Code: [Select]
global $cat_tree, $boards, $boardList, $scripturl, $sourcedir, $user_info, $db_prefix;

$block_parameters = array(
'num_children' => 'int',
);

if ($return_parameters)
return $block_parameters;

$child_depth = !empty($parameters['num_children']) ? (int) $parameters['num_children'] - 1 : -1;

require_once($sourcedir . '/Subs-Boards.php');
getBoardTree();

// Remobe any boards this user can't actually see.
$temp_boards = $boards;
$request = db_query("
SELECT b.ID_BOARD
FROM {$db_prefix}boards AS b
WHERE !($user_info[query_see_board])", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($request))
unset($temp_boards[$row['ID_BOARD']]);
mysql_free_result($request);

echo '
<div style="padding-left:2px;">';

foreach ($cat_tree as $catid => $tree)
{
echo '
<span class="sp_navigation_block_cat" style="font-weight:bold;"><a href="', $scripturl, '?action=forum#', $tree['node']['id'], '">', $tree['node']['name'], '</a></span><br />';

foreach ($boardList[$catid] as $boardid)
{
$prefix = '';
for ($i=0; $i<=$boards[$boardid]['level']; $i++)
$prefix .= '-';

echo '
', $prefix, '<span class="sp_navigation_block_board"><a href="', $scripturl, '?board=', $boards[$boardid]['id'], '">', $boards[$boardid]['name'], '</a> (', $boards[$boardid]['posts'], ')</span><br />';
}
}

echo '
</div>';
Title: Re: Category block
Post by: iobit on April 24, 2011, 11:47:08 AM
are you fantastic  :D work very fine  :D thanks thanks thanks
Title: Re: Category block
Post by: [SiNaN] on April 24, 2011, 11:48:16 AM
You're welcome. ;)
Title: Re: Category block
Post by: wille on April 11, 2012, 11:06:56 AM
This code gives error "Fatal error: Call to undefined function db_query()" with SMF 2.0.2 and SP 2.3.5

Can't figure how to fix it...
Title: Re: Category block
Post by: Tricky on April 13, 2012, 03:01:59 PM
Same "Fatal Error"
Title: Re: Category block
Post by: iobit on February 10, 2013, 01:53:35 AM
Hello,
please can anyone update this code for version 2.3.5?

Thanks.
Code: [Select]
global $cat_tree, $boards, $boardList, $scripturl, $sourcedir, $user_info, $db_prefix;

$block_parameters = array(
'num_children' => 'int',
);

if ($return_parameters)
return $block_parameters;

$child_depth = !empty($parameters['num_children']) ? (int) $parameters['num_children'] - 1 : -1;

require_once($sourcedir . '/Subs-Boards.php');
getBoardTree();

// Remobe any boards this user can't actually see.
$temp_boards = $boards;
$request = db_query("
SELECT b.ID_BOARD
FROM {$db_prefix}boards AS b
WHERE !($user_info[query_see_board])", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($request))
unset($temp_boards[$row['ID_BOARD']]);
mysql_free_result($request);

echo '
<div style="padding-left:2px;">';

foreach ($cat_tree as $catid => $tree)
{
echo '
<span class="sp_navigation_block_cat" style="font-weight:bold;"><a href="', $scripturl, '?action=forum#', $tree['node']['id'], '">', $tree['node']['name'], '</a></span><br />';

foreach ($boardList[$catid] as $boardid)
{
$prefix = '';
for ($i=0; $i<=$boards[$boardid]['level']; $i++)
$prefix .= '-';

echo '
', $prefix, '<span class="sp_navigation_block_board"><a href="', $scripturl, '?board=', $boards[$boardid]['id'], '">', $boards[$boardid]['name'], '</a> (', $boards[$boardid]['posts'], ')</span><br />';
}
}

echo '
</div>';
SimplePortal 2.3.8 © 2008-2024, SimplePortal