WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 2 years ago

#39251 new defect (bug)

Support end_size=0 in paginate_links()

Reported by: danielbachhuber Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch has-unit-tests
Focuses: Cc:
PR Number:

Description (last modified by danielbachhuber)

Passing end_size=0 produces one link when I'd expect it to produce zero links.

When using paginate_links() on the homepage of a site with thousands of posts, having an end size link of 1885, etc. is a bit crazy.

Attachments (1)

39251.patch (1.9 KB) - added by birgire 2 years ago.

Download all attachments as: .zip

Change History (4)

#1 @danielbachhuber
3 years ago

  • Description modified (diff)

@birgire
2 years ago

#3 @birgire
2 years ago

  • Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed

This:

$links = paginate_links( array(
    'total'         => 10,
    'current'       => 5,
    'mid_size'      => 1,
    'end_size'      => 0,
) );

will generate:

Previous 1 ... 4 [5] 6 ... 10 Next

but with 39251.patch it generates:

Previous ... 4 [5] 6 ... Next

PS:

We might get a better control if we supported e.g. arrays like:

'end_size' => array( 1, 0 ),  // left and right parts
'mid_size' => array( 1, 2 ),  // left and right parts

to generate:

Previous 1 ... 4 [5] 6 7 ... Next

Just thinking out loud, I wonder if it would be more flexible with e.g.

echo paginate_links( array(
        'walker'  	=> new RomanNumeralsPaginator,
) );

where the default paginator class would handle paginating objects and mimic some parts of the wp_nav_menu().

... or something more suitable than a walker.

But maybe it would be too much ;-)

Last edited 2 years ago by birgire (previous) (diff)
Note: See TracTickets for help on using tickets.