Opened 10 years ago
Last modified 6 years ago
#29972 new enhancement
Split pagination calculations and HTML in paginate_links
Reported by: | dylanj | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.0 |
Component: | General | Keywords: | has-patch |
Focuses: | template | Cc: |
Description
The current implementation of paginate_links has a number of issues. It has been improved significantly in the latest version, however there is still room for more improvements.
Currently, the function forces you to use the HTML as it has been returned. If you want to add a class onto something, there is no easy way to do it - you're stuck with the defaults as they are hard-coded.
The first step towards fixing this is to split the pagination calculations from the HTML. Sort out what's going to go where, and then go and build the HTML and return it.
My reasoning is below, take a look and see what you think. I'm not necessarily advocating my particular fix, but I believe at the very least it needs some discussion.
This change will make it easier to create features such as custom classes for elements, and will make the code easier to read and maintain.
Also this is my first time creating a ticket on WordPress Trac, so go easy :)
Return raw array data
If you want to write your own completely custom HTML, you currently have to either copy+paste the function and modify it to suit your needs, or write a whole new one from scratch. The function should be able to return an array containing these values for each pagination item:
- type (next/prev/dots/page)
- link (where the item links to)
- text (the text to be displayed within the link)
- active (so you can apply your own active class)
This allows for more flexible use of the function within the template.
Customize the default output
Sometimes, you might just want to add an extra class to an item or two. Now, you could add these features to the current code, but the section for the active element is split from the normal elements which means you'd have to duplicate code to do it.
Change the currently selected page element
I've added a new arg 'link_current' so you can change the default element of the selected page to an A tag instead of the SPAN. I needed this for our specific design, but thought other people might find it useful as well.
Full proposed version of paginate_links