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.

"if" statement for an Add-on to target a specific CategoryID

dan39dan39 New
edited March 2007 in Vanilla 1.0 Help
Anyone know of a simple "if" statement that would enable an Add-On to do something within a specific category ID? Say, if you wanted an Add-On to display something (an ad, for instance) in the Sidepanel only when the "CategoryID=4" (on on index.php pages), what would that "if" statement look like? This seems like it should be easy to do, but for some reason, everything I've tried hasn't worked.

Comments

  • if ( ('index.php' == $Context->SelfUrl) && (4 == ForceIncomingInt('CategoryID', 0)) ) { // do stuff }
  • edited March 2007
    Thanks, Wallphone. I was looking for that, too.

    I have a problem: it only works in the discussion list, not in the comments page. How can i know to which category belongs a certain discussion ?

    Thanks in advance.

    -- edit

    Of course i'm just checking the category id. I mean, if i do:

    var_dump(ForceIncomingInt('CategoryID',0));

    I get: int(0).
  • just add comments.php to the if statement if ( in_array($Context->SelfUrl, array('comments.php','index.php')) && (4 == ForceIncomingInt('CategoryID', 0)) ) { // do stuff }
  • edited March 2007
    Actually, that won't work for comments.php as it never takes a querystring parameter for a category ID.

    If you want to do something special with a paticular comments page (discussion) in a category you would need to attach to the PostCommentOptionsRender delegate and check the Comment's CategoryID:function DoSomething(&$CommentGrid) { $RowNumber = &$CommentGrid->DelegateParameters['RowNumber']; // Since this delegate fires for every comment in a discussion, // we check the RowNumber to only fire on the first comment if (1 == $RowNumber) { $Comment = &$CommentGrid->DelegateParameters['Comment']; if (4 == $Comment->CategoryID) { // do something } } } $Context->AddToDelegate('CommentGrid', 'PostCommentOptionsRender', 'DoSomething');
  • Thanks for this, Wallphone. Very clear and concise. A big help.
  • Thanks :) I understood a little more. However, i still get a 0 in $Comment->CategoryID. Maybe i can obtain it by querying for the discussion id and its category id ?
  • Ah yes, it appears that value is set only on comment searches.

    You could either look up the ID by the discussion ID, or you can tell the CommentManager to retrieve the category ID along with the rest of the comment info... the second function is just a shortened version of the above one.function GetCategoryID(&$CommentGrid) { $s = &$CommentGrid->DelegateParameters['SqlBuilder']; $s->AddSelect('CategoryID', 't', 'CategoryID'); } $Context->AddToDelegate('CommentManager', 'CommentManager_GetCommentList', 'GetCategoryID'); function DoSomething(&$CommentGrid) { $R = $CommentGrid->DelegateParameters['RowNumber']; $C = $CommentGrid->DelegateParameters['Comment']; if ( (1 == $R) && (4 == $C->CategoryID) ) { // do something } } $Context->AddToDelegate('CommentGrid', 'PostCommentOptionsRender', 'DoSomething');I actually tested this block of code and know it works :-)
  • Thanks !!!! :) It worked perfectly.
This discussion has been closed.