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 9208179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:33:40+00:00 2026-06-18T00:33:40+00:00

In my admin I have 12 posts tagged with ‘Efforts’, though there are lots

  • 0

In my admin I have 12 posts tagged with ‘Efforts’, though there are lots of other posts.

The 3 most recent posts tagged with ‘Efforts’ show up on the homepage, the rest show up in a page, not surprisingly titled “Efforts”

On that Efforts page I needed to have pagination with 5 posts per page but alos have it offset by 3.

On a blog post an can no longer seem to locate, the Following was suggested:

$temp = $wp_query;

$number_of_posts_per_page = 5;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$number_of_posts_past = $number_of_posts_per_page * ($paged - 1);
$off = 3 + (($paged > 1) ? $number_of_posts_past : 0);

wp_reset_query();
wp_reset_postdata();

$wp_query = new WP_Query('category_name=efforts&posts_per_page='.$number_of_posts_per_page.'&offset='.$off);

That works great except that there is one too many paginated pages and the last page is blank.

Why does the ‘Previous Entries’ link show up on page 2 and take you to a blank page.

Here’s the full code for reference:

<?php
global $options;
foreach ($options as $value) {
    if (get_settings( $value['id'] ) === FALSE) { 
        $$value['id'] = stripslashes( $value['std'] ); 
    } else { 
        $$value['id'] = stripslashes( get_settings( $value['id'] ) ); 
    } 
}
?>
<?php get_header(); ?>

<?php /* Enables two or three columns */
if ($et_threecolumn_disable == "false") { ?> <?php include(TEMPLATEPATH."/sidebar.php");?><?php } ?>

<div class="content <?php if ($et_threecolumn_disable == "false") { ?> <?php echo $et_columnorder; ?> <?php } else { ?> content-two-column<?php echo $et_columnorder; ?> <?php } ?>">
<?php
$temp = $wp_query;

$number_of_posts_per_page = 5;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$number_of_posts_past = $number_of_posts_per_page * ($paged - 1);
$off = 3 + (($paged > 1) ? $number_of_posts_past : 0);

wp_reset_query();
wp_reset_postdata();

$wp_query = new WP_Query('category_name=efforts&posts_per_page='.$number_of_posts_per_page.'&offset='.$off);



if (have_posts()) : while (have_posts()) : the_post();
    $video = get_post_custom_values('YT_video_id');
?>

<div class="post" id="post-<?php the_ID(); ?>">
    <h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
    <h2><?php the_time('F jS, Y') ?> | <?php the_category(', ') ?> | <?php comments_popup_link('0 Comments', '1 Comment', '% Comments'); ?></h2>

    <div class="entry">
        <?php the_content('Read More'); ?>

        <iframe id="player" type="text/html" width="600" height="355" src="http://www.youtube.com/embed/<?php echo $video[0] ?>" frameborder="0"></iframe>

        <?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
    </div>

    <?php if (function_exists('the_tags')) { the_tags('<p class="postmetadata">Tags: ', ', ', '</p>'); } ?>
</div>

<?php endwhile; endif; ?>


<div class="navigation">
    <div class="alignleft"><?php next_posts_link('&larr; Previous Entries') ?></div>
    <div class="alignright"><?php previous_posts_link('Next Entries &rarr;') ?></div>
</div>
<?php wp_reset_query(); $wp_query = null; $wp_query = $temp;?>

</div>


<?php include(TEMPLATEPATH."/primary-sidebar.php");?>

<?php get_footer(); ?>  
  • 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-18T00:33:42+00:00Added an answer on June 18, 2026 at 12:33 am

    I ran a few tests.

    $temp = $wp_query;
    
    $number_of_posts_per_page = 5;
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $number_of_posts_past = $number_of_posts_per_page * ($paged - 1);
    $off = 3 + (($paged > 1) ? $number_of_posts_past : 0);
    
    wp_reset_query();
    wp_reset_postdata();
    
    $wp_query = new WP_Query('category_name=efforts&posts_per_page='.$number_of_posts_per_page.'&offset='.$off);
    
    $wp_query->found_posts; // 12
    

    So found_posts seems to be ignoring offset and posts_per_page.
    And since according to the codex max_num_pages is calculated as $found_posts / $posts_per_page it was coming out to 3 pages.

    I needed to calculate my own max_pages to feed to the pagination links.

    $temp = $wp_query;
    
    $number_of_posts_per_page = 5;
    $initial_offset = 3;
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $number_of_posts_past = $number_of_posts_per_page * ($paged - 1);
    $off = $initial_offset + (($paged > 1) ? $number_of_posts_past : 0);
    
    wp_reset_query();
    wp_reset_postdata();
    
    $wp_query = new WP_Query('category_name=efforts&posts_per_page='.$number_of_posts_per_page.'&offset='.$off);
    
    $max_pages = ceil(($wp_query->found_posts - $initial_offset) / $number_of_posts_per_page);
    
    // snipped a bunch of post related code that worked fine
    
    <div class="navigation">
        <div class="alignleft"><?php next_posts_link('&larr; Previous Entries', $max_pages) ?></div>
        <div class="alignright"><?php previous_posts_link('Next Entries &rarr;', $max_pages) ?></div>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have selected to show 5 posts per page in admin panel. And we
I have to admin there is slight difference between the columns from both tables.
I have set 10 posts to display per page from WordPress admin panel, but
In order to apply some changes to the default Recent Posts Widget I have
I have this setup in my routes: namespace :admin do resources :posts end so
I have a custom field in my posts so the admin can enter a
All, I have read several other posts before posing my question to you. I
I have a controller like follows: namespace :admin do resources :posts end # app/controllers/admin_posts_controller.rb
I have this PHP code in a loop for every post on the admin
I have a path defined: when /the admin home\s?page/ /admin/ I have scenario that

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.