Forums

[resolved] Ad display problem (3 posts)

  1. Anonymous
    Unregistered
    Posted 3 years ago #

    I have the following code added to the index.php file of the Default WordPress theme:
    ---------------------------
    global $css_display, $ad_is_displayed;
    $str_content = str_the_content('Read the rest of this entry »');
    $word_count = str_word_count($str_content);

    if($word_count > 300 && ! $ad_is_displayed)
    {
    $css_display ='';
    //display ad only once
    $ad_is_displayed = true;
    }
    else
    {
    $css_display='style="display:none;"';
    }

    //print("<p>Word Count: $word_count </p>");
    ?>
    --------------------------------

    Basically I want an ad displayed if a post has 300 or more words. It works great for my homepage, but for some reason on my archived pages or individual pages for blog posts (if you click the title), the ad won't show up. Any help with this would be greatly appreciated.

    My blog is http://www.thinkmulticultural.com and the ad tag I am using is
    <iframe src="http://c5.zedo.com/jsc/c5/ff2.html?n=595;c=121/1;s=79;d=9;w=300;h=250" frameborder=0 marginheight=0 marginwidth=0 scrolling="no" allowTransparency="true" width=300 height=250></iframe>

  2. chaoskaizer
    Member
    Posted 3 years ago #

    IMHO using "display:none" for iframe will get you in trouble with certain search engine if it done too much within one page. You can try my solutions its much cleaner.

    add it inside your theme functions.php

    function append_ads($content){
    
      // ads code
      $style_prop = 'float:right;width:300px;margin: 0pt 0pt 5px 10px';
    
      $output = '<div class="ads_300x250" style="'.$style_prop.'">'.PHP_EOL;
      $output .= '<iframe src="http://whatever" width="300"></iframe>'.PHP_EOL;
      $output .= '</div>'.PHP_EOL;
    
      return $output.$content;
    }
    
    function my_ads_content_filter($content){
    
     $ln = str_word_count($content);
     $max_len = 300;
    
     return ( ( $ln >= $max_len) ? append_ads($content) : $content );
    }
    
    // remove filter
    function my_filter_gc(){
    
      remove_filter('the_content','my_ads_content_filter');
    }
    
    add_filter('the_content','my_ads_content_filter');
    add_action('loop_end','my_filter_gc');
  3. Anonymous
    Unregistered
    Posted 3 years ago #

    thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.