• Hello! How can I make the following: when showing !in_single() page I want the e.g. first and third post be adsense, so that actual first and third posts were at positions 2 and 4, and the following were in normal order? TIA

Viewing 3 replies - 1 through 3 (of 3 total)
  • One method… at the start of The Loop in your template (typically after the_post() initializes things), set up a post counter to increment for each post in the loop:

    <?php post_counter++; ?>

    Then before the post div/content/whatever in The Loop, add:

    <?php if( ($post_counter == 1) || ($post_counter == 3) ): ?>
    
    ~ad stuff goes here~
    
    <?php endif; ?>
    Thread Starter hategrinder

    (@hategrinder)

    Thanks, however I suppose it is possible without modifuing the template. Any ideas on doing that would also be cool…

    Thread Starter hategrinder

    (@hategrinder)

    Yeah, l did it ??

    add_filter('the_posts','tester_addposts');
    class tester_ad
    {
    	public $ID="0";
    	public $post_content="AD";
    	public $post_title="AD";
    }
    
    function tester_addposts($posts)
    {
    	$adunit=new tester_ad();
    	$adunit=array($adunit);
    	return array_merge($adunit,array($posts[0]),$adunit,array_slice($posts,1));
    }

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to insert something to where a post would be?’ is closed to new replies.