wake-up-neo.net

Underscores.me ruft die Miniaturansicht des nächsten/vorherigen Beitrags in der Funktion post_nav ab

Ich benutze Underscores.me für ein Projekt. Ich möchte das vorgestellte Bild (Thumbnail) zu den Links des vorherigen/nächsten Beitrags hinzufügen. Sie haben eine Funktion namens THEMENAME_post_nav(), die ich zu bearbeiten versuche. Ich habe Mühe, diese Funktion zu optimieren, damit sie die Thumbnails enthält. Kann jemand bitte helfen? Hier ist der 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">&larr;</span> %title', 'Previous post link', 'THEMENAME' ) );
            next_post_link( '<div class="nav-next">%link</div>$nextthumbnail', _x( '%title <span class="meta-nav">&rarr;</span>', 'Next post link', 'THEMENAME' ) );
        ?>
    </div><!-- .nav-links -->
</nav><!-- .navigation -->
<?php
} 
2
mtwallet

Ich habe das Problem gelöst, indem ich get_the_post_thumbnail() anstelle der Variablen $prevthumbnail und $nextthumbnail verwendet habe.

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

}

1
mtwallet
 previous_post_link( '<div class="nav-previous">%link</div>$prevthumbnail', _x( '<span class="meta-nav">&larr;</span> %title', 'Previous post link', 'THEMENAME' ) );
 next_post_link( '<div class="nav-next">%link</div>$nextthumbnail', _x( '%title   <span class="meta-nav">&rarr;</span>', 'Next post link', 'THEMENAME' );

Mir scheint, Sie haben die Variablen $prevthumbnail und $nexxtthumbnail unbeabsichtigt in einfache Anführungszeichen gesetzt.

Nach dem, was ich gerade gesagt habe, würde ich Folgendes versuchen:

previous_post_link( '<div class="nav-previous">%link</div>'. $prevthumbnail, _x( '<span class="meta-nav">&larr;</span> %title', 'Previous post link', 'THEMENAME' ) );
next_post_link( '<div class="nav-next">%link</div>' . $nextthumbnail, _x( '%title   <span class="meta-nav">&rarr;</span>', 'Next post link', 'THEMENAME' );
0
toni_lehtimaki