Читать книгу Professional WordPress Plugin Development - Brad Williams - Страница 113

Pagination

Оглавление

If your plugin contains a list of records, you may have a need for pagination, which is the method to break lists of data into multiple pages and have links to load each individual page. This helps reduce the load times and makes it a much cleaner user experience to navigate through the data. Would you rather view 500 records on a page or 10 pages with 50 records on each page?

WordPress has a few different classes to style your pagination. The following is an example:

<div class="tablenav"> <div class="tablenav-pages"> <span class="displaying-num">Displaying 1-20 of 69</span> <span class="page-numbers current">1</span> <a href="#" class="page-numbers">2</a> <a href="#" class="page-numbers">3</a> <a href="#" class="page-numbers">4</a> <a href="#" class="next page-numbers">&raquo;</a> </div> </div>

First, you need to wrap your pagination links in the tablenav and tablenav‐pages div classes. The displaying‐num class styles the records you view. The page‐numbers class styles the page links in the familiar WordPress format. Adding current or next to the link class can add some unique styles to those elements, as shown in Figure 3‐15.


FIGURE 3‐15: Pagination style

Keeping your plugin design consistent with the WordPress user interface can reduce your plugins' learning curve because users will feel comfortable with the design and styles used. This can also make your plugins' design future‐proof. If the WordPress core styles change down the road, your plugins' design will also change to match the new user interface, and you won't need to edit a single line of code!

Professional WordPress Plugin Development

Подняться наверх