如何在single.php上的上一个/下一个导航中使用特色图像

时间:2015-03-15 11:24:13

标签: php wordpress

我在wordpress中使用二十五个主题。我想在single.php的后期导航中添加精选图片

导航代码是

the_post_navigation( array(
      'next_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Next', 'twentyfifteen' ) . '</span> ' .
          '<span class="screen-reader-text">' . __( 'Next post:', 'twentyfifteen' ) . '</span> ' .
          '<span class="post-title">%title</span>',
      'prev_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Previous', 'twentyfifteen' ) . '</span> ' .
          '<span class="screen-reader-text">' . __( 'Previous post:', 'twentyfifteen' ) . '</span> ' .
          '<span class="post-title">%title</span>',
  ) );

如何在此代码中添加图片?

1 个答案:

答案 0 :(得分:9)

使用Wordpress函数 get_next_post get_previous_post 获取下一个和上一个帖子ID。然后,您可以使用 get_the_post_thumbnail 。像这样:

    // Previous/next post navigation.
    $next_post = get_next_post();
    $previous_post = get_previous_post();
    the_post_navigation( array(
        'next_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Next', 'twentyfifteen' ) . '</span> ' .
            '<span class="screen-reader-text">' . __( 'Next post:', 'twentyfifteen' ) . '</span> ' .
            '<span class="post-title">%title</span>' . get_the_post_thumbnail($next_post->ID,'thumbnail'),
        'prev_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Previous', 'twentyfifteen' ) . '</span> ' .
            '<span class="screen-reader-text">' . __( 'Previous post:', 'twentyfifteen' ) . '</span> ' .
            '<span class="post-title">%title</span>' . get_the_post_thumbnail($previous_post->ID,'thumbnail'),
    ) );