WordPress.org

Ready to get started?Download WordPress

Forums

How to have this structure: two posts - something in the middle - other posts? (5 posts)

  1. Gatto Nero
    Member
    Posted 6 years ago #

    First of all, hi.
    This is not a place for presentation, but say hello is always kind :D
    First of all: I'm italian, english is not my mother language and maybe I'll have some difficulties explaining what I would like to have. I apologize from now.

    I use WordPress since a long time, and I can say I've learned a lot of things.
    But something I have (really) ever not understood, is how to have something in the middle of my posts.

    I'd like this very simple structure (I see it in a lot of blogs):

    • Two posts
    • Something in the middle (adsense or whatever)
    • The other posts

    I've read the Codex for a solution, but my lack of knowing the PHP makes me not understand how it works, which is the logic beside the code. And this doesn't allow me to "change" the code.

    For example, I've this code in my blog:

    <?php $my_query = new WP_Query('showposts=1');
    while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate = $post->ID; ?>
    
    >--- Post appearance ---<
    
    >--- "The infamous middle thing" ---<
    
    <?php if (have_posts()) : while (have_posts()) : the_post();
    if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>

    The problem is: it works only for ONE post. If I try with two post, one of the post is duplicated.

    How could I solve this problem?
    And important: how "do_not_duplicate" works?

    Thank you all, guys.
    You're great.

  2. Root
    Member
    Posted 6 years ago #

    Try to find the Codex on multiple loops.

  3. Gatto Nero
    Member
    Posted 6 years ago #

    I've read the Codex for a solution, but my lack of knowing the PHP makes me not understand how it works, which is the logic beside the code

    I tried, but it seems something beyond my abilities...

  4. moshu
    Member
    Posted 6 years ago #

    This should get you started:
    http://www.tamba2.org.uk/wordpress/adsense/

  5. Root
    Member
    Posted 6 years ago #

    Add this before the loop Part II

    <?php rewind_posts(); ?>

    Should do it.

Topic Closed

This topic has been closed to new replies.

About this Topic