Daily Lucky Numbers:
5
14
19
27
28
36

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)
~action|arcade

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;
        document.getElementById("arcadeBlockForm3").submit()
    }
    </script>
    <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',
    array()
);

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>';
}
$smcFunc['db_free_result']($request);

echo '
            </select>
        </form>
    </div>';



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.

Rowdy

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.

Arcade-Reset.png