Marketpress - Categories Dropdown Menu - How to set custom default text?

Hello all,

I'm making a custom theme w/ Marketpress. In my store page, I've inserted a dropdown menu of all available categories. But when the page loads, the category that shows up by default isn't submit-able. The rest of the categories are, but not the default category. To get around this, I'm wondering if there is a snippet I can paste into the backend that will list the following default text, no matter which categories populate the list:

Default Text: "Select a Category"

Is this possible? Thanks guys.

Cheers,
AC

  • DavidM
    • DEV MAN’s Mascot

    Hi AC,

    Just checking real quick, are you using the mp_list_categories() template function? If not, that should definitely help you here, providing various ways to display the category listing.

    It's detailed on line 76 in marketpress-includes/template-functions.php in the MarketPress folder, while the comments before that line explains all the parameters.

    That function is actually the same used by the product category widget too.

    Would that maybe sort this issue with your category list?

    -David

  • AC
    • Flash Drive

    Hi David,

    No, I am not using the mp_list_categories() function, I am using the function below it, the mp_dropdown_categories, which is similar to the one you mentioned but displays the categories in a dropdown menu instead. I went with this because this is for a Mobile Store and there is limited screen space, so the dropdown solution works perfectly, almost...

    http://mob01a.smartdepartment.net/store/

    As you can see, "Drinks - Sweet" is selected by default, and for some reason, it is impossible for me to select and submit (i.e., go to that category page) in the dropdown menu. If you select "Drinks - Caffeinated," it will automatically submit via Javascript, but "Drinks - Sweet" will not.

    So, instead I'm looking for a way to have this text: "Select a Category" show by default instead.

    I just need to set it as an <option> somehow and then set that as default.

  • AC
    • Flash Drive

    David,

    As always thanks for tuning in. Hmmm, I have tested with Chrome, Safari, and several mobile browsers and upon first entering the Store, when I select the default option, "Drinks - Sweet," nothing happens. "Drinks - Caffeinated" does work.

    But this issue could be simply resolved if I could just add a default option to the dropdown list that says "Select Category"

    I believe this ability is available already in Marketpress, but I don't know how to activate it. Perhaps Aaron can chime in?

    Kindest regards,

    AC

  • Mason
    • DEV MAN’s Sidekick

    Hiya AC,

    Let me see if Aaron has any recommendations here. You may want to look at how the Category Widget is created (search marketpress.php for MarketPress_Categories_Widget). As it actually provides exactly what you're looking for.

    Hope that helps!

  • AC
    • Flash Drive

    Thank you all for helping out. Since I'm a beginner, I'm not sure where I put this in. Here is the default categories HTML dropdown template function:

    How do I pass it the show_option_one argument that Aaron describes?

    function mp_dropdown_categories( $echo = true, $args = '' ) {
      $args['taxonomy'] = 'product_category';
      $args['echo'] = false;
      $args['id'] = 'mp_category_dropdown';
    
      $dropdown = wp_dropdown_categories( $args );
      $dropdown .= '<script type="text/javascript">
    /* <![CDATA[ */
    	var dropdown = document.getElementById("mp_category_dropdown");
    	function onCatChange() {
    		if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
    			location.href = "<?php echo home_url(); ?>/?product_category="+dropdown.options[dropdown.selectedIndex].value;
    		}
    	}
    	dropdown.onchange = onCatChange;
    /* ]]> */
    </script>';
    
      if ($echo)
        echo $dropdown;
      else
        return $dropdown;
    }

    And here is where I've included the dropdown menu in my MP Custom theme:

    <?php echo mp_dropdown_categories( $echo = true, $args = '' );
    //echo mp_list_categories( $echo = true, $args = '' );
    ?>

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.