Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

CATEGORY DROP DOWN MENU

Hello,

my categories are on the left hand side , i need them to be a drop down menu at the top.

ive used the 3 available plugins and they put all in a line instead of drop down?

Comments

  • Options
    hgtonighthgtonight ∞ · New Moderator

    Which plugins did you try?

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    the category drop down plugins do not work with tpl based themes. It has to do with the theme not the plugin. Try one of my themes, everything works and are easy to edit.

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    I have started to create a custom Smarty function for a category dropdown, but never quite finished it:

    <?php defined('APPLICATION') or die;
    /*
    -Categories (overview)
     +-Kategorie 1
     +-Kategorie 2
     +-Kategorie 3
    */
    
    function smarty_function_menu_categories($params, &$smarty) {
      // Don't do anything at all, if we do not use categories.
      if (!c('Vanilla.Categories.Use')) {
        return '';
      }
    
      if (strtolower(get_class(Gdn::Controller())) === 'categoriescontroller') {
        $menuCss = 'Categories Active';
      } else {
        $menuCss = 'Categories';
      }
    
      $categoryID = $smarty->get_template_vars('CategoryID');
    
      // Get all categories (cached if possible)
      $categories = CategoryModel::Categories();
    
      // Filter out the categories we aren't watching, we have no permission, and root.
      foreach ($categories as $index => $category) {
        if (!$category['PermsDiscussionsView'] || !$category['Following'] || $category['CategoryID'] == -1) {
          unset($categories[$index]);
        }
      }
    
      $request = Gdn::Request();
      $depth = 0;
      ob_start();
      echo '<li class="',$menuCss,'">';
      echo '<a href="',$request->url('categories'),'" class="Categories">',t('Categories'),'</a>';
    
    
      foreach ($categories as $category) {
        if ($depth < $category['Depth']) {
          echo '<ul class="Depth',$category['Depth'],' dropdown-menu">';
        } elseif ($depth > $category['Depth']) {
          echo '</li></ul>';
        } else {
          echo '</li>';
        }
    
        if ($category['CategoryID'] != $categoryID) {
          echo '<li>';
        } else {
          echo '<li class="Active">';
        }
    
        echo '<a href="',$category['Url'],'" class="',$category['CssClass'],'">',$category['Name'],'</a>';
    
        $depth = $category['Depth'];
      }
      echo str_repeat('</li></ul>', $depth),'</li>';
      return ob_get_clean();
    }
    

    The example results (together with some very basic and ugly styling) can be seen here: https://jsfiddle.net/8vx0h15c/

    But as you can see, there is a problem with showing the active sub menu item, which cannot be addressed by changing the given CSS (as far as I can tell). That would require changing the php code. I will not support that snippet above, but it might get you going. Maybe you can already use it for your page if you only have one or two levels of category depths

Sign In or Register to comment.