Subcategories?
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.
0
This discussion has been closed.
Comments
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.
- 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:
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 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.
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.
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.
i dont find the code that Arny said , so help me please !
Here's my categories.php : Thanks .
Bouazza .