PageRenderTime 10ms CodeModel.GetById 2ms app.highlight 3ms RepoModel.GetById 1ms 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/**
 23 * Add Page Navigation Links
 24 * 
 25 * Adds "Previous Post" and "Next Post" links 
 26 * to single blog posts, and adds "Older Posts" 
 27 * and "Newer Posts" links to paginated archive 
 28 * index pages.
 29 * 
 30 * This function hooked into the micro_after_posts hook, 
 31 * which is defined in /inc/hooks.php, and which fires
 32 * in the footer.php template file.
 33 * 
 34 * Child Themes can remove this output by calling 
 35 * remove_action( 'micro_after_posts', 'micro_attach_navigation' );
 36 * 
 37 * Template file: footer.php
 38 * 
 39 * @uses	micro_get_the_page_count()	Defined in /inc/navigation.php
 40 * 
 41 * @link 	http://codex.wordpress.org/Function_Reference/is_single 			is_single()
 42 * @link 	http://codex.wordpress.org/Function_Reference/previous_post_link 	previous_post_link()
 43 * @link 	http://codex.wordpress.org/Function_Reference/next_post_link 		next_post_link()
 44 * @link 	http://codex.wordpress.org/Function_Reference/get_query_var 		get_query_var()
 45 * @link 	http://codex.wordpress.org/Function_Reference/previous_posts_link	previous_posts_link()
 46 * @link 	http://codex.wordpress.org/Function_Reference/next_posts_link		next_posts_link()
 47 * @link 	http://codex.wordpress.org/Function_Reference/is_archive 			is_archive()
 48 * @link 	http://codex.wordpress.org/Function_Reference/is_category 			is_category()
 49 * @link 	http://codex.wordpress.org/Function_Reference/is_tag 				is_tag()
 50 * @link 	http://codex.wordpress.org/Function_Reference/is_home 				is_home()
 51 * @link 	http://codex.wordpress.org/Function_Reference/is_author 			is_author()
 52 * @link 	http://codex.wordpress.org/Function_Reference/is_search 			is_search()
 53 * 
 54 * @param	none
 55 * @return	string	HTML markup for page navigation links
 56 * 
 57 * @since	Micro 1.0
 58 * 
 59 */
 60function micro_attach_navigation(){
 61	
 62	global $up_options, $wp_query;
 63	
 64	if( empty($up_options->attach_navigation) ): ?>
 65	
 66	<div id="post-navigation">
 67
 68		<?php if( is_single() ): ?>
 69
 70			<ul id="pages">
 71				<li class="prev-page"><?php previous_post_link('%link',"<span>&larr; Previous Post: %title</span>"); ?></li>
 72				<li class="next-page"><?php next_post_link('%link',"<span>Next Post: %title &rarr;</span>"); ?></li>
 73			</ul>
 74		
 75		<?php else: ?>
 76
 77			<?php
 78			$paged = get_query_var('paged');
 79			$maxpage = $wp_query->max_num_pages;
 80	
 81			if( $maxpage > 1 ): ?>
 82	
 83			<ul id="pages">
 84				<?php
 85
 86				echo '<li class="prev-page">';
 87				previous_posts_link( "<span>" . __('&larr; Newer Posts','micro') . "</span>" );
 88				echo '</li>';
 89?>
 90				<li class="number"><?php if( is_archive() || is_category() || is_tag() || is_home() || is_author() || is_search() ) micro_get_the_page_count(); ?></li>
 91<?php
 92				echo '<li class="next-page">';
 93				next_posts_link( "<span>" . __('Older Posts &rarr;','micro') . "</span>" );
 94				echo '</li>';
 95
 96				?>
 97			</ul>
 98			
 99			<?php endif; ?>
100		
101		<?php endif; ?>
102		
103	</div>
104
105	<?php
106
107	endif;
108
109}
110// Hook micro_attach_navigation() into micro_after_posts
111add_action( 'micro_after_posts', 'micro_attach_navigation' );
112
113/**
114 * Echo Current Page Count
115 * 
116 * Echoes the current page count for paginated 
117 * archive index pages.
118 * 
119 * This function is called by micro_attach_navigation(),
120 * which outputs navigation links in footer.php
121 * 
122 * Template file: footer.php
123 * 
124 * @link 	http://codex.wordpress.org/Function_Reference/_e 				_e()
125 * @link 	http://codex.wordpress.org/Function_Reference/get_query_var 	get_query_var()
126 * @link 	http://codex.wordpress.org/Function_Reference/is_paged 			is_paged()
127 * 
128 * @param	none
129 * @return	string	Current page, as "Page X of Y"
130 * 
131 * @since	Micro 1.0
132 * 
133 */
134function micro_get_the_page_count(){
135
136		global $wp_query;
137	
138		$paged = get_query_var( 'paged' );
139		$maxpage = $wp_query->max_num_pages;
140		
141		if( is_paged() )
142			$current_page = $paged;
143		else
144			$current_page = '1';
145					
146		_e( "Page {$current_page} of {$maxpage}", "micro" );
147
148}