• Hello,

    I have searched the forums and google, but all the methods I tried yielded no result.

    I designed my main index page like a magazine style, with multiple loops.
    near the end of the page, I made a “latest posts” loop, displaying the recent 5 posts.

    underneath that loop there is another loop, displaying another 6 posts, each one from different category.

    I have placed the pagination at the end of the “Latest posts” loop.
    But pressing the pagination keys takes me to a new page and displays the last loop, the one with 6 posts from different categories.

    I am pulling my hair here, and can’t find solution.

    I even tried to use vertical scroll bar to navigate through the latest posts, but this is a poor solution.

    PLEASE PLEASE PLEASE help me figure it out.

    here is the code for the index page.
    I commented the “Latest posts” section in the code.

    <?php get_header(); ?>
        <?php if(!is_paged()) { ?>
            <div id="top" class="clearfloat" style="position:relative;">
                <div id="welcome" class="demo-show" style="margin-top:-28px;">
    
                    <h3 style="padding-bottom:10px;margin-right:3px;color:#fff;">?????? ????? ?????? ??? ???? (???? ?????? / ?????)
                    </h3>
                        <div id="welcomeHide" style="font-size:130%">                
    
                                <p>
    ??? ???? ?????? ?? ???????? ?????? ?????.
    ???? ???? ???? ???? ????? ????? ???.
    <br />
    ?????? ??? ???? ??? ??? ???? ??????
    ?? ???? ???? ?????? ???????????
    ??????? ?????? ???? ???? ????? ????
    ?????? ??????? ???????.
    <br />
    ??? ??????? ???? ????? ????
    ????? ???? ?? ???? ?? ?????,
    ?????? ????? ?????? ?? ????? ???? ????
    ?? ???????? ???????? ?????? ??? ?????.
    <br />
    ??? ???? ?????? ???, ???? ?????? ???? ????
    ???? ???? ????, ???? ????? ?????? ??????
    ???? ?????? ????.
    <br />
    ??? ?? ????, ???? ?????.
                                </p>
    <p>
                                <span style="font-size:1.1em">
    ?????? ??????? ?????<a href="https://www.emetaheret.org.il/2008/12/11/%d7%a7%d7%a6%d7%aa-%d7%94%d7%91%d7%94%d7%a8%d7%95%d7%aa-%d7%91%d7%a0%d7%95%d7%92%d7%a2-%d7%9c%d7%90%d7%aa%d7%a8/"> ???? ???? ?????</a> ????? ??? ???? ??
    <a href="https://www.emetaheret.org.il/%d7%9e%d7%99-%d7%95%d7%9c%d7%9e%d7%94/">?? ????? ??????</a>
     ????? ?????? ????? ?? ????? ??????? ???? ??????.</span>
    </p>
    <p style="font-weight:bold;">?? ??????? ?????? ????? ?????? ?? ??????, ?? ????? ?? ???????, ?? ????? ??? ???? ????,<br /> ??? ??? ???? ??? ???
    <a href="https://www.emetaheret.org.il/%d7%99%d7%a6%d7%99%d7%a8%d7%aa-%d7%a7%d7%a9%d7%a8/">????? ???</a>
    
     ?? ?????? ?????
    <a href="https://emetaheret.org.il/wiki">???? ??? ????</a>
    </p>
     <!-- AddThis Button BEGIN -->
    <div class="addthis_toolbox addthis_default_style" style="float:right;margin-bottom:10px;">
    <a href="https://www.addthis.com/bookmark.php?v=250&pub=xa-4b0e08a44f0efa1e" class="addthis_button_compact">????</a>
    <span class="addthis_separator">|</span>
    <a class="addthis_button_facebook"></a>
    <a class="addthis_button_myspace"></a>
    <a class="addthis_button_google"></a>
    <a class="addthis_button_twitter"></a>
    </div>
    <script type="text/javascript" src="https://s7.addthis.com/js/250/addthis_widget.js#pub=xa-4b0e08a44f0efa1e"></script>
    <script type="text/javascript">
    var addthis_config = {
         ui_language: "he"
    }
    </script>
    <!-- AddThis Button END -->
    <p style="clear:both;">
    ?????? ?????? ?? ?????? ??? ???? ????????: <a href="https://www.facebook.com/group.php?gid=53459072720" target="_blank"><img src="https://tbn0.google.com/images?q=tbn:A3kY7ltk62yqnM:https://www.unodc.org/images/yournocounts/facebookLogo.gif" alt="?????? ?????? ????????" width="20px" height="20px" border="0" style="vertical-align:middle; " /></a>
    </p>
        </div>
    </div>
    
                </div>
    
    <!--******************* RIGHT ************************* -->
    <div class="clearfloat">
            <div id="colomnRight" class="left" style="">
                <?php include (TEMPLATEPATH . '/includes/sidebarRight.php'); ?>
            </div>
    
    <!--********************* MIDLLE ********************* -->    
    
        <div id="colomnMiddle" class="left">
            <div id="headline">
                <div class="topHeadline">
                    <h4><span>?????? ?????? &raquo;</span></h4>
                </div>
                        <?php jquery_ui_slider(); ?>
    
            </div>
    <div class="shadow">
        <?php include (TEMPLATEPATH . '/searchform.php'); ?>
        </div>
    
    <div id="moviesList">
        <div class="emptyHeadline"><h4><span>????? ?????? &raquo;</span></h4>
        </div>
            <?php
        $movies = new WP_Query();
        $movies->query('showposts=3&cat=198');
    ?>
        <div id="container_division" style="">
            <?php if (have_posts()) : while ($movies->have_posts()) : $movies->the_post(); ?>
            <div class="post-block">
                <div class="img">
                    <a href="<?php the_permalink() ?>" rel="bookmark">
            <?php
            if (has_post_thumbnail()) {
            the_post_thumbnail();
            }
        else {
            echo '';
        }
    ?>
                    </a>
    
                    <div class="title"><?php the_title(); ?>
                    </div>
                </div>
            </div>
    
    <?php endwhile; else: ?>
    
    <?php endif; ?>
    <?php wp_reset_query(); ?>
        </div>
    </div>
    
    <div style="clear:both;"></div>
    <div class="categoriesDiv">
        <?php
        $display_categories = array(188,189,190,191,192); $i = 1; // ???? ?? ????? ?????????
        foreach ($display_categories as $category) {
        ?>
    <div class="categoryBox">
    <?php
        $catPosts = new WP_Query();
        $catPosts->query("showposts=1&cat=$category");
    ?>
            <div class="catHead catHead<?php echo $category; ?>"></div>
            <div class="headline<?php echo $category; ?> catHeadline">
                <h4><span><a href="<?php echo get_category_link($category);?>"><?php echo get_cat_name($category);?> &raquo;</a></span></h4>
            </div>
                    <a href="<?php echo get_category_link($category);?>"><?php echo category_description($category); ?></a>
    <?php while ($catPosts->have_posts()) : $catPosts->the_post(); ?>
        <div class="clearfloat">
          <a href="<?php the_permalink() ?>" rel="bookmark">
        <?php the_post_thumbnail( 'category-thumbnail' ); ?></a>
        <div class="info"><a href="<?php the_permalink() ?>" rel="bookmark" class="title"><?php echo short_title('...', 12);
    ?></a>
    </div>
        <div class="meta">[<?php the_time('j M Y') ?> | <?php comments_popup_link('??? ??????', '????? ???', '% ??????');?>]</div>
            </div>
    <?php endwhile; ?>
    <ul class="categoryBoxUl">
     <?php
     global $post;
     $myposts = query_posts("showposts=3&cat=$category&offset=1");
     foreach($myposts as $post) :
       setup_postdata($post);
     ?>
        <li><span class="categoryTitle"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>
    <div class="meta">[<?php the_time('j M Y') ?> | <?php comments_popup_link('??? ??????', '????? ???', '% ??????');?>]</div>    
    
    </li>
     <?php endforeach; ?>
     </ul>
    <div style="clear:both;">
    <span><a href="<?php echo get_category_link($category);?>">??? ?<?php single_cat_title(); ?> &raquo;</a></span>
    </div>
           </div><!-- end of div categoryBox -->
        <?php $i++; ?>
            <?php } ?>
    
    </div><!-- end of div categoriesDiv -->
        <!-- LATEST POSTS -->
    <div class="emptyHeadline"><h4><span>?????? ??????? &raquo;</span></h4>
        </div>
    <div id="latest" style="overflow-y:auto;height:400px;padding:0px 10px;">
    
     <?php
        query_posts('posts_per_page=5');
    
    ?>
        <?php while (have_posts()) : the_post(); ?>
    <div class="clearfloat">
        <div class="title" style="font-weight:700;"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></div>
    <div class="meta">
            <ul>
                <li class="time"><?php the_time('j M Y') ?></li>
                <li class="comments"><?php comments_popup_link('??? ??????', '????? ???', '% ??????');?></li>
                <li class="author">??? <?php the_author_posts_link(); ?></li>
            </ul>
        </div>
            <div class="spoiler">
                              <?php echo excerpt(25); ?>
            </div>
        </div>
       <?php endwhile;?>
    <?php wp_reset_query(); ?>
    
             <div class="navigation">
            <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
                else { ?>
                <div class="right"><?php next_posts_link('????? ??? &raquo;') ?></div>
                <div class="left"><?php previous_posts_link('&laquo; ????? ?????') ?></div>
                <?php } ?>
        </div>
    </div>
    </div><!-- end of div topMiddle -->
    
    <!--********************** LEFT *************************** -->    
    
    <div id="colomnLeft">
        <div id="news">
        <?php
        $newsPost = new WP_Query();
        $newsPost->query('showposts=5&category_name=??????');
        $i = 1;
     ?>
        <div class="topHeadline"><h4><span><a href="<?php echo get_category_link(109); ?>"><?php single_cat_title(); ?>
     &raquo;</a></span></h4></div>
    
        <?php while ($newsPost->have_posts()) : $newsPost->the_post(); ?>
        <div class="clearfloat <?=($i%2)?"newsColor1":"newsColor2";$i++;?>" style="position:relative;">
        <div class="newsDate">
        <?php the_time('j M Y') ?>
        </div>
          <a href="<?php the_permalink() ?>" rel="bookmark">
        <?php
    if (has_post_thumbnail()) {
            the_post_thumbnail('news-thumbnail');
        }
        else {
            echo '';
        }
    ?></a>
        <div class="info"><a href="<?php the_permalink() ?>" rel="bookmark" class="title">
        <?php the_title(); ?></a>
    <div class="excerpt">
    <?php echo excerpt(10); ?>
        </div>
    </div>
            </div>
          <?php endwhile; ?>
    
        </div>
                <?php if (class_exists('MailPress')) MailPress::form(); ?>
            <div class="" style="width: 290px;">
        <div class="emptyHeadline"><h4>??????  &raquo;</h4></div>
            <?php wp125_write_ads(); ?>
        </div>
        <div style="clear:both;"></div>
        <?php include(TEMPLATEPATH . '/includes/categoryTabs.php'); ?><!-- categorytabs -->
    
            <div style="clear:both;"></div>
    <div class="categoryBox" style="width: 292px; height:480px; margin-top:20px; border:0;clear:both;">
            <div class="emptyHeadline"><h4>??? ???? ??  &raquo;</h4></div>
    <div class="moreOnDiv div1"><a href=""><p>?????? ?????. ??? ????? ?????? ??????? ??? ???? ????? ????????</p></a></div>
    <div class="moreOnDiv div2"><a href=""><p>??? ??????, ?? ???? ????? ??? ????? ?? ???? ????? ???. ??? ????????? ???????? ??? ???? ????? ??????? ??????? ?? ??? 
    
    ??????</p></a></div>
    <div class="moreOnDiv div3"><a href=""><p>???????. ?? ???? ???????, ?? ??? ??????? ????? ?????????? ??????? ???????</p></a></div>
    <div class="moreOnDiv div4"><a href=""><p>??? ?????. ???? ????? ?????? ??????? ?? ?? ???. ??? ???? ?? ???? ??? ??????, ?? ?????? ???? ??? ?????? ?????? 
    
    ????</p></a></div>
    <div class="moreOnDiv div5"><a href=""><p>?????? ?????? ??? ???. ???? ????? ??? ????? ????. ??? ?? ?????? ??????? ?? ???? ????</p></a></div>
    <div class="moreOnDiv div6"><a href=""><p>????? ???????? ?? ?? ????. ????? ?????? ??????
    ???? ?? ?? ???? ??????? ????? ??????. ?? ????? ????? ??????</p></a></div>
    <div class="moreOnDiv div7"><a href=""><p>??? ?????????? ??????? ????? ?????? ?????? ???? ?????? ?????. ???? ?????? ?????????? ???? ????? ???? ???? ?????. ??? 
    
    ????? ?? ??? ????????</p></a></div>
        </div>
    
    </div><!-- end of div topLeft -->
    </div>
        <div id="middle" class="clearfloat">
    <div class="left" style="width:610px;">
    
    <!-- Categories -->
    
    </div>
    <div id="middleLeft" class="left" style="width:300px;">
    </div><!-- end of div middleLeft -->
        </div>
        <?php } ?>
        <div id="front-list">
    <div class="topHeadline"><h4><span>????? ????????? ????? &raquo;</span></h4></div>
        <div class="catCont">
        <?php
        $display_categories = array(197,202,201,200,199,193); $i = 1; // ???? ?? ????? ?????????
        foreach ($display_categories as $category) { ?>
    <div class="otherCatBox">
    <?php
        $otherPosts = new WP_Query();
        $otherPosts->query("showposts=1&cat=$category");
    ?>
        <div class="catHead catHead<?php echo $category; ?>"></div>
            <div class="headline<?php echo $category; ?> catHeadline">
                <h4><span><a href="<?php echo get_category_link($category);?>"><?php echo get_cat_name($category);?>
     &raquo;</a></span></h4>
            </div>
                    <a href="<?php echo get_category_link($category);?>"><?php echo category_description($category); ?></a>
    <?php while ($otherPosts->have_posts()) : $otherPosts->the_post(); ?>
        <div class="clearfloat" style="font-size:0.7em;width:140px;">
          <a href="<?php the_permalink() ?>" rel="bookmark">
        <?php the_post_thumbnail( 'category-thumbnail' ); ?></a>
        <div class="info"><a href="<?php the_permalink() ?>" rel="bookmark" class="title"><?php echo short_title('...', 12);
    ?></a>
    </div>
        <div class="meta">[<?php the_time('j M Y') ?> | <?php comments_popup_link('??? ??????', '????? ???', '% ??????');?>]</div>
            </div>
    <?php endwhile; ?>
    
           </div><!-- end of div categoryBox -->
        <?php $i++; ?>
    
            <?php } ?>
    
    </div>
        </div>
    <!--    </div> -->
    
    <?php get_footer(); ?>

    The site in action: https://www.emetaheret.org.il/blog_new

Viewing 8 replies - 1 through 8 (of 8 total)
  • Try taking out the wp_reset_query just ahead of the nav section and add pagination to the query_posts:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("posts_per_page=5&paged=$paged");
    Thread Starter nivosh

    (@nivosh)

    Thank you vtxyzzy, my friend,
    but the solution is not working.

    There is a relativly new call to use after custom queries within the loop, that might work as it returns to the post.

    Just outside of your last custom loop and before the page counter add
    <?php wp_reset_postdata(); ?>

    Also if you don’t mind a suggestion, if are using ‘WordPress 3’ and need to repeat blocks of code, have a look at template parts for the loops, create a file something like loop-custom.php with the loop code in it.

    //Do Layout stuff
    //Query One
    $query= 'cat=' . $catid. ''; query_posts($query);
    //Get the Posts
    get_template_part( 'loop', 'custom' );
    wp_reset_query();
    
    //Do Layout Stuff
    //Query Two
    $query= 'cat=' . $catid. ''; query_posts($query);
    //Get the Posts
    get_template_part( 'loop', 'custom' );
    wp_reset_query();
    
    //Do Layout Stuff
    //Query Three
    $query= 'cat=' . $catid. ''; query_posts($query);
    //Get the Posts
    get_template_part( 'loop', 'custom' );
    wp_reset_query();
    
    wp_reset_postdata();
    //Get the Page comments

    HTH

    David

    Thread Starter nivosh

    (@nivosh)

    Hello David,

    I have added the code: wp_reset_postdata ()
    after the final loop in the page, but the pagination still returns the wrong loop data.

    here is the final loop code with the added rest_postdata():

    <div id="front-list">
    <div class="topHeadline"><h4><span>????? ????????? ????? &raquo;</span></h4></div>
        <div class="catCont">
        <?php
        $display_categories = array(197,202,201,200,199,193); $i = 1; // ???? ?? ????? ?????????
        foreach ($display_categories as $category) { ?>
    <div class="otherCatBox">
    <?php
        $otherPosts = new WP_Query();
        $otherPosts->query("showposts=1&cat=$category");
    ?>
        <div class="catHead catHead<?php echo $category; ?>"></div>
            <div class="headline<?php echo $category; ?> catHeadline">
                <h4><span><a href="<?php echo get_category_link($category);?>"><?php echo get_cat_name($category);?>
     &raquo;</a></span></h4>
            </div>
                    <a href="<?php echo get_category_link($category);?>"><?php echo category_description($category); ?></a>
    <?php while ($otherPosts->have_posts()) : $otherPosts->the_post(); ?>
        <div class="clearfloat" style="font-size:0.7em;width:140px;">
          <a href="<?php the_permalink() ?>" rel="bookmark">
        <?php the_post_thumbnail( 'category-thumbnail' ); ?></a>
        <div class="info"><a href="<?php the_permalink() ?>" rel="bookmark" class="title"><?php echo short_title('...', 12);
    ?></a>
    </div>
        <div class="meta">[<?php the_time('j M Y') ?> | <?php comments_popup_link('??? ??????', '????? ???', '% ??????');?>]</div>
            </div>
    <?php endwhile; ?>
    <?php wp_reset_postdata(); ?>
           </div><!-- end of div categoryBox -->
        <?php $i++; ?>
    
            <?php } ?>
    
    </div>
        </div>
    <!--    </div> -->

    About your suggestion, can you please elaborate further, I am no expert in php.
    Maybe you can use the code of my site as an example?

    Thread Starter nivosh

    (@nivosh)

    Can no one help me with this?

    Thread Starter nivosh

    (@nivosh)

    Last try?

    Hi Nivosh

    I’m not certain that I understand your problem, it sounds like you’ve got more than one loop and you want to out put “Next Page” links for the 1st look AFTER you have you displayed the 2nd loop. Is that correct?

    If so, couldn’t you capture the “next page” links into a variable immediately after the 1st loop so that you get its posts and then display that variable’s contents when you want to?

    You might need to use wp_link_pages as that has an option to echo or return the result.

    Thread Starter nivosh

    (@nivosh)

    Hello JohnC28,
    Thank you for your help.

    I have several loops in my index.php home page.

    the one before the last loop is for my recent posts and has the pagination links.

    The problem is that when I click the “next page” button, wordpress displays the last loop content for some reason, and not the content of the loop before it, the one that has the pagination code.

    Please go to: https://www.emetaheret.org.il/blog_new
    go down the page until you’ll see the two last loops.

    the first one is the recent posts loop, which has the pagination at the bottom.

    after that there is a row of latest from different categories.

    If you’ll press the pagination links, you’ll see the problem.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Multiple loops, Pagination not working properly’ is closed to new replies.