WebDev

SMF Arcade => SMF Arcade Block Codes => Topic started by: Chen Zhen on July 06, 2013, 02:56:25 PM

Title: Drop-Down Category Block
Post by: Chen Zhen on July 06, 2013, 02:56:25 PM
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%;';
Title: Re: Drop-Down Category Block
Post by: Chen Zhen on November 21, 2021, 12:57:14 AM

This block code has been updated.
Title: Re: Drop-Down Category Block
Post by: Rowdy on November 21, 2021, 12:14:13 PM
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?
Title: Re: Drop-Down Category Block
Post by: Chen Zhen on November 21, 2021, 02:17:08 PM

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
EhPortal 1.39.6 © 2024, WebDev