Support » Themes and Templates » Don't show post navigation when it's not necessary

  • Hello everyone,

    I am making a WordPress theme, but I have a problem.

    I want that if there are multiple posts pages (index.php and archives.php) then it needs to show the post-navigation. This is the following code of my post navigation:

    <div id="post-navigation">
    	<?php posts_nav_link(); ?>

    But the problem is, when there aren’t multiple pages for the posts than he shows the div, and I don’t want that.

    Can anyone help me?



Viewing 1 replies (of 1 total)
  • Check any of the default themes.
    There is a function (template tag, mostly in inc/template-tags.php) called twentysomething_paging_nav(). This starts with a conditional, something like this:

    if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {

    If no paging navigation is needed, nothing is printed.

    Alternatively, if no backwards compatibility is needed, you can use the new core template tags (4.1 and higher) the_posts_navigation() and the_posts_pagination(). See this post for more information about these new template tags.

Viewing 1 replies (of 1 total)
  • The topic ‘Don't show post navigation when it's not necessary’ is closed to new replies.