Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8602211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:01:34+00:00 2026-06-12T02:01:34+00:00

Im just wondering is it possible to use the pagination_links() function in a foreach

  • 0

Im just wondering is it possible to use the pagination_links() function in a foreach loop in wordpress?
When I try it nothing happens, I have looked around and it seems this is a little trickier than I was expecting…

<?php
$args = array( 'numberposts' => 6, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post); ?>
   <div class="events">
        <div class="newslistingblock">
        <div class="newslistingblockheader"><p><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></p>
        </div>
        <div class="newslistingblockthumbnail">
         <?php echo get_the_post_thumbnail( $post_id, 'news-thumb', $attr ); ?> </div>
         <div class="newslistingexcerpt">
                <?php the_excerpt( ); ?> </div> 
  </div>
  </div>



<?php endforeach; ?>

Im basically looking for basic pagination, with “next”, “prev” and numbers.

Any help on this would be great thanks.

EDIT:
I have decided to change the code to this to suit wordpress…

    <?php 
query_posts( 'posts_per_page=5' );
if (have_posts()) : 

while (have_posts()) : the_post(); ?>
<!-- Do suff -->

   <div class="events">
        <div class="newslistingblock">
        <div class="newslistingblockheader"><p><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></p>
        </div>
        <div class="newslistingblockthumbnail">
         <?php echo get_the_post_thumbnail( $post_id, 'news-thumb', $attr ); ?> </div>
         <div class="newslistingexcerpt">
                <?php the_excerpt( ); ?> </div> 
  </div>
  </div>
  <?php endwhile; ?> 
   <div class="navigation">
    <div class="alignleft"><?php next_posts_link('← Older Entries') ?></div>
    <div class="alignright"><?php previous_posts_link('Newer Entries →') ?></div>
</div>
<?php endif; ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:01:36+00:00Added an answer on June 12, 2026 at 2:01 am

    Why are you using foreach instead of while?

    The default loop with pagenation should look like this (should work with foreach as well):

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <!-- Do suff -->
    <?php endwhile; ?>    
    <div class="navigation">
        <div class="alignleft"><?php next_posts_link('← Older Entries') ?></div>
        <div class="alignright"><?php previous_posts_link('Newer Entries →') ?></div>
    </div>
    <?php endif; ?>
    

    This just shows the next and previous link, but if you want pagination with numbers, I would suggest the great plugin: Wp-Pagenavi.

    Good luck!

    EDIT:

    The error you are experiencing is that you haven’t set the paged variable correctly. You need to do the following:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
    query_posts('posts_per_page=5&paged=' . $paged); 
    ?>
    

    Then everything should work.

    You can find more information in the codex: http://codex.wordpress.org/Pagination#Adding_the_.22paged.22_parameter_to_a_query

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first time use JTree. Just wondering is it possible to have more than one
Just wondering if it's possible to use an XMLHTTPReq to login to a website,
EDITED: Just wondering if is it possible to add a function (or static script)
I'm just wondering...is it possible to use Java to convert a .mp3 file into
I was just wondering if this is possible. I have a site that admins
I am just wondering if it is possible to have a condition that passes
Am just wondering is this possible to use FPTwebRequest to call a file share.
I'm just wondering if it's possible to use one regular expression to match another,
Just wondering if what I want to do is possible with Solr: I have
just wondering is it possible to use mixed mode on sql server 2005 for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.