Daily Lucky Numbers:
5
16
19
30
34
45

Category Block (Regular List)

Started by Chen Zhen, July 06, 2013, 03:00:53 PM

Previous topic - Next topic

Chen Zhen

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.


aquarius

Appreciate the code @Chen Zhen

Worked like a charm :)

Vincent Titus

hey chen i really like this block, and will it be compatable with the new arcade when it comes out...?


Chen Zhen


Yes this block will work with SMF Arcade 2.6.0

Vincent Titus


Vincent Titus

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 /> ??

Chen Zhen

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.