Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Subcategories?

edited February 2007 in Vanilla 1.0 Help
I'd like to be able to have subcategories for my forum. For example: Auto Repair >BMW >Ford >Volvo Music >MP3 >Video Is this possible with Vanilla? I have not been able to find anything.
«1

Comments

  • not currently
  • yes, it is possible, but nobody has made the extension yet.
  • yeah i meant by that it is possible but no one has currently done it :P
  • would be a really useful extension...
  • why dont you just create longer category names? Auto Repair - BMW Auto Repair - Ford Auto Repair - Volvo
  • edited August 2006
    Its one of the most requested things I know, but there seems to be some inertia against actually making it happen.

    I did manage to make it somewhat you can see here http://forums.gamecreation.org/categories.php

    My categories.php
    $CategoryList = '<div class="ContentInfo Top"> <h1>General Topics'. /*$this->Context->PageTitle. */'</h1></b> </div> <div id="ContentBody"> <ol id="Categories">'; $Category = $this->Context->ObjectFactory->NewObject($this->Context, 'Category'); $FirstRow = 1; while ($Row = $this->Context->Database->GetRow($this->Data)) { $Category->Clear(); $Category->GetPropertiesFromDataSet($Row); $Category->FormatPropertiesForDisplay(); if ($Category->CategoryID > 5){ $CategoryList .= '<li class="catBreak">Active Projects</li>'; } ...
    And you can just order your categories in the forum settings, and use if statements like this to fake it somewhat.

    Then in my categoryjumper's default.php
    while ($Row = $Context->Database->GetRow($CategoryData)) { $cat->Clear(); $cat->GetPropertiesFromDataSet($Row); if ($cat->CategoryID == 1) { $Select->AddOption('-1', 'General Categories', " disabled=\true\""); } if ($cat->CategoryID == 6) { $Select->AddOption('-1', 'Active Projects', " disabled=\true\""); } if ($cat->Blocked != $LastBlocked && $LastBlocked != -1) { $Select->AddOption('-1', '---', " disabled=\"true\""); } $Select->AddOption($cat->CategoryID, ' - ' .$cat->Name); $LastBlocked = $cat->Blocked; }
    Thats the best I can do without more time :)

    When it steps through the loop, when it hits like category ID 6 as I use it, it'll insert that bit, and no other times.
  • Here is an easy way to fake sub categories:
    - in your categories.php, look for:
    while ($Row = $this->Context->Database->GetRow($this->Data)) { $Category->Clear(); $Category->GetPropertiesFromDataSet($Row); $Category->FormatPropertiesForDisplay();
    then add the following:
    if(preg_match("/^$PrevCat-(.+)/",$Category->Name,$match)) { $DisplayCat = $match[1]; $Class = "SubCategory"; } else { $DisplayCat = $Category->Name; $Class = "Category"; $PrevCat = $Category->Name; }
    then replace the next lines with
    $CategoryList .= '<li id="Category_'.$Category->CategoryID.'" class="<b>'.$Class.</b>($Category->Blocked?' BlockedCategory':' UnblockedCategory').($FirstRow?' FirstCategory':'').' Category_'.$Category->CategoryID.'"> <ul> <li class="CategoryName"> <span>'.$this->Context->GetDefinition('Category').'</span> <a href="'.GetUrl($this->Context->Configuration, 'index.php', '', 'CategoryID', $Category->CategoryID).'"><b>'.$DisplayCat.'</b></a>
    - in your vanilla.css add the following style that is the same as the .Category style, but with a left padding (to create the 2nd level of caterogies):
    .SubCategory { margin: 0px; padding-left: 10px; overflow: hidden; width: 100%; }

    - now when you want to add a sub caterogy use the following naming convention:
    "maincategory"
    "maincatergory-subcategory"

    for example:
    sport
    sport-football
    sport-hockey


    It's pretty easy: when displaying the result, vanilla will look for the previous category's name and if the current one's match previousname-something, vanilla will detect it's a subcategory and will use the .Subcategory style and apply a left padding. Of course, it's so simple that you can only have one level of subcategories.

    Here is how it looks like:
    image
  • edited August 2006
    interesting how many of the requests for extensions are all the bells and whistles that already exist on most forum software,
    you can take the software out of the forum but never the forum out of the software ;-)

    I like the way SMF does subcategories by adding a extra row to the main category

    I tried the first example my categories.php but only got a blank page
  • I think this would make a stellar extension!
  • Stellar, maybe for some.

    I find my users like limited categories, the fewer the better, it gets too complex for the poor dears otherwise, horses for courses I guess, it wouldn't hurt if the feature was there but didn't have to use it.
  • It would be cool if you could do it like this, say you have topics and want to specify.

    Cars > BRAND 1 | Brand 2 etc
    Boats > BRAND 1 etc

    but instead of being brought to a page after clicking cars to see all the sub forums for brand 1 etc, you have AJAX make it just slide out.
  • great
  • @wanderer: If multiple roles become a reality, this extension would help me sort the many categories I'd create to better control permissions.
  • edited September 2006
    JeffBax--This is exactly what i am looking for. However, when i copy your code on categories.php, i get errors. Can you please post your complete categories.php file and your categoryjumper's default.php? Many thanks! *EDIT* I am using 1.0.1 Vanilla.. Some of the code from this post does not even look like the code that is in my categories.php.
  • jeffbax - funny decision :-) will be released soon(by algorithm Nested Sets) with unlimited subcategories levels but also with a lot of errors in manual) cause my English is very poor) ps. if you wanna to make some offer write to icq:371600
  • there's not much to it... add a ParentCategoryID column to the database and alter the sql in discussions.php a little bit.
  • ithcy, lol, with the rekursion function? :-) Only for small forums this decison can be acceptable. For forums with more than 1000 visitors per hour it will be improperly...
  • edited September 2006
    Sure, here is my whole Categories and CatJumper, though I am using Vanilla 1 still. I'm sure that its not a big stretch to modify the new Vanilla files either. I'm basically just checking the IDs, and if its past a certain one inserting a header.

    Categories.php:
    <?php // Note: This file is included from the library/Vanilla/Vanilla.Control.CategoryList.php class. $CategoryList = '<div class="ContentInfo Top"> <h1>General Topics'. /*$this->Context->PageTitle. */'</h1> </div> <div id="ContentBody"> <ol id="Categories">'; $Category = $this->Context->ObjectFactory->NewObject($this->Context, 'Category'); $FirstRow = 1; $ActiveProjectsBreak = 0; while ($Row = $this->Context->Database->GetRow($this->Data)) { $Category->Clear(); $Category->GetPropertiesFromDataSet($Row); $Category->FormatPropertiesForDisplay(); if (($Category->CategoryID > 5 && $Category->CategoryID != 10) && $ActiveProjectsBreak == 0){ $CategoryList .= '<li class="catBreak">Active Projects</li>'; $ActiveProjectsBreak = 1; } $CategoryList .= '<li id="Category_'.$Category->CategoryID.'" class="Category'.($Category->Blocked?' BlockedCategory':' UnblockedCategory').($FirstRow?' FirstCategory':'').' Category_'.$Category->CategoryID.'"> <ul> <li class="CategoryName"> <span>'.$this->Context->GetDefinition('Category').'</span> <a href="'.GetUrl($this->Context->Configuration, 'index.php', '', 'CategoryID', $Category->CategoryID).'">'.$Category->Name.'</a> </li> <li class="CategoryDescription"> <span>'.$this->Context->GetDefinition('CategoryDescription').'</span> '.$Category->Description.' </li>'; /*<li class="CategoryDiscussionCount"> <span>'.$this->Context->GetDefinition('Discussions').'</span> '.$Category->DiscussionCount.' </li>'; if ($this->Context->Session->UserID > 0) { $CategoryList .= ' <li class="CategoryOptions"> <span>'.$this->Context->GetDefinition('Options').'</span> '; if ($Category->Blocked) { $CategoryList .= '<a id="BlockCategory'.$Category->CategoryID.'" onclick="ToggleCategoryBlock('."'".$this->Context->Configuration['WEB_ROOT']."ajax/blockcategory.php', ".$Category->CategoryID.", 0, 'BlockCategory".$Category->CategoryID."');\">".$this->Context->GetDefinition('UnblockCategory').'</a>'; } else { $CategoryList .= '<a id="BlockCategory'.$Category->CategoryID.'" onclick="ToggleCategoryBlock('."'".$this->Context->Configuration['WEB_ROOT']."ajax/blockcategory.php', ".$Category->CategoryID.", 1, 'BlockCategory".$Category->CategoryID."');\">".$this->Context->GetDefinition('BlockCategory').'</a>'; } $CategoryList .= '</li> '; } */ $CategoryList .= '</ul> </li>'; $FirstRow = 0; } echo $CategoryList .'</ol> </div>'; ?>

    And CategoryJumper's default.php
    <?php /* Extension Name: Category Jumper Extension Url: http://lussumo.com/docs/ Description: A simple plugin that places a category dropdown in the control panel on the discussion page allowing for fast jumping between categories Version: 1.0 Author: Mark O'Sullivan Author Url: http://www.markosullivan.ca/ Copyright 2003 - 2005 Mark O'Sullivan This file is part of Vanilla. Vanilla is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Vanilla is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Vanilla; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA The latest source code for Vanilla is available at www.lussumo.com Contact Mark O'Sullivan at mark [at] lussumo [dot] com You should cut & paste these language definitions into your conf/your_language.php file (replace "your_language" with your chosen language, of course): */ $Context->Dictionary['AllUnblockedCategories'] = 'All Categories'; function GetCategoryJumper(&$Context) { $CategoryManager = $Context->ObjectFactory->NewContextObject($Context, 'CategoryManager'); $CategoryData = $CategoryManager->GetCategories(0, 1); if (!$CategoryData) { return ''; } else { $Select = $Context->ObjectFactory->NewObject($Context, 'Select'); $Select->Name = 'CategoryID'; $Select->SelectedValue = ForceIncomingInt('CategoryID', 0); if ($Context->Configuration['URL_BUILDING_METHOD'] == 'mod_rewrite') { $Select->Attributes = "onchange=\"document.location='".$Context->Configuration['WEB_ROOT']."'+(this.options[this.selectedIndex].value > 0 ? this.options[this.selectedIndex].value+'/' : 'discussions/');\""; } else { $Select->Attributes = "onchange=\"document.location='".$Context->Configuration['WEB_ROOT']."'+(this.options[this.selectedIndex].value > 0 ? '?CategoryID='+this.options[this.selectedIndex].value : '');\""; } $Select->Attributes .= " id='CategoryJumper'"; $Select->AddOption(0, $Context->GetDefinition('AllUnblockedCategories')); $LastBlocked = -1; $cat = $Context->ObjectFactory->NewObject($Context, 'Category'); while ($Row = $Context->Database->GetRow($CategoryData)) { $cat->Clear(); $cat->GetPropertiesFromDataSet($Row); if ($cat->CategoryID == 1) { $Select->AddOption('-1', 'General Categories', " disabled=\true\""); } if ($cat->Blocked != $LastBlocked && $LastBlocked != -1) { $Select->AddOption('-1', '---', " disabled=\"true\""); } $Select->AddOption($cat->CategoryID, ' - ' .$cat->Name); if ($cat->CategoryID == 5) { $Select->AddOption('-1', 'Active Projects', " disabled=\true\""); } $LastBlocked = $cat->Blocked; } return '<h2>'.$Context->GetDefinition('Categories').'</h2>' .$Select->Get(); } } if (in_array($Context->SelfUrl, array('index.php','categories.php','search.php','account.php','comments.php','extension.php')) && $Configuration['USE_CATEGORIES']) { $Panel->AddString(GetCategoryJumper($Context), 000); $Head->AddStyleSheet('extensions/CategoryJumper/style.css'); } ?>

    Which you can see in action at http://forums.gamecreation.org/categories.php

    And basically, I sort the categories relative to their ID number ie my categories are like this in vanilla.

    Photobucket - Video and Image Hosting
  • Hi all ,
    i dont find the code that Arny said , so help me please !
    Here's my categories.php :

    <?php
    /*
    * Copyright 2003 Mark O'Sullivan
    * This file is part of Vanilla.
    * Vanilla is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
    * Vanilla is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    * You should have received a copy of the GNU General Public License along with Vanilla; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    * The latest source code for Vanilla is available at www.lussumo.com
    * Contact Mark O'Sullivan at mark [at] lussumo [dot] com
    *
    * Description: Display and manipulate discussions
    */

    include("appg/settings.php");
    $Configuration['SELF_URL'] = 'categories.php';
    include("appg/init_vanilla.php");

    // 1. DEFINE VARIABLES AND PROPERTIES SPECIFIC TO THIS PAGE

    // Ensure the user is allowed to view this page
    $Context->Session->Check($Context);
    if (!$Configuration["USE_CATEGORIES"]) header("location:".GetUrl($Configuration, "index.php"));

    // Define properties of the page controls that are specific to this page
    $Head->BodyId = 'CategoryPage';
    $Menu->CurrentTab = "categories";
    $Panel->CssClass = "CategoryPanel";
    $Panel->BodyCssClass = "Categories";
    $Context->PageTitle = $Context->GetDefinition("Categories");

    // 2. BUILD PAGE CONTROLS

    // Add the category list to the body
    $CategoryList = $Context->ObjectFactory->CreateControl($Context, "CategoryList");

    // 3. ADD CONTROLS TO THE PAGE

    $Page->AddRenderControl($Head, $Configuration["CONTROL_POSITION_HEAD"]);
    $Page->AddRenderControl($Menu, $Configuration["CONTROL_POSITION_MENU"]);
    $Page->AddRenderControl($Panel, $Configuration["CONTROL_POSITION_PANEL"]);
    $Page->AddRenderControl($NoticeCollector, $Configuration['CONTROL_POSITION_NOTICES']);
    $Page->AddRenderControl($CategoryList, $Configuration["CONTROL_POSITION_BODY_ITEM"]);
    $Page->AddRenderControl($Foot, $Configuration["CONTROL_POSITION_FOOT"]);
    $Page->AddRenderControl($PageEnd, $Configuration["CONTROL_POSITION_PAGE_END"]);

    // 4. FIRE PAGE EVENTS

    $Page->FireEvents();

    ?>
    Thanks .

    Bouazza .
  • I take it, it is because of the version differences that my categories.php file does not look like yours, jeffbax. I am using Vanilla 1.0.1 and here is my categories.php file: <?php /* * Copyright 2003 Mark O'Sullivan * This file is part of Vanilla. * Vanilla is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. * Vanilla is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * You should have received a copy of the GNU General Public License along with Vanilla; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * The latest source code for Vanilla is available at www.lussumo.com * Contact Mark O'Sullivan at mark [at] lussumo [dot] com * * Description: Display and manipulate discussions */ include("appg/settings.php"); $Configuration['SELF_URL'] = 'categories.php'; include("appg/init_vanilla.php"); // 1. DEFINE VARIABLES AND PROPERTIES SPECIFIC TO THIS PAGE // Ensure the user is allowed to view this page $Context->Session->Check($Context); if (!$Configuration["USE_CATEGORIES"]) header("location:".GetUrl($Configuration, "index.php")); // Define properties of the page controls that are specific to this page $Head->BodyId = 'CategoryPage'; $Menu->CurrentTab = "categories"; $Panel->CssClass = "CategoryPanel"; $Panel->BodyCssClass = "Categories"; $Context->PageTitle = $Context->GetDefinition("Categories"); // 2. BUILD PAGE CONTROLS // Add the category list to the body $CategoryList = $Context->ObjectFactory->CreateControl($Context, "CategoryList"); // 3. ADD CONTROLS TO THE PAGE $Page->AddRenderControl($Head, $Configuration["CONTROL_POSITION_HEAD"]); $Page->AddRenderControl($Menu, $Configuration["CONTROL_POSITION_MENU"]); $Page->AddRenderControl($Panel, $Configuration["CONTROL_POSITION_PANEL"]); $Page->AddRenderControl($NoticeCollector, $Configuration['CONTROL_POSITION_NOTICES']); $Page->AddRenderControl($CategoryList, $Configuration["CONTROL_POSITION_BODY_ITEM"]); $Page->AddRenderControl($Foot, $Configuration["CONTROL_POSITION_FOOT"]); $Page->AddRenderControl($PageEnd, $Configuration["CONTROL_POSITION_PAGE_END"]); // 4. FIRE PAGE EVENTS $Page->FireEvents();
This discussion has been closed.