• Resolved timothyf

    (@timothyf)


    AFAIK, caching is disabled and remote debugging in enabled on the site.

    Problem: I’m automatically inserting custom ads between posts on the home page, archives pages, category pages, and search pages to appear on tablets and phones. Because the home page has different ad insertion points, I have defined the query in a shortcode and called by <?php echo do_shortcode( ‘[ad-query]’ ); ?> in Ad Inserter code blocks 5 and 8.

    This worked fine with Ad Inserter 2.1.14 and continues to work on the production site. After updating to Ad Inserter 2.2.3, the |count| feature seems to be ignored: the full ad div generated by the shortcode is inserted into each defined ad insertion point. Here’s a (slightly modified) sample of the ad div that appears on a page with AI 2.2.3:

    <div class="code-block code-block-8 ai-viewport-2 ai-viewport-3" style="margin: 8px 0; clear: both;">
    <div class="general-ad ad-counter-1"><a href="https://www.example1.org/production/" onclick="trackOutboundLink('https://www.example1.org/production/'); return false;" target="_blank"><img width="250" height="307" src="https://dev2.example.com/wp-content/uploads/2017/09/ad-e1506456807356.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt=""></a></div>
    |count|
    <div class="general-ad ad-counter-2"><a href="https://www.example2.com/artists/" onclick="trackOutboundLink('https://www.example2.com/artists/'); return false;" target="_blank"><img width="300" height="250" src="https://dev2.example.com/wp-content/uploads/2017/10/image.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt=""></a></div></div>

    This occurs on both the home page and on archives/category/search pages on tablets and phones where you can see both ads separated by |count|.

    And here is the PHP code that generates the ad div after setting $args for $the_query:

    $the_query = get_posts( $args );
    $ad_counter = 1 ;
    foreach( $the_query as $the_post ) {
    	if ($ad_counter>1) $return_string.='|count|';
    	$postid = $the_post->ID ; 
    	$target = get_field('target_url', $postid);
    	$return_string .= '<div class="general-ad ad-counter-' . $ad_counter .'"><a href="' . get_field('target_url', $postid) . '" onclick="trackOutboundLink(\'' . get_field('target_url', $postid) . '\'); return false;" target="_blank">' . get_the_post_thumbnail($postid) . '</a></div>' ;
    	$ad_counter ++ ;
    }
    wp_reset_query();	 // Restore global post data stomped by the_post(). 

    Thanks,
    Tim

    • This topic was modified 7 years, 4 months ago by timothyf.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Issue with |count| and Ad Inserter 2.2.3’ is closed to new replies.