Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

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

Your help will be highly appreciated.

share|improve this question
    
You will not to post some code or a better example , please have a look at wordpress.stackexchange.com/faq –  Wyck Jan 11 '13 at 17:13

1 Answer 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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.