• Resolved mom2ashley

    (@mom2ashley)


    Hi,
    I would like to add a google adsense banner below each post just after the posted in/comment line. I have tried to add it in the child index.php file but it doesnt seem to appear in the right place.

    Below is how my child index file look like. Where should I be inserting my code? Or should i be inserting it in a different file?

    <?php
    /**
    * The main template file.
    *
    * This is the most generic template file in a WordPress theme
    * and one of the two required files for a theme (the other being style.css).
    * It is used to display a page when nothing more specific matches a query.
    * E.g., it puts together the home page when no home.php file exists.
    * Learn more: http://codex.wordpress.org/Template_Hierarchy
    *
    * @package WordPress
    * @subpackage Twenty_Ten
    * @since Twenty Ten 1.0
    */

    get_header(); ?>
    <div id=”container”>
    <div id=”content” role=”main”>

    <?php
    /* Run the loop to output the posts.
    * If you want to overload this in a child theme then include a file
    * called loop-index.php and that will be used instead.
    */
    get_template_part( ‘loop’, ‘index’ );

    ?>
    </div><!– #content –>

    </div><!– #container –>

    <?php get_footer(); ?>

    The only difference between this file and the parent file is that i removed the ‘php get_sidebar’ line from the child index file.

    Thanks in advance.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Josh Feck

    (@builtbynorthby)

    You might want to take a look at loop.php or maybe even loop-single.php

    Thread Starter mom2ashley

    (@mom2ashley)

    hmm not sure how to but will try, thanks.

    Hi,
    This post of mine may help you, there are the child themes to download as well, this adds and uses a new widget area which for me is better than adding script code in the pages.

    It uses a template part to inject the code, so placement is easy to change and add to any of the page files.

    Be aware that you are limited to three google ads per page so adding after each post will not work.

    Looking at the heat map in my post above the posts is the best placement, so you could add one in index.php.

    In loop-index add a second using a <?php $counter=0; ?> inside the loop increase <?php $counter++; ?> then output the template part on row 2

    Sample Code you would ned to change the name in get template part to your file name, example content-above.php

    <?php
    if( $counter % 2 ) {
        get_template_Part( 'content' , 'above' );
    } ?>

    HTH

    David

    Add the following code into your functions.php file.

    function adsensesinglebottom($content) {
    
    if(is_single()) {
    
    	global $post;
    
    	$content = $content.'
            <div id="adsinglebottom">
            INSERT ADSENSE CODE HERE
            </div>';
    
    }
    
    return $content;
    
    }
    
    add_filter( 'the_content', 'adsensesinglebottom' );

    This will add the AdSense banner after your post content.

    Thread Starter mom2ashley

    (@mom2ashley)

    JarretC – thanks, that works but the ad only shows up on a single page and not on the home page.

    Adeptri – ok I’ll give yours a try.

    Thanks to JarretC and Adeptri for your suggestions.

    Thread Starter mom2ashley

    (@mom2ashley)

    Ok i got it resolved!
    I followed the tutorial here.

    It worked like a charm. Not something which I had in mind initially but this’ll do just fine.

    Thread Starter mom2ashley

    (@mom2ashley)

    The method stated in the post above this one didnt work so nicely.
    Google only allows 3 ads to be displayed at any one time so if you insert the 4th ad into the post, the last ad will be represented as a blank yellow box.
    So i scrapped that and installed the wp plugin called Easy Adsense. It’s exactly what I needed!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Twenty Ten : Which code to edit to include google adsense code after each post’ is closed to new replies.