简体   繁体   中英

How to get only the next post's link and the URL of the thumbnail?

Need link (only) of next and previous post (chronologically speaking). If is first or last post, then need link of last or first post respectively. Also, need the post-thumbnail for respective post.

Desired output:

<a href="[link to previous post]" class="previous">
  <div class="hover">
    <div style="background: url(<?php ... ?>) no-repeat center center;"></div>
  </div>
</a>

<a href="..." class="next">
.
.
.
</a>

What I've tried:

<?php previous_post_link( '%link', ...) but how can I insert all those other items inside of the `a` tags?

Thanks for taking the time.

looks like previous_post_link has a "link" parameter where you can customize the content of the link.

Have you tried something like the following?

<?php previous_post_link( '%link', '<div> ... %title ... </div>' ); ?>

Pssht : %title will be replaced with the title of the previous post (default behaviour).

Got the answer, but with one unwieldy block of code:

$date = get_the_time('j F Y'); 
$image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'single-post-thumbnail' );
      previous_post_link( 
        '%link', 
        '<div class="text"><div class="date">'.$date.'</div><h3>%title</h3></div><div class="hover"><div style="background: url('.$image[0].') no-repeat center center;"></div></div>'
      ); 

The variables are for the link and the feature image url.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM