Quantcast
Channel: Michael (aka alchymyth) – TransformationPowerTools
Viewing all articles
Browse latest Browse all 12

Integrate Pagination Plugins into Twenty Twelve

$
0
0

The ‘next/prev’ posts links are done with a function in Twenty Twelve; twentytwelve_content_nav().

That function is pluggable, which makes it easy to change it in a child theme of Twenty Twelve.
To integrate for instance the plugin ‘wp_pagenavi’, you would need to change the function as follows (when you are using a child theme, add this into functions.php of the child theme; else edit the function in Twenty Twelve):

function twentytwelve_content_nav( $html_id ) {
	global $wp_query;

	$html_id = esc_attr( $html_id );

	if ( $wp_query->max_num_pages > 1 ) : ?>
		<nav id="<?php echo $html_id; ?>" class="navigation" role="navigation">
			<h3 class="assistive-text"><?php _e( 'Post navigation', 'twentytwelve' ); ?></h3>
		<?php if( function_exists( 'wp_pagenavi' ) ) { wp_pagenavi(); } else { ?>	
			<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentytwelve' ) ); ?></div>
			<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); ?></div>
		<?php } ?>
		</nav><!-- #<?php echo $html_id; ?> .navigation -->
	<?php endif;
}

the use of the conditional check if( function_exists( 'wp_pagenavi' ) ) prevents an error message if the plugin is not activated, and provides the theme’s default pagination as a fallback.


Viewing all articles
Browse latest Browse all 12

Trending Articles