1. Add Numbered Page Navigation In Thesis Without Plugin
  2. function numbered_page_nav($prelabel = '', $nxtlabel = '', $pages_to_show = 8, $always_show = false) {
  3. global $request, $posts_per_page, $wpdb, $paged;
  4. $custom_range = round($pages_to_show/2);
  5. if (!is_single()) {
  6. if(!is_category()) {
  7. preg_match('#FROM\s(.*)\sORDER BY#siU', $request, $matches);
  8. }
  9. else {
  10. preg_match('#FROM\s(.*)\sGROUP BY#siU', $request, $matches);
  11. }
  12. $blog_post_count = $matches[1];
  13. $numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $blog_post_count");
  14. $max_page = ceil($numposts /$posts_per_page);
  15. if(empty($paged)) {
  16. $paged = 1;
  17. }
  18. if($max_page > 1 || $always_show) {
  19. echo "<div class='page-nav'><div class='page-nav-intro'>Page $paged of $max_page</div>";
  20. if ($paged >= ($pages_to_show-2)) {
  21. echo '<div class="page-number"><a href="'.get_pagenum_link().'">1</a></div><div class="elipses">...</div>';
  22. }
  23. for($i = $paged - $custom_range; $i <= $paged + $custom_range; $i++) {
  24. if ($i >= 1 && $i <= $max_page) {
  25. if($i == $paged) {
  26. echo "<div class='current-page-number'>$i</div>";
  27. }
  28. else {
  29. echo '<div class="page-number"><a href="'.get_pagenum_link($i).'">'.$i.'</a></div>';
  30. }
  31. }
  32. }
  33. if (($paged+$custom_range) < ($max_page)) {
  34. echo '<div class="elipses">...</div><div class="page-number"><a href="'.get_pagenum_link($max_page).'">'.$max_page.'</a></div>';
  35. }
  36. echo "</div>";
  37. }
  38. }
  39. }
  40. remove_action('thesis_hook_after_content', 'thesis_post_navigation');
  41. add_action('thesis_hook_after_content', 'numbered_page_nav');
  42. /* NUMBERED PAGE NAV */ .page-nav { font-size: 1.35em; font-weight: bold; margin: 1em 0; padding: 0; overflow: hidden; } .page-nav-intro { float: left; padding: .3em .5em; margin: 0 1em 1em 0; background: #efefef; border: .1em solid #ccc; } .page-number { float: left; padding: .3em .5em; margin: 0 .2em; background: #fff; border: .1em solid #ccc; } .current-page-number { float: left; padding: .3em .5em; margin: 0 .2em; background: #efefef; border: .1em solid #ccc; } .elipses { float: left; padding: .3em .2em; }