Creating pagination with Fishpig
Asked Answered
T

1

8

I'm displaying 3 posts on my homepage and I need to have either a next page, previous page type functionality. I'd also like to incorporate 1,2,3,4,5,6,7,8,9, ... type paging functionality on some areas of the site.

I tried doing this:

    <span class="page-skips">
        <?php if (($previous = $page->getPreviousPage()) !== false): ?>
            <a href="<?php echo $previous->getPermalink() ?>">&larr; <?php echo $this->__('Previous Page') ?></a>
        <?php endif; ?>
        <?php if (($next = $page->getNextPage()) !== false): ?>
            <a href="<?php echo $next->getPermalink() ?>"><?php echo $this->__('Next Page') ?> &rarr;</a>
        <?php endif; ?>
    </span>

but getPreviousPage / getNextPage are obviously not functions. any ideas?

Tera answered 24/3, 2014 at 20:56 Comment(2)
You have already check this: magento.stackexchange.com/a/55357 (post paging) and this: savethefix.wordpress.com/2011/07/13/… ?Jeuz
For wordpress please check below link may be it will help you. wpbeginner.com/wp-themes/…Herrle
D
0

Wordpress provides inbuilt predefined methods for pagination which will show Next and Previous buttons automatically and Page numbers as well.

Use Method paginate_links() https://developer.wordpress.org/reference/functions/paginate_links/

So for exmaple you have a wordpress query like

$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;

$args = array(
    'posts_per_page' => 5,
    'category_name' => 'gallery',
    'paged' => $paged,
);

$the_query = new WP_Query( $args );

Then you can implement pagination like below

$big = 999999999; // need an unlikely integer

echo paginate_links( array(
    'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    'format' => '?paged=%#%',
    'current' => max( 1, get_query_var('paged') ),
    'total' => $the_query->max_num_pages
) );
Discommon answered 19/7 at 7:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.