• Hello Greg,

    is it possible to display in grid and list view after every 5th or any other number of ad a google ad?

    If so, how can i realize this?

    Best
    Sven

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    this is possible but requires some rather advanced programming knowledge, you would need to start with creating a child template file for wpadverts/templates/list-item.php file as explained here https://wpadverts.com/doc/child-themes-and-templates/

    Once you have a custom list-item.php file you would need to put inside it code that will display custom code every 5 ads, something like this

    
    <?php
    include ADVERTS_PATH . '/templates/list-item.php';
    
    global $adverts_list_index;
    if( $adverts_list_index < 1 ) {
      $adverts_list_index = 0;
    }
    $adverts_list_index++;
    
    if( $adverts_list_index % 5 === 0 ) {
        $cl = adverts_css_classes( 'advert-item advert-item-col-'.(int)$columns, get_the_ID() );
        echo sprintf( "<div class='%s'>[YOUR AD HERE]</div>", $cl );
    }
    
    Thread Starter freizeitmonster

    (@freizeitmonster)

    Thank you, Greg.
    The basic code is working great (with static content). But when i insert a google ads script it crashes the whole website layout.

    <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <!-- hochzeit-planen sidebar -->
    <ins class="adsbygoogle"
         style="display:block"
         data-ad-client="ca-pub-0000000000"
         data-ad-slot="0000000000"
         data-ad-format="auto"
         data-full-width-responsive="true"></ins>
    <script>
         (adsbygoogle = window.adsbygoogle || []).push({});
    </script>
    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    please try using this code

    
    <?php
    include ADVERTS_PATH . '/templates/list-item.php';
    
    $ad_code = '<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <!-- hochzeit-planen sidebar -->
    <ins class="adsbygoogle"
         style="display:block"
         data-ad-client="ca-pub-0000000000"
         data-ad-slot="0000000000"
         data-ad-format="auto"
         data-full-width-responsive="true"></ins>
    <script>
         (adsbygoogle = window.adsbygoogle || []).push({});
    </script>';
    
    global $adverts_list_index;
    if( $adverts_list_index < 1 ) {
      $adverts_list_index = 0;
    }
    $adverts_list_index++;
    
    if( $adverts_list_index % 5 === 0 ) {
        $cl = adverts_css_classes( 'advert-item advert-item-col-'.(int)$columns, get_the_ID() );
        echo sprintf( "<div class='%s'>%s</div>", $cl, $ad_code );
    }
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Google Ads after n ad’ is closed to new replies.