PageRenderTime 120ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/inc/navigation.php

https://github.com/envex/Micro-Theme
PHP | 148 lines | 45 code | 24 blank | 79 comment | 10 complexity | 7679255be2239114c8c928a8ef1fa042 MD5 | raw file
  1. <?php
  2. /**
  3. * Theme Navigation Functions file
  4. *
  5. * The /inc/navigation.php file defines
  6. * all of the Theme's custom, navigation functions
  7. * - micro_get_the_page_count()
  8. *
  9. * This file also defines navigation-related callback
  10. * functions hooked into custom Theme hooks
  11. * - micro_after_posts
  12. *
  13. * @link http://codex.wordpress.org/Function_Reference/add_action add_action()
  14. *
  15. * @package Micro
  16. * @copyright Copyright (c) 2011, UpThemes
  17. * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License, v2 (or newer)
  18. *
  19. * @since Micro 1.0
  20. */
  21. /**
  22. * Add Page Navigation Links
  23. *
  24. * Adds "Previous Post" and "Next Post" links
  25. * to single blog posts, and adds "Older Posts"
  26. * and "Newer Posts" links to paginated archive
  27. * index pages.
  28. *
  29. * This function hooked into the micro_after_posts hook,
  30. * which is defined in /inc/hooks.php, and which fires
  31. * in the footer.php template file.
  32. *
  33. * Child Themes can remove this output by calling
  34. * remove_action( 'micro_after_posts', 'micro_attach_navigation' );
  35. *
  36. * Template file: footer.php
  37. *
  38. * @uses micro_get_the_page_count() Defined in /inc/navigation.php
  39. *
  40. * @link http://codex.wordpress.org/Function_Reference/is_single is_single()
  41. * @link http://codex.wordpress.org/Function_Reference/previous_post_link previous_post_link()
  42. * @link http://codex.wordpress.org/Function_Reference/next_post_link next_post_link()
  43. * @link http://codex.wordpress.org/Function_Reference/get_query_var get_query_var()
  44. * @link http://codex.wordpress.org/Function_Reference/previous_posts_link previous_posts_link()
  45. * @link http://codex.wordpress.org/Function_Reference/next_posts_link next_posts_link()
  46. * @link http://codex.wordpress.org/Function_Reference/is_archive is_archive()
  47. * @link http://codex.wordpress.org/Function_Reference/is_category is_category()
  48. * @link http://codex.wordpress.org/Function_Reference/is_tag is_tag()
  49. * @link http://codex.wordpress.org/Function_Reference/is_home is_home()
  50. * @link http://codex.wordpress.org/Function_Reference/is_author is_author()
  51. * @link http://codex.wordpress.org/Function_Reference/is_search is_search()
  52. *
  53. * @param none
  54. * @return string HTML markup for page navigation links
  55. *
  56. * @since Micro 1.0
  57. *
  58. */
  59. function micro_attach_navigation(){
  60. global $up_options, $wp_query;
  61. if( empty($up_options->attach_navigation) ): ?>
  62. <div id="post-navigation">
  63. <?php if( is_single() ): ?>
  64. <ul id="pages">
  65. <li class="prev-page"><?php previous_post_link('%link',"<span>&larr; Previous Post: %title</span>"); ?></li>
  66. <li class="next-page"><?php next_post_link('%link',"<span>Next Post: %title &rarr;</span>"); ?></li>
  67. </ul>
  68. <?php else: ?>
  69. <?php
  70. $paged = get_query_var('paged');
  71. $maxpage = $wp_query->max_num_pages;
  72. if( $maxpage > 1 ): ?>
  73. <ul id="pages">
  74. <?php
  75. echo '<li class="prev-page">';
  76. previous_posts_link( "<span>" . __('&larr; Newer Posts','micro') . "</span>" );
  77. echo '</li>';
  78. ?>
  79. <li class="number"><?php if( is_archive() || is_category() || is_tag() || is_home() || is_author() || is_search() ) micro_get_the_page_count(); ?></li>
  80. <?php
  81. echo '<li class="next-page">';
  82. next_posts_link( "<span>" . __('Older Posts &rarr;','micro') . "</span>" );
  83. echo '</li>';
  84. ?>
  85. </ul>
  86. <?php endif; ?>
  87. <?php endif; ?>
  88. </div>
  89. <?php
  90. endif;
  91. }
  92. // Hook micro_attach_navigation() into micro_after_posts
  93. add_action( 'micro_after_posts', 'micro_attach_navigation' );
  94. /**
  95. * Echo Current Page Count
  96. *
  97. * Echoes the current page count for paginated
  98. * archive index pages.
  99. *
  100. * This function is called by micro_attach_navigation(),
  101. * which outputs navigation links in footer.php
  102. *
  103. * Template file: footer.php
  104. *
  105. * @link http://codex.wordpress.org/Function_Reference/_e _e()
  106. * @link http://codex.wordpress.org/Function_Reference/get_query_var get_query_var()
  107. * @link http://codex.wordpress.org/Function_Reference/is_paged is_paged()
  108. *
  109. * @param none
  110. * @return string Current page, as "Page X of Y"
  111. *
  112. * @since Micro 1.0
  113. *
  114. */
  115. function micro_get_the_page_count(){
  116. global $wp_query;
  117. $paged = get_query_var( 'paged' );
  118. $maxpage = $wp_query->max_num_pages;
  119. if( is_paged() )
  120. $current_page = $paged;
  121. else
  122. $current_page = '1';
  123. _e( "Page {$current_page} of {$maxpage}", "micro" );
  124. }