Skip Navigation

[Resolved] Display Thumbnail for next post

This thread is resolved. Here is a description of the problem and solution.

Problem:

I am using this shortcode below: [wpv-post-featured-image]

it is (like expected) displaying the featured image thumbnail to the current post. how would I modify this shortcode to display the featured image thumbnail to the next post instead of the current post?

Solution:

It needs custom codes, for example:

https://toolset.com/forums/topic/display-thumbnail-for-next-post/#post-1117593

Relevant Documentation:

This support ticket is created 6 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 0.80 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 8 replies, has 3 voices.

Last updated by ericm-13 6 years ago.

Assisted by: Luo Yang.

Author
Posts
#1117240

------ Tell us what you are trying to do?
I have a custom post type named 'Portfolios' where I am in it's content template 'T2 Portfolios (single)' trying to display the featured image to the next post, I am using this shortcode below:
[wpv-post-featured-image]
it is (like expected) displaying the featured image thumbnail to the current post.
how would I modify this shortcode to display the featured image thumbnail to the next post instead of the current post?

------ Is there any documentation that you are following?
https://toolset.com/documentation/user-guides/views-shortcodes/

#1117593

Long story short it needs some custom code.

You can pass an ID to the Featured Image ShortCode like so:
[wpv-post-featured-image item="1"]

You can replace the 1 in the "item" attribute with a Custom ShortCode that returns the next post in the loop, using the native WordPress function get_next_post()
https://codex.wordpress.org/Function_Reference/get_next_post

A ShortCode that returns the next post using this function can be crafted using these guidelines.
https://codex.wordpress.org/Shortcode_API
Example:

function next_post_id( ) {
	$next_post_id = get_next_post()->ID;
	return $next_post_id;
}
add_shortcode( 'next_post_id', 'next_post_id' );

Then you can use that in the Featured Image ShortCode as:
[wpv-post-featured-image item="[next_post_id]"]

It will display the featured image of the next post in the loop (single post type template, for example)

Don't forget to register this ShortCode in Toolset > Settings > Front end content > Third-party shortcode arguments, or it'll not work.

#1122884

Thank you!

#1122944

this works great to pull the next post ID, thank you so much again!
im not good with .php, how could this shortcode be modified to loop back to the first post if it is currently at the last post?

#1123297

Hello,

It needs custom codes, for example, you can modify the PHP codes as below:

function next_post_id() {
	$next_post = get_next_post();
	if(!$next_post){
		$args = array(
		  'numberposts' => 1,
		  'post_type'   => 'portfolios', // replace it with your post type slug
		  'order'	=> 'ASC',
		  'fields'	=> 'ids'
		);
		$first_post = get_posts( $args );
		$next_post_id = $first_post[0];
	}
    else{
		$next_post_id = get_next_post()->ID;
	}
    return $next_post_id;
}
add_shortcode( 'next_post_id', 'next_post_id' );
#1124660

My issue is resolved now. Thank you! You guys are awesome!!

#1125035

You are welcome

#1146679

Hello Luo!

thanks again for resolving this for me, I am using this method now to not only call the featured image, but also some normal and custom fields for the next post, these are the shortcodes I am using:

- this is calling the featured image for the next post:
[types field='primary-portfolio-image' title='%%TITLE%%' alt='%%ALT%%' align='center' size='full' item='[next_post_id]'][/types]

- this is outputting a link for the next post:
[wpv-post-next-link item='[next_post_id]' format="%%LINK%%" link="NEXT PROJECT"]

- this is calling the title for the next post:
[wpv-post-next-link item='[next_post_id]' format="%%LINK%%" link="%%TITLE%%"]

- this is calling a custom field for the next post
[types field='location' item='[next_post_id]'][/types]

- this is calling a custom field for the next post
[types field='number' output='raw' item='[next_post_id]'][/types]

this is being used at the bottom of each individual custom post 'portfolio' as you can see at the bottom of this page:
hidden link

it seems to be working just fine across all my posts.

my problem is, i can't seem to figure out at the bottom of this post in particular
hidden link

why these two shortcodes below are not displaying,
[wpv-post-next-link item='[next_post_id]' format="%%LINK%%" link="NEXT PROJECT"]
[wpv-post-next-link item='[next_post_id]' format="%%LINK%%" link="%%TITLE%%"]

but the rest of the shortcodes are displaying just fine

thank you so much in advanced Luo!!

#1146755

I figured it out, my shortcodes were all messed up, thank you Luo