Accueil > WordPress > Navigation entre articles Wordpress
Navigation entre articles Wordpress
vendredi 21 janvier 2011, par
Pour naviguer d’article en article sous Wordpress, tout en restant dans la même rubrique.
Mise à jour le 20/01/2020
A écrire dans le fichier functions.php de votre thème sous Genesis.
add_action( 'genesis_entry_footer', 'custom_single_nav' );
function custom_single_nav() {
if ( ! is_singular( 'post' ) )
return;
genesis_markup( array(
'html5' => '<div %s>',
'xhtml' => '<div class="navigation">',
'context' => 'adjacent-entry-pagination',
) );
echo '<div class="pagination-previous alignleft">';
next_post_link('%link', '%title', TRUE);
echo '</div>';
echo '<div class="pagination-next alignright">';
previous_post_link('%link', '%title', TRUE);
echo '</div>';
echo '</div>';
}
Publié en 2011
Il faut insérer le code suivant dans la page single.php
<div id="nav-art">
<div id="nav-art-right">
<?php previous_post(' %', 'Article plus ancien » <br />', 'yes', 'yes'); ?>
</div>
<div id="nav-art-left" >
<?php next_post(' %', ' « Article plus récent <br />', 'yes', 'yes'); ?>
</div>
</div>
Puis rajouter les caractéristiques des id dans la feuille de style
#nav-art{
width: 620px;
margin-top: 20px;
clear: both;
}
#nav-art-left{
width: 300px;
float:left;
}
#nav-art-right{
width: 300px;
float: right;
text-align: right;
Pour le framework Genesis
<div id="prev-next">
<div class="prev-link">←
<?php previous_post_link('%link', '%title'); ?>
</div>
<div class="next-link"> →
<?php next_post_link('%link', '%title'); ?>
</div>
</div>
<?php get_footer(); ?>
Et dans functions.php ajouter
/** Add Previous & Next Links in Genesis Single Post Page */
function genesis_post_navigation() {
if ( is_single ( ) ) { ?>
<div id="prev-next">
<div class="prev-link">←
<?php previous_post_link('%link', '%title'); ?>
</div>
<div class="next-link">→
<?php next_post_link('%link', '%title'); ?>
</div>
</div>
<?php
} }
add_action('genesis_after_post_content', 'genesis_post_navigation');