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.
[Solved] How do I create a unique header for each category in Vanilla?
ericcarl
New
I'm working on a theme and I'm attempting to set it up so that each category has unique content at the top of the page. Specifically we're using Vanilla to host some online classes and we'll need to embed a different video at the top of each category. Is there a simple way to do this in Vanilla's theme development or will I have to take a different approach? I've got a quick visual example of what I'd like to do here:
http://gnomonschool.com/temp/category-player.jpg
Thanks for any help!
http://gnomonschool.com/temp/category-player.jpg
Thanks for any help!
Tagged:
0
Best Answers
-
Todd Vanilla StaffIn the vanillaforums.org theme we put the following in our theme hooks file:
public function CategoriesController_AfterBreadcrumbs_Handler($Sender, $Args) {
You could then put the html you want in your category's description.
$Description = $Sender->Data('Category.Description');
if ($Description) {
echo ''.$Description.'';
}
}1 -
Todd Vanilla StaffYou can add an extra column to the GDN_Category table. Then you can grab
$Sender->Data('Category.YourField')
instead of Description.
To add the column in code you would do something like:Gdn::Structure()->Table('Category')->Column('YourField', 'text', FALSE)->Set();
You can put that in your theme hook's setup method and it will be called when you enable the theme.
You'd probably want to add that field to the add/edit category UI. That's different depending on your version of Vanilla you are running. I think 2.0.18 has some stuff to make this a one line type of thing.1
Answers
I've added a file called class.mc2011themehooks.php to my theme folder location here: And this is all of the code inside that file (I'm not sure why the
<br />
is displaying on line 1 here, it's not actually in my file that way): And I have some plain text in my Category descriptions that I assume should now be visible on my Category pages, but they aren't displaying.I wasn't sure about the first line of PHP there. I included it because I also saw it in the theme hook files from other themes. If I leave it out all of the code in my theme hooks file appears at the top of my Dashboard, like this:
http://gnomonschool.com/temp/vanilla-hook.jpg
Any idea what I may be doing wrong? Thanks a bunch!
If I decided I didn't want to use the category description what would my options be? Is there some way to create a custom element I could call in instead of the category description?
$Sender->Data('Category.YourField')
instead of Description.To add the column in code you would do something like: You can put that in your theme hook's setup method and it will be called when you enable the theme.
You'd probably want to add that field to the add/edit category UI. That's different depending on your version of Vanilla you are running. I think 2.0.18 has some stuff to make this a one line type of thing.