How To Display An 'Advertisement' Post Between Blog Posts?

Discussion in 'WordPress' started by bad_bob00, Sep 2, 2008.

  1. #1
    Hi,

    I'm trying to set up my blog so that it displays an 'Advertisement' post in between blog posts... ideally after every 2 posts, or something like that.

    Obviously I would like the advert to appear automatically, without me manually having to make a post after every 2 posts.

    Ideally it would work like it does on this website (scroll down about 2 or 3 posts until you can see the advertisement).


    Does anyone know of a simple way of doing what I want? Would there be a plugin suitable to use?


    Thanks for any help
     
    bad_bob00, Sep 2, 2008 IP
  2. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This works for the default index.php:
    
    <?php if (have_posts()) : ?>
       <?php $post_count = 0; ?>
       <?php while (have_posts()) : the_post(); ?>
          <div class="post" id="post-<?php the_ID(); ?>">
          .....
          </div>
          <?php if ( ++$post_count == 2) { ?>
             <!-- advertisement code here -->
          <?php post_count = 0; } ?>
       <?php endwhile; ?>
    
    Code (markup):
     
    Cash Nebula, Sep 2, 2008 IP
  3. mdvaldosta

    mdvaldosta Peon

    Messages:
    4,079
    Likes Received:
    362
    Best Answers:
    0
    Trophy Points:
    0
  4. bad_bob00

    bad_bob00 Active Member

    Messages:
    3,472
    Likes Received:
    56
    Best Answers:
    0
    Trophy Points:
    90
    #4
    Thanks for trying to help but thats not the kind of thing I want...

    I want to display a special "advertisement" blog post, so that my readers know that its a sponsored blog post.
    This is a screenshot of the kind of thing I want...

    [​IMG]


    Thanks for any help
     
    bad_bob00, Sep 3, 2008 IP
  5. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I didn't bother looking at the website because I thought I understood. Oh well...try this then:
    
    <?php if (have_posts()) : ?>
       <?php $post_count = 0; ?>
       <?php while (have_posts()) : the_post(); ?>
          <div class="post" id="post-<?php the_ID(); ?>">
          .....
          </div>
          <?php if ( ++$post_count == 2) { ?>
             <div style="height: 320px; padding-top: 5px; margin-bottom: 20px; background-color: #EFEFEF">
                <h4>Advertisement</h4>
                <div style="margin: 0 0 20px 80px;">
                   <!--- advertisement code here -->
                </div>
             </div>
          <?php } ?>
       <?php endwhile; ?>
    
    Code (markup):
    The style will need adjusting if your advertisement is a different size, and also if your post column is a different width.
     
    Cash Nebula, Sep 3, 2008 IP