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

  • Home
  • SEARCH
  • 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 959739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:04:25+00:00 2026-05-16T01:04:25+00:00

I am building a wordpress theme I want to have the next and previous

  • 0

I am building a wordpress theme I want to have the next and previous DIV only appear IF their is a next and previous button available.

If there is 10 posts and the display limit is 10 posts I don’t want an empty div. However when there are 20 posts and the display limit is 10 I want the next and previous buttons to show in there own div.

I got this far and realized that posts_nav_link() doesn’t return null.

function next_previous_div(){
print '<!-- ';
$output = posts_nav_link();
print " -->\n";
if ($output != null) 
    {   
        echo '<div class="float post" style="text-align:center">';
        echo posts_nav_link();
        echo '</div><!-- end post-->';
    };
};
  • 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-05-16T01:04:25+00:00Added an answer on May 16, 2026 at 1:04 am

    There are a few different ways you could test if you’ll have a previous/next link:

    Test $wp_query->max_num_pages

    Get a global reference to the $wp_query object and see if it’s greater than 1. If yes, you’ve got paging links:

    global $wp_query;
    if($wp_query->max_num_pages > 1){
       posts_nav_link();
    }
    

    Capture the output of posts_nav_link()

    This function echos by default, which is why your null test isn’t working. You need to capture the echoed output and then test:

    // Capture the echoed output in the $links variable and test on it
    ob_start();
    posts_nav_link();
    $links = ob_get_clean();
    
    if(strlen($links) > 0){
        echo $links;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a WordPress theme for a small startup. They want to have
I am building a custom wordpress theme and have a slideshow on the front
i am building a wordpress site, twenty eleven theme. I want a widget area
I'm building a Wordpress theme, and I have these snippets in my style.css: #content
I have jQuery for a WordPress theme I'm building. I've given up for now
I'm currently building a WordPress theme that I would like to have a header
im building off the wordpress plaintxt sandbox theme, and what i have i a
I am building out my first WordPress site for a client. I really want
I'm building a theme options page for my WordPress theme and I would like
I am building my first site in wordpress. I want to get the data

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.