Users running a non-download version of Vanilla (pulled from github), on branch release/2019.016 or master from the last 2 weeks should upgrade to release/2019.017 or latest master for security reasons. Downloaded official open sources releases are not affected.

Category specific code on top each post

Please, I'll like to add code on top of every post a user posts on my forum.

I would have used the POCKETS plugin, but I want every category or subcategory to have its own specific code that I can edit anytime.

Specifically, I want to add HTML code that can play/stream audio while the users discuss.

Different categories will have different stream links.

Please help me, I'm building a discussion forum for community interests and I am a novice.

Thank you


  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    Here is some untested code (but I assume it should work) which you certainly would have to customize and wrap up in a plugin of your own:

       public function pocketsPlugin_toString_handler($sender, $args) {
           $controllerName = Gdn::controller()->ControllerName;
           // Only continue when viewing a discussion.
           if ($controllerName !== 'discussioncontroller') {
           $categoryID = Gdn::controller()->CategoryID;
           $pocketName = $args['Pocket']->Name;
           $pocketMatrix = [
               'Some Pocket Name' => [1, 2, 6],
               'Another Pocket Name' => [4, 5, 6],
               'The Last Pocket Name' => [9]
           $allowedCategoryIDs = $pocketMatrix[$pocketName] ?? [];
           // Pocket is not in our matrix, so return to normal processing.
           if ($allowedCategoryIDs === []) {
           // Current category is where this pocket should be shown.
           if (in_array($categoryID, $allowedCategoryIDs)) {
           // a) Current pocket is in our matrix and b) not in an allowed category
           // Make the body an empty string so that nothing will be shown.
           $args['Pocket']->Body = '';

    I hope it is mostly readable what's happening: Before a pocket is printed out, you can hook into the process flow and take some actions. I have thrown together some lines which a) ensure we are dealing with the /discussion view (and not e.g. with the Recent Discussions view) b) the pocket that we are checking is one pocket that really should be treated based on the category and not a pocket that should be shown for every one on every page and c) the category of the current discussion matches the array of allowed categories for this pocket

  • Oh Boy!

    This then mean I must work with code afterall. I thought I could use Vanilla without codes, so far it's been working just fine but then, I guess I'm going into deeper waters.

    I was hoping there was already a plugin I could use.

    Thank you @R_J

  • phreakphreak Vanilla*APP (White Label) & Vanilla*Skins Shop MVP
    edited March 24

    @JoshuaO: We have a plugin for sale that does exactly what you are looking for. "Pocket Categories" is an additional plugin to Pockets that allows you to define in which categories your custom HTML code will appear.

    • VanillaAPP | iOS & Android App for Vanilla - White label app for Vanilla Forums OS
    • VanillaSkins | Plugins, Themes, Graphics and Custom Development for Vanilla
Sign In or Register to comment.