How display page switcher in WordPress. 3 function open

How display page switcher in WordPress. 3 function

Approved. Code works!
This is exactly the working code that is verified by the moderator or site administrators
Tested: Wordress 4.0+, PHP 5.6 +

In the loop where any of your entries are displayed, you can always display a page switcher.

The number of posts displayed can be edited in the admin panel of yours site.

The number of posts displayed can be edited in the admin panel
The number of posts displayed can be edited in the admin panel

posts_nav_link

With this function, your navigation will look like this:

Posts nav link navigation looks like
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'entry' ); ?>

<?php posts_nav_link(); ?> //post_nav_link function

<?php posts_nav_link(' . ', 'Prev Page', 'Next Page'); ?> //same function but with parameters

<?php endwhile; endif; ?>

Learn more about this function – post_nav_link()

If you want to split the buttons “Next Page” and “Previous Page”

To put these buttons in different places of the template or wrap them in different HTML tags, will help function:

<?php previous_posts_link('Prev link'); ?>
<?php next_posts_link('Next link'); ?>

the_posts_pagination

With this function, your navigation will look like this:

With the_posts_pagination your navigation will look like this

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'entry' ); ?>

<?php the_posts_pagination(); ?> // the_posts_pagination function

<?php the_posts_pagination(array(
'prev_text' => 'Previous link',
'nex_text' => 'Previous link'
)); ?>  // the_posts_pagination function can get many parameters, you can read more about them at the link below

<?php endwhile; endif; ?>

Learn more about this function – the_posts_pagination()

echo_paginate_links

With this function, your navigation will look like this:

This is what yours page swither will be look like with paginate_links()

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'entry' ); ?>

<?php echo_paginate_links() ?> // echo_paginate_links function, this function can also take many parameters, read more at the link below

<?php endwhile; endif; ?>

Learn more about this function – the_posts_pagination()

Now navigation will be turned on for 10 posts on the page (this is a setting from the admin panel), but how to turn on navigation for different numbers of posts on different pages

We talked about navigation for posts page, but there is also navigation for one post that allows you to split it into several parts

0

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation