Daily Lucky Numbers:

Drop-Down Category Block

Started by Chen Zhen, July 06, 2013, 02:56:25 PM

Previous topic - Next topic

Chen Zhen

Drop-Down categories PHP block code for SMF Arcade

This will give you a nice drop-down category menu inside a php block.
You can check out the one in this arcade for the example.

Custom Display Options:
(For viewing on portal - leave this line blank)

Main Code:
// Category PHP block code for SMF Arcade
global $scripturl, $smcFunc;

$selectCSS = 'font-size: 100%;';

list($count, $cat_name, $cat_link, $cat_drop) = array(1, array(), array(), array());

echo '
    <script type="text/javascript">
    function arcadeCatBlockSelect() {
        var arcadeNewFormSelectOpt = document.getElementById("arcCategoryBlockId");
        var arcadeNewFormCatId = arcadeNewFormSelectOpt.options[arcadeNewFormSelectOpt.selectedIndex].value;
        document.getElementById("arcadeBlockForm3").action += ";category=" + arcadeNewFormCatId;
    <div class="centertext" style="width: 100%;margin: 0 auto;">
        <form id="arcadeBlockForm3" action="', $scripturl, '?action=arcade" method="post">
            <select id="arcCategoryBlockId" name="arcCategoryBlock" style="' . $selectCSS . '" onchange="arcadeCatBlockSelect()">
                <option value="">View By Category</option>';

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

while ($row = $smcFunc['db_fetch_assoc']($request)) {
    $count = $row['id_cat'];
    $cat_name[$count] = $row['cat_name'];
    $cat_link[$count] = $scripturl . '?action=arcade;category=' . $count;
    $cat_drop[$count] = '<a href="' . $cat_link[$count] .'">'.$cat_name[$count].'</a>';

    echo '
                <option value="', $count, '">', $cat_name[$count], '</option>';

echo '

Note: You can style your select box with this part of the above code:
$selectCSS = 'font-size: 100%;';

Chen Zhen

This block code has been updated.


I was under the impression that this would select only game in the type selected, but it only changes the Champion block for those type games selected.  Was that the intent?

Chen Zhen

It changes the champ block & the list.
The arcade keeps track of multiple list criteria (game type & category).
If you want to reset the list then use the ARCADE button in the toolbar located on the left side of the arcade template.