HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Hooks in discussions/comments list

Hi Team,

I’m trying to add ads banner every after 4 discussion in discussion list. I managed to get it to work by cloning/editing the discussions.php to my custom theme. Added the ff on discussions.php:

  1. Looped through each discussion
  2. Added counter variable that increments every loop
  3. Set condition if counter === 4, display ads banner html & reset counter

This is working ok, however I think a better way of doing it is through plugin, so that I can add inputs for banner html, banner frequency & banner limit per page.

I tried using the base_betweenDiscussion_handler however it did not give me the expected results, since $sender->Discussions->result() is looping inside each discussion instead of looping through discussions list.

Need advice if this is possible through plugins or do I just leave it on my custom theme.

TIA

Comments

  • This is working ok, however I think a better way of doing it is through plugin

    That is definitely the way to go.

    Try base_beforeDiscussionName_handler.

  • @Bleistivt I tried the base_beforeDiscussionName_handler, it also looped inside each discussion in discussion list.

  • You need to get your counter outside of the method you are using.
    It's always
    Discussion, event
    Discussion, event
    ...

    So if you try to count inside the event, you will not get to your counter.
    Is that hint enough? Sounds like you like trying to figure out things by yourself. If not, just ask again and I give more details

    I'm not 100% sure, but the pockets plugin might be able to do so and you wouldn't need to write your own plugin.

  • @martin28 said:
    Hi Team,

    I’m trying to add ads banner every after 4 discussion in discussion list. I managed to get it to work by cloning/editing the discussions.php to my custom theme. Added the ff on discussions.php:

    >

    To make myself more clear, here is some code. I guess you have started by modifying this code from discussions.php:

    foreach ($this->DiscussionData->result() as $Discussion) {
        writeDiscussion($Discussion, $this, $Session);
    }
    

    This loop calls writeDiscussion() which has the purpose to write one discussion. In this function, the event gets fired so at this time, all you can access (easily) is the current discussion and therefore you cannot use a counter with a local scope in base_betweenDiscussion_handler

Sign In or Register to comment.