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.
Options

How do you find the current CategoryID in a template?

edited October 2008 in Vanilla 1.0 Help
How do you get the current CategoryID inside menu.php or any other template. I want to put a different header on each category page.

Comments

  • Options
    Something like this$result = mysql_query("SELECT CategoryID FROM ".$Context->Configuration['DATABASE_TABLE_PREFIX']."Discussion WHERE DiscussionID = '$DiscussionID'",$Context->Database->Connection); $row = mysql_fetch_row($result); $CategoryID = $row[0];
    If you have my extension Notifi installed it already grabs that so I think you should be able to just grab $categoryID if it is installed. Try it and let me know
  • Options
    edited October 2008
    Thanks for your help, I was hoping that the meta data for a page (DiscussionID, CategoryID, etc) was available through $this, or some other object already, but if inserting SQL is the only solution, then I will use that for now. Thanks again.
  • Options
    do you want the CategoryID when you are in the discussion page of this category? it can be made available, try this (i haven't tested):

    create an extension folder in /extensions and name it as you want, e.g. CustomCategoryHeader.
    then create an empty file on it and fill in the metadata for the extension (you can find this info in every other extensions' default.php) remember specially to change the name!
    then after the extension's metadata paste this:
    function AddCategoryIDToContext(&$DiscussionGrid) { if( isset($DiscussionGrid->Category) ) { $DiscussionGrid->Context->CategoryID = $DiscussionGrid->Category->CategoryID; } } $Context->AddToDelegate('DiscussionGrid','PreDataLoad','AddCategoryIDToContext');then save the file as default.php
    then in your themes folder, create a new folder (or if you are using any other theme but the default, then in its folder) and copy /themes/menu.php to it.
    then add:if( isset($this->Context->CategoryID) ) { switch($this->Context->CategoryID) { case 1:// echo the html code of the custom category 1 header break; case 2: ... }
    login to the forum and go to settings and enable the extension, and hopefully...voilà!
  • Options
    I have same problem, but i have that to get the current CategoryID inside head.php, how i make? I test your code, but wrong!
This discussion has been closed.