WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Add a Banner for every 4 posts in my Home (5 posts)

  1. Microzama
    Member
    Posted 1 year ago #

    WordPress Hello friends, I have a little problem, I'm working staff has the ability to issue options to place a notice of Google Code for every 2 Post on my homepage, excellent if you use any advertising program like Google AdWords, trouble is that I want to put my own banner ad, and the problem I have is that it repeats the same banner every other post, and so does not help me, I want each banner is different. Homepage appears 20 post and if I divide every 3 post a notice would go out six banner on my home page with a width of 550x140 high, super well but I could not, accomplish do that.

    here is the code in different files:

    First create that where:

    option-functions.php

    array( "name" => __("Google Adsense en entrada Individual", TEMPLATE_DOMAIN),
      "description" => __("Insertar el código de Google Adsense para su entrada individual. Aparecerá antes <em>post_content()</em>. Dejar en blanco si no se utiliza.", TEMPLATE_DOMAIN),
    	"id" => $shortname."_adsense_single",
    	"type" => "textarea",
    	"default" => ""),

    template-blog.php in which is inserted:

    <div class="separator"></div>
    
    <?php $get_google_code = get_theme_option('adsense_post'); if($get_google_code == '') { ?>
    <?php } else { ?>
    <?php if(( 2 == $postcount) || (4 == $postcount) ){ ?>
    <div class="adsense-post">
    <?php echo stripcslashes($get_google_code); ?>
    </div>
    <div class="separator"></div>
    <?php } ?>
    <?php } ?>
    
    <?php ($oddpost == "alt-post") ? $oddpost="" : $oddpost="alt-post"; $postcount++; ?>
    
    <?php endwhile; ?>

    And this home.php where appear the following code:

    <div class="separator"></div>
    
    <code><?php $get_google_code = get_theme_option('adsense_post');</code>if($get_google_code == '') { ?>
    <?php } else { ?>
    <?php if(( 2 == $postcount) || (4 == $postcount) ){ ?>
    <div class="adsense-post">
    <?php echo stripcslashes($get_google_code); ?>
    </div>
    <div class="separator"></div>
    <?php } ?>
    <?php } ?>
    
    <?php ($oddpost == "alt-post") ? $oddpost="" : $oddpost="alt-post"; $postcount++; ?>
    
    <?php endwhile; ?>

    How I can change this to display different ad every 3 post.

    Try creating several thing and anything that makes me the required effect.

    Thank you very much for your input ..

  2. alchymyth
    Forum Moderator
    Posted 1 year ago #

    what theme are you working with?

    and how are you planning to enter and save the banner data such as image url and link url?

    imho, the whole problem might be too complex to get answered in the forum ...

  3. Microzama
    Member
    Posted 1 year ago #

    They notice my own code or imagen, <img class="aligncenter size-full wp-image-181" title="aviso-160x600jpg" src="http://localhost/prueba1/wp-content/uploads/2012/10/aviso-550x140-verde.jpg" alt="" width="550" height="140" />

    Theme gamezerg v1.1.
    example:

    in option-functions:

    array ("name" => __ ("Ads Posts Single 1" TEMPLATE_DOMAIN)
      "description" => __("Insertar el código de aviso para su entrada individual. Aparecerá antes <em>post_content()</em>. Dejar en blanco si no se utiliza.", TEMPLATE_DOMAIN),
    	"Id" => $ nombre corto ". _ads_single1"
    	"Type" => "textarea",
    	"Default" => "")
    
    array ("name" => __ ("Ads Posts Single 2" TEMPLATE_DOMAIN)
      "description" => __("Insertar el código de aviso para su entrada individual. Aparecerá antes <em>post_content()</em>. Dejar en blanco si no se utiliza.", TEMPLATE_DOMAIN),
    	"Id" => $ nombre corto ". _ads_single2"
    	"Type" => "textarea",
    	"Default" => "")
    
    array ("name" => __ ("Ads Posts Single 3" TEMPLATE_DOMAIN)
      "description" => __("Insertar el código de aviso para su entrada individual. Aparecerá antes <em>post_content()</em>. Dejar en blanco si no se utiliza.", TEMPLATE_DOMAIN),
    	"Id" => $ nombre corto ". _ads_single3"
    	"Type" => "textarea",
    	"Default" => "")
    
    array ("name" => __ ("Ads Posts Single 4" TEMPLATE_DOMAIN)
      "description" => __("Insertar el código de aviso para su entrada individual. Aparecerá antes <em>post_content()</em>. Dejar en blanco si no se utiliza.", TEMPLATE_DOMAIN),
    	"Id" => $ nombre corto ". _ads_single4"
    	"Type" => "textarea",
    	"Default" => "")
    
    array ("name" => __ ("Ads Posts Single 5" TEMPLATE_DOMAIN)
      "description" => __("Insertar el código de aviso para su entrada individual. Aparecerá antes <em>post_content()</em>. Dejar en blanco si no se utiliza.", TEMPLATE_DOMAIN),
    	"Id" => $ nombre corto ". _ads_single5"
    	"Type" => "textarea",
    	"Default" => "")
    <Php $ get_google_code get_theme_option = ('ads_single1);? If ($ get_google_code =='') {>
    <? Php} else {>
    <? Php if? ((4 == $ postcount)) {>
    <div class="adsense-post">
    <? Php echo ($ stripcslashes get_google_code);?>
    </ Div>
    <div class="separator"> </ div>
    <? Php}>
    <? Php}>
    
    <? Php ($ Oddpost == "alt-post")? Oddpost $ = "": $ Oddpost = "alt-post", $ postcount + +;>?
    
    <Php $ get_google_code get_theme_option = ('ads_single2);? If ($ get_google_code =='') {>
    <? Php} else {>
    <? Php if? ((8 == $ postcount)) {>
    <div class="adsense-post">
    <? Php echo ($ stripcslashes get_google_code);?>
    </ Div>
    <div class="separator"> </ div>
    <? Php}>
    <? Php}>
    
    <? Php ($ Oddpost == "alt-post")? Oddpost $ = "": $ Oddpost = "alt-post", $ postcount + +;>?
    
    <div class="separator"> </ div>
    
    <? Php endwhile;?>

    and etc...

  4. bcworkz
    Member
    Posted 1 year ago #

    If all you want to do is insert an image once in while, the adsense code is confusing things. Rethink what needs to happen from scratch. At the most basic, the following added to your home page template that contains the loop will work. Just be sure each portion is inside a php code block.

    //this part goes OUTSIDE the "loop". Alter image paths/names as needed. Alter 2nd to last line if image quantity changes
    $source = array ( 'http://localhost/prueba1/wp-content/uploads/2012/10/aviso-550x140-verde(0).jpg',	'http://localhost/prueba1/wp-content/uploads/2012/10/aviso-550x140-verde(1).jpg',
    	'http://localhost/prueba1/wp-content/uploads/2012/10/aviso-550x140-verde(2).jpg', 'http://localhost/prueba1/wp-content/uploads/2012/10/aviso-550x140-verde(3).jpg');
    $skipcount = 4; $postcount = 1; $bannercount = 0; //alter frequency by changing $skipcount value
    //this part goes INSIDE the "loop".
    if ( $skipcount-1 == $postcount % $skipcount ) {
    	echo "<img class='aligncenter size-full' title='aviso-550x140' src='" . $source[$bannercount] . "' width='550' height='140' />";
    	++$bannercount;
    	if ( $bannercount > 3 ) { $bannercount = 0; } } // Alter "$bannercount > 3" so that the number is 1 less than number of images listed above
    ++$postcount;

    It's far less than ideal because you manually need to tweak the code to change anything. But it's a start. Build from that.

  5. Microzama
    Member
    Posted 1 year ago #

    Solved with this wonderful plugin "Adsense Custom Placement" , very good thanks all !!

Topic Closed

This topic has been closed to new replies.

About this Topic