WordPress.org

Ready to get started?Download WordPress

Forums

display ad every X entries (9 posts)

  1. vladi
    Member
    Posted 9 years ago #

    I would like to display an ad every 5 entries on the main page. is there a plugin for that? thanks :)

  2. Lorelle
    Member
    Posted 9 years ago #

    Did you search for this on the forum or from a search engine? I know it's been talked about in length here....

  3. vladi
    Member
    Posted 9 years ago #

    I've been looking through here for 30 minutes now and haven't found it yet. A pointer would be appreciated...

  4. PirateKing
    Member
    Posted 9 years ago #

    I'm not sure myself if the indexing on this site is correct, because I've searched several times for postings that I know were here before, and I can't find them at all now.

  5. Lorelle
    Member
    Posted 9 years ago #

    Me, too. I've been looking on and off since early this morning. I know this was a huge thread and it was within the last four days...give or take.

    Okay, here is one:

    http://wordpress.org/support/topic.php?id=24751

  6. Lorelle
    Member
    Posted 9 years ago #

    It isn't the one I was looking for, but I know people are all helping to find this thread. If I could come up with the right keywords....

  7. Jinsan
    Member
    Posted 9 years ago #

    You should use google for a fuller search to look at past posts.

  8. gnukerman
    Member
    Posted 9 years ago #

    Why not just use the google adsense plugin and you can place ads on any post you wish from the Quicktags

  9. Ming
    Member
    Posted 9 years ago #

    If you can't find the plugin here's the PHP code. This will work on any page using the 'Loop'.


    <?php
    // These two lines go above your loop
    $i = 0;
    $number_of_posts = 5;
    ?>
    // Now your loop starts
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php
    // If it's a 5th post show the ad otherwise show a post
    if ($i%$number_of_posts==$number_of_posts-1) {
    // AD RELATED CODE GOES HERE
    } else {
    // REGULAR POST TAGS GO HERE
    }
    $i++;
    ?>

    <?php endwhile; ?>
    // Page continues on
    ...

    The // lines can removed.
    The $number_of_posts can = whatever.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.