J'utilise Underscores.me pour un projet. J'aimerais ajouter l'image sélectionnée (la vignette) aux liens de publication précédents/suivants. Ils ont une fonction que je tente d’éditer, appelée THEMENAME_post_nav()
. Je me bats pour modifier cette fonction pour qu’elle inclue les vignettes. Quelqu'un peut-il aider s'il vous plaît? Voici le code:
function THEMENAME_post_nav() {
// Don't print empty markup if there's nowhere to navigate.
$previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
$next = get_adjacent_post( false, '', false );
// This is how I'm trying to include the thumbnails
$prevthumbnail = get_the_post_thumbnail($previous->ID);
$nextthumbnail = get_the_post_thumbnail($next->ID);
if ( ! $next && ! $previous ) {
return;
}
?>
<nav class="navigation post-navigation" role="navigation">
<h1 class="screen-reader-text"><?php _e( 'Post navigation', 'THEMENAME' ); ?></h1>
<div class="nav-links">
<?php
previous_post_link( '<div class="nav-previous">%link</div>$prevthumbnail', _x( '<span class="meta-nav">←</span> %title', 'Previous post link', 'THEMENAME' ) );
next_post_link( '<div class="nav-next">%link</div>$nextthumbnail', _x( '%title <span class="meta-nav">→</span>', 'Next post link', 'THEMENAME' ) );
?>
</div><!-- .nav-links -->
</nav><!-- .navigation -->
<?php
}
J'ai résolu le problème en utilisant get_the_post_thumbnail()
à la place des variables $prevthumbnail
et $nextthumbnail
.
function THEMENAME_post_nav() {
// Don't print empty markup if there's nowhere to navigate.
$previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
$next = get_adjacent_post( false, '', false );
if ( ! $next && ! $previous ) {
return;
}
?>
<nav class="navigation post-navigation" role="navigation">
<!-- <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'THEMENAME' ); ?></h1> -->
<div class="nav-links">
<?php
previous_post_link( '<div class="nav-previous">' . get_the_post_thumbnail() . '%link</div>', _x( '%title', 'Previous post link', 'THEMENAME' ) );
next_post_link( '<div class="nav-next">' . get_the_post_thumbnail() . '%link</div>', _x( '%title', 'Next post link', 'THEMENAME' ) );
?>
</div><!-- .nav-links -->
</nav><!-- .navigation -->
<?php
}
previous_post_link( '<div class="nav-previous">%link</div>$prevthumbnail', _x( '<span class="meta-nav">←</span> %title', 'Previous post link', 'THEMENAME' ) ); next_post_link( '<div class="nav-next">%link</div>$nextthumbnail', _x( '%title <span class="meta-nav">→</span>', 'Next post link', 'THEMENAME' );
Il me semble que vous avez involontairement placé les variables $prevthumbnail
et $nexxtthumbnail
entre guillemets simples.
Après ce que je viens de dire, je voudrais essayer ceci:
previous_post_link( '<div class="nav-previous">%link</div>'. $prevthumbnail, _x( '<span class="meta-nav">←</span> %title', 'Previous post link', 'THEMENAME' ) );
next_post_link( '<div class="nav-next">%link</div>' . $nextthumbnail, _x( '%title <span class="meta-nav">→</span>', 'Next post link', 'THEMENAME' );