WebDev

SMF Arcade => SMF Arcade Block Codes => Topic started by: Chen Zhen on July 06, 2013, 03:00:53 PM

Title: Category Block (Regular List)
Post by: Chen Zhen on July 06, 2013, 03:00:53 PM
Category block for SMF Arcade 2.5

Copy and paste this into a PHP code block (I suggest top or bottom block):

global $db_prefix, $modSettings, $context, $sourcedir, $scripturl, $smcFunc, $boardurl;

// Set table width & column variables  -
// change $NumberOfColumns for the number of columns across

$NumberOfColumns = 4;
$columns = 0;

list($requestit, $rowit, $category, $jam) = array(array(), array(), array(), array());
$jam['arcade_category'] = array();

$requestit = $smcFunc['db_query']('', '
SELECT id_cat, cat_name, num_games, cat_order
FROM {db_prefix}arcade_categories
ORDER BY cat_order',
array()
);

while ($rowit = $smcFunc['db_fetch_assoc']($requestit))
{
$jam['arcade_category'][] = array(
'id' => $rowit['id_cat'],
'name' => $rowit['cat_name'],
'href' => $scripturl . '?action=arcade;category=' . $rowit['id_cat'],
'games' => $rowit['num_games'],
'order' => $rowit['cat_order'],
);
}
$smcFunc['db_free_result']($requestit);

echo '
<div style="overflow: hidden;">
<div style="display: table;width: 100%;margin: 0 auto;border: 0px;padding: 5px 5px 1em 5px;text-align: center;overflow: hidden !important;" summary="cats_block2" class="smalltext">
<div style="display: table-row;overflow: hidden;">';

foreach ($jam['arcade_category'] as $category)
{
if ($columns <= $NumberOfColumns) {
$gamepic_name = str_replace (" ", "_", $category['name']);
$gamepic_name = str_replace ("/", "-", $gamepic_name);
$category_pic = '<img src="' .$boardurl. '/Themes/default/images/arc_icons/'.$gamepic_name.'.gif" style="border: 0px;width: 25px;height: 25px;" alt="~"  title="'.$category['name'].'" />';

echo'
<div style="width: 320px;text-justify: inter-word;border-spacing: 2px;">', $category_pic, " ", '
<a href="', $category['href'], '">',$category['name'], '</a> (', $category['games'] , ' games)
</div>';
$columns++;
}

if ($columns >= $NumberOfColumns)  {
$columns = 0;
echo '
</div>
<div style="display: table-row;overflow: hidden;">';
}
}

echo '
</div>
</div>
</div>';
   

<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>

For Simple Portal users, you can have this show in your arcade (only) by selecting Advanced Options and enter the following into Custom Display Options:
~action|arcade


Note:
 The categories can also be displayed with small icons. Just name the icon the same as your category name except change any spaces to an underscore (case sensitive) and make sure it's in gif format.
 Place the icons in: / Themes / default / images / arc_icons
The icons are set at 20 x 20 but this can be edited within the block.

Title: Re: Category Block (Regular List)
Post by: aquarius on April 14, 2020, 11:57:55 AM
Appreciate the code @Chen Zhen

Worked like a charm :)
Title: Re: Category Block (Regular List)
Post by: vince on August 28, 2020, 08:42:58 PM
hey chen i really like this block, and will it be compatable with the new arcade when it comes out...?

Title: Re: Category Block (Regular List)
Post by: Chen Zhen on August 28, 2020, 11:30:02 PM

Yes this block will work with SMF Arcade 2.6.0
Title: Re: Category Block (Regular List)
Post by: vince on August 29, 2020, 08:47:14 AM
great. TY ;D
Title: Re: Category Block (Regular List)
Post by: vince on August 30, 2020, 08:15:22 PM
hey chen, what would i change in the code for this so the category link shows under the category image instead of beside it i was thinking or adding <br /> ??
Title: Re: Category Block (Regular List)
Post by: Chen Zhen on August 30, 2020, 11:01:30 PM
You can try using a line break like that or you can perhaps wrap the link in div container.
div has the display of block by default which will drop down to the next line.
EhPortal 1.39.6 © 2024, WebDev