How to put a banner ad between post 1 and post 2 on homepage only

WordPress Swift Theme is installed on my My site http://tech-ticks.info

From last few days, I am trying to find a solution to put an ad banner on homepage only between post1 and post 2. I have already tried on worpress support forum.

Read More

Can anyone here help me out as i don’t have much knowledge about PHP.

Your help will be highly appreciated.

Related posts

Leave a Reply

1 comment

  1. Register a widget, and call it on the front-page when the the_post action is called second time:

    add_action( 'wp_loaded', 'wpse_80202_register_banner_widget' );
    function wpse_80202_register_banner_widget()
    {
        // used on the first page of main loop only
        register_sidebar(
            array (
                'name'          => 'Banner front-page ',
                'id'            => 'frontpage_banner',
                'before_widget' => '<div class="frontpage-banner">',
                'after_widget'  => '</div>'
            )
        );
    }
    
    add_action( 'loop_start', 'wpse_80202_show_banner_widget' );
    
    function wpse_80202_show_banner_widget()
    {
        static $count = 0;
        if ( ! is_front_page() )
            return;
    
        if ( 'loop_start' === current_filter() )
        {
            add_action( 'the_post', __FUNCTION__ );
            return;
        }
    
        $count += 1;
    
        if ( 2 === $count )
        {
            dynamic_sidebar( 'frontpage_banner' );
            remove_action( 'the_post', __FUNCTION__ );
        }
    }
    

    I would use the Text widget for that:

    enter image description here

    Another variant of this code here: Add Adsense code in index.php