How to Insert Adsense Code above the Content after click on Read More

Discussion in 'Programming' started by dark0circles, Apr 17, 2007.

  1. #1
    Hi how can I display the adsense directly above the content after click on "Read More" in index template? e.g. in antiaging911.com

    I would like to configure it in template level and not post level. Can it be done?

    Thanks.
     
    dark0circles, Apr 17, 2007 IP
  2. BILZ

    BILZ Peon

    Messages:
    1,515
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You should be able to do it if you edit the template files.
     
    BILZ, Apr 17, 2007 IP
  3. dark0circles

    dark0circles Peon

    Messages:
    660
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    it didn't work if i put the adsense code under the readmore code ... getcontent(somethingthing)..
     
    dark0circles, Apr 17, 2007 IP
  4. dark0circles

    dark0circles Peon

    Messages:
    660
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Anyone have any tips on this?
     
    dark0circles, Apr 18, 2007 IP
  5. ednit

    ednit Peon

    Messages:
    152
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I'm working on something, but it's still not doing what I want it to do completely - though it might work for you.

    It's for my wordpress blog; I'm a perl coder but I hacked this together after a lot of messing around. I use this in the index.php file right after the php get header code:

    <?php
    $AC_Onlyshow = $_SERVER['REQUEST_URI'];
    $ADSENSE_CODE = <<<ADSENSECODE
    <div style="display:block;float:left;padding:5px;">
    <script type="text/javascript"><!--
    google_ad_client = "pub-XXXXXXXXXXXXXXX";
    google_ad_width = 250;
    google_ad_height = 250;
    google_ad_format = "250x250_as";
    google_ad_type = "text";
    //2007-03-31: seowps - single pages top
    google_ad_channel = "5756494487";
    google_color_border = "FFFFFF";
    google_color_bg = "FFFFFF";
    google_color_link = "7DA721";
    google_color_text = "000000";
    google_color_url = "000000";
    //-->
    </script>
    <script type="text/javascript"
      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script></div>
    ADSENSECODE;
    ?>
    
    Code (markup):
    Later on down the page, I use this. It might be slightly different for you, but I'll post the surrounding code so it'll be easier for you to find the right location:


    <?php get_sidebar(); ?>
    <hr />
    <div id="content">
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    	<?php // Post dates off by default the_date('','<h2>','</h2>'); ?>
    	<h2 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>	
    	<div class="meta"><?php _e("Posted in"); ?> <?php the_category(',') ?> by <?php the_author() ?> on the <?php the_time('F jS, Y') ?> <?php edit_post_link(__('Edit This')); ?></div>
    
    	<div class="main">
    
    [color="red"]
    <?php if ( $AC_Onlyshow != '/' && (!preg_match("/\/index.php+?/","$AC_Onlyshow")))
    {
        echo "$ADSENSE_CODE";
    }
    
    ?>
    
    [/color]
    		<?php the_content(__('(more...)')); ?>
    
    Code (markup):
    The part in red is the code to put in place. What it does is it'll show adsense code on pages other than the main page (provided your blog is installed in the main directory, and the code won't show on search pages. I just 3 minutes ago, literally, realized that the adsense code shows up on archive & category pages. . . but I'll see what I can do with that over time.

    Be sure to backup your files before making any changes - and use this if it works for you. . . It took me a good deal of time to figure this out cuz I know nothing about php. . .and it's still not right for my purpose, though it might work for you.
     
    ednit, Apr 19, 2007 IP
  6. dark0circles

    dark0circles Peon

    Messages:
    660
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hi ednit,

    Thanks for your code. I'll try out the code and tell you how it it.

    Thanks again.:p
     
    dark0circles, Apr 20, 2007 IP
  7. dark0circles

    dark0circles Peon

    Messages:
    660
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    ednit, i try out the code just now but the adsense did not display under the "read more" marks..but under the post title.. here's how's the code look like in the template..
    <div id="contentleft">
    	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    	<h1><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h1>
    	<div style="display:none"><p>Posted on <?php the_time('F j, Y'); ?><br />Filed Under <?php the_category(', ') ?> | <?php comments_popup_link('Leave a Comment', '1 Comment', '% Comments'); ?></p>  </div>
    <?php if ( $AC_Onlyshow != '/' && (!preg_match("/\/index.php+?/","$AC_Onlyshow")))
    {
        echo "$ADSENSE_CODE";
    }
    
    ?>
    <?php the_content("...Continue Reading on " . get_the_title('', '', false) . "&raquo;&raquo;") ;  ?><div style="clear:both;"></div>
     	
    Code (markup):
    Does the adsense display right under the paragraph that you mark read more in your blog index template?:confused:
     
    dark0circles, Apr 20, 2007 IP