How To Insert an Ad after first post

  • Elegantvogue

    #3988

    Hiya…

    I wanted to insert and adsense right after the first post on the home page… I am not talking about individual Single post…

    You can check my site layout here

    http://www.bytewiki.com

    I have search over the internet but couldn’t find an appropriate answer…

    Can anyone tell me.. Which file to edit and where to put the code exactly?

    Thanks

    Kind Regards

    Mod

    Kenneth John Odle

    #26851

    Moved to Support.

    You can use a Graphene Action hook widget area. I’m not sure which one you will want to use, however.

    http://blog.kjodle.net/2011/11/04/graphene-action-hook-widgets-an-easy-way-to-modify-your-blog/

    Elegantvogue

    #26852

    I want adsense on the home page under the first post only…. It should not appear after every post…

    here is the example of another blog

    http://img94.imageshack.us/img94/926/53243417.png

    I think I have to edit this code

    Code:
    if ( ! ( is_home() && $graphene_settings[‘frontpage_posts_cats’] && ! have_posts() ) ) {
    while ( have_posts() ) {
    the_post();
    get_template_part( ‘loop’, ‘index’ );
    }
    }

    I need something like this integrated into the code…

    <?php if ( $postcount == 1) { ?>

    Adsense Code Goes Here

    <?php } ?>

    Mod

    Kenneth John Odle

    #26853

    I need something like this integrated into the code…

    That’s PHP. You can use that in a PHP widget in an action hook widget area without hacking into theme files.

    Elegantvogue

    #26854

    Hi

    Yea from action hooks, I turn on “Graphene index pre loop” but when I insert my ad code here… The code appears on top of main container but I want it after the first post in the container…

    I also tried “Graphene after post content” in loop.php… then the ad appears after every post. Even if I try this code… it still comes after every post

    Code:
    <?php if ( $postcount == 1) { ?>
    Adsense Code Goes Here
    <?php } ?>

    Any solution or anyone can tell me Am I using the right code?

    Thanks

    Mod

    Kenneth John Odle

    #26855

    On_The_Spot

    #26856

    I ran into the same problem as I’m redesigning my site (I wanted a sticky article below the lead article), and here’s the solution I came up with:

    Make a copy of loop.php to your child theme.

    Edit loop.php, modify the last line to read:

    <?php do_action( 'graphene_loop_footer', $wp_query->current_post); ?>

    Then, in your child theme’s functions.php, add a function:

    function show_interstitials($post_on_page) {

    if (is_home() & !is_paged() & ($post_on_page < 1)) {

    Rest of your php code for the ad/insert goes here

    };
    };

    add_action('graphene_loop_footer', 'show_interstitials', 10, 1);

    This currently only allows a post on the home page, and not on search or other pages. Modify the if statement above to remove is_home and is_paged references if you wish to enable it.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

Do NOT follow this link or you will be banned from the site!