-
-
Save tommcfarlin/763a68936f225834bba671a3d0a8b9f6 to your computer and use it in GitHub Desktop.
[WordPress] WordPress Pagination: A Simple Utility (And Why)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| global $wpdb; | |
| $results = $wpdb->get_results( | |
| $wpdb->prepare( | |
| " | |
| SELECT * | |
| FROM $wpdb->posts | |
| WHERE ID < ( | |
| SELECT ID | |
| FROM $wpdb->posts | |
| WHERE ID = %d | |
| AND post_type = '%s' | |
| AND post_status = '%s' | |
| ORDER BY ID DESC | |
| ) | |
| AND post_type = '%s' | |
| AND post_status = '%s' | |
| ORDER BY ID DESC | |
| LIMIT 1 | |
| ", | |
| get_the_ID(), | |
| 'acme-custom-post-type', | |
| 'publish', | |
| 'acme-custom-post-type', | |
| 'publish' | |
| ) | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| global $wpdb; | |
| $results = $wpdb->get_results( | |
| $wpdb->prepare( | |
| " | |
| SELECT * | |
| FROM $wpdb->posts | |
| WHERE ID > ( | |
| SELECT ID | |
| FROM $wpdb->posts | |
| WHERE ID = %d | |
| AND post_type = '%s' | |
| AND post_status = '%s' | |
| ORDER BY ID ASC | |
| ) | |
| AND post_type = '%s' | |
| AND post_status = '%s' | |
| ORDER BY ID ASC | |
| LIMIT 1 | |
| ", | |
| get_the_ID(), | |
| 'acme-custom-post-type', | |
| 'publish', | |
| 'acme-custom-post-type', | |
| 'publish' | |
| ) | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * @param array $results the results of the query to determined if there are past posts | |
| * | |
| * @return bool true if there is a previous post; otherwise, false | |
| */ | |
| private function hasPreviousPost($results) | |
| { | |
| return isset($results[0]); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * @param array $results the results of the query to determined if there are future posts | |
| * | |
| * @return bool true if there is a next post; otherwise, false | |
| */ | |
| private function hasNextPost($results) | |
| { | |
| return isset($results[0]); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * @param array $results the results of the array from which to retrieve the post ID | |
| * | |
| * @return string the ID of the post to which we're going to link | |
| */ | |
| private function getPostLink($results) | |
| { | |
| return get_the_permalink($results[0]->ID); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment