73 | Integrate Pagination Plugins into Twenty Twelve

g+

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.

This entry was posted in Tips & Tricks, Twenty Twelve, WordPress and tagged , , , , , . Bookmark the permalink.

One Response to Integrate Pagination Plugins into Twenty Twelve

  1. Alba Flugum comments:

    I have learn several just right stuff here. Certainly price bookmarking for revisiting. I wonder how much attempt you put to make any such excellent informative web site.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*