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
dan39
New
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.
0
This discussion has been closed.
Comments
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).
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');
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 :-)