Jump to content

Featured Replies

Posted

Hey there!

I have several advertisements blocks and also blocks widgets that can load these advertisements.

I was wondering... Can I use the {block="myblock"} or {advertisement="myad"} inside a page content? How do you resolve this thing?

Cheers,

Ibai

Solved by Eudemon

Go to solution

use JS to inject your ad code into post via something like

$("article.cPost:eq(0) [data-role='commentContent'] p:eq(2)").after("your code here")

above shows ad in first post, after 3rd paragraph

image.png.32cd17aeb4d39706c36ea32e622dff0b.png

Edited by Eudemon

  • Author
10 minutes ago, Eudemon said:

use JS to inject your ad code into post via something like


$("article.cPost:eq(0) [data-role='commentContent'] p:eq(2)").after("your code here")

above shows ad in first post, after 3rd paragraph

Hey thanks @Eudemon!

I understand the code. However, how can I embed adsense code? Just copy and paste their code there escaping the quote mark? Would that work?

  • Solution
7 minutes ago, Ibai said:

how can I embed adsense code? Just copy and paste their code there escaping the quote mark? Would that work?

yes

const yoyo = '<b>tofu is life</b>'
$("article.cPost:eq(0) [data-role='commentContent'] p:eq(2)").after(yoyo)

image.png.82ada16bed0b416b0dc865a94c89fa22.png

Edited by Eudemon

  • Author

Thanks for the idea @Eudemon

This is my final code for long articles, which I inserted in a advertisement block and then I load wherever I want with {advertisement="myad"}

 

<script>
  const yoyo = '<ins class="adsbygoogle"........ADSENSE INS TAG.......></ins>';
  window.addEventListener('load', function () {
    if($("article:eq(0) p").size()>10){
      $("article:eq(0) p:eq(8)").after(yoyo);
      (adsbygoogle = window.adsbygoogle || []).push({});
    }
    if($("article:eq(0) p").size()>25){
      $("article:eq(0) p:eq(20)").after(yoyo);
      (adsbygoogle = window.adsbygoogle || []).push({});
    }
    if($("article:eq(0) p").size()>50){
      $("article:eq(0) p:eq(43)").after(yoyo);
      (adsbygoogle = window.adsbygoogle || []).push({});
    }
    if($("article:eq(0) p").size()>75){
      $("article:eq(0) p:eq(69)").after(yoyo);
      (adsbygoogle = window.adsbygoogle || []).push({});
    }
    if($("article:eq(0) p").size()>100){
      $("article:eq(0) p:eq(98)").after(yoyo);
      (adsbygoogle = window.adsbygoogle || []).push({});
    }
    if($("article:eq(0) p").size()>130){
      $("article:eq(0) p:eq(128)").after(yoyo);
      (adsbygoogle = window.adsbygoogle || []).push({});
    }
    if($("article:eq(0) p").size()>170){
      $("article:eq(0) p:eq(167)").after(yoyo);
      (adsbygoogle = window.adsbygoogle || []).push({});
    }
  });
</script>

 

just few point of improvement base on your code

you can just have one of this, this pushes all adsbygoogle globally

(adsbygoogle = window.adsbygoogle || []).push({});

you can also store `article:eq(0)` to a variable then select whatever within it, so you don't have to repeat the same code, you can also shorten all the statements above with one line tenant condition

Edited by Eudemon

  • Author
11 hours ago, Eudemon said:

just few point of improvement base on your code

you can just have one of this, this pushes all adsbygoogle globally


(adsbygoogle = window.adsbygoogle || []).push({});

you can also store `article:eq(0)` to a variable then select whatever within it, so you don't have to repeat the same code, you can also shorten all the statements above with one line tenant condition

Hey Eudemon,

Thanks for your tips. Yeah, definitely the code was optimizable, that was the first approach. I applied your second suggestion.

However, are you sure that one line of push is enough? I've been testing and when I code just one line of push, it shows only the last ad. I put back that line for each ad and now is showing all of them.

 

Thanks for your support!

that's weird, i just tried it myself and it worked for me ...

  • 7 months later...
On 3/17/2021 at 4:50 AM, Ibai said:

Hey Eudemon,

Thanks for your tips. Yeah, definitely the code was optimizable, that was the first approach. I applied your second suggestion.

However, are you sure that one line of push is enough? I've been testing and when I code just one line of push, it shows only the last ad. I put back that line for each ad and now is showing all of them.

 

Thanks for your support!

It's not working more 😞

I have move this topic to our developer connection forum, as this isnt really a built in function of the platform.

2 hours ago, Marc Stridgen said:

I have move this topic to our developer connection forum, as this isnt really a built in function of the platform.

Please, allow this function by default. This help us a lot if we have a big topics.

Recently Browsing 0

  • No registered users viewing this page.