function knaeckebrot_content_nav( $html_id ) {
global $wp_query;
if ( $wp_query->max_num_pages > 1 ) : ?>
<nav id="<?php echo esc_attr( $html_id ); ?>" class="other-posts">
<h3 class="screen-reader-text">Beitrags-Navigation</h3>
<div class="older-posts"><?php next_posts_link( __('Ältere Einträge') );?></div>
<div class="newer-posts"><?php previous_posts_link( __('Neuere Einträge') ); ?></div>
</nav>
<?php endif;
}
Anwendung: <?php knaeckebrot_content_nav('nav-below'); ?>, wobei nav-below die ID für das nav-Element ist.
Um den Links noch Klassen mitzugeben, sind zusätzlich Filter notwendig:
add_filter('next_posts_link_attributes', 'posts_link_attributes');
add_filter('previous_posts_link_attributes', 'posts_link_attributes');
function posts_link_attributes() {
return 'class="btn"';
}
// Quelle: https://css-tricks.com/snippets/wordpress/add-class-to-links-generated-by-next_posts_link-and-previous_posts_link/