Skip Navigation

[Resolved] Single Post Template with a Teaser for Next Post

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

Problem:

Display next/previous post information of same category.

Solution:

There isn't such kind of built-in feature within Toolset plugins, you can consider custom codes, for example:

https://wordpress.stackexchange.com/a/208050

Relevant Documentation:

This support ticket is created 2 years, 9 months 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.

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 5 replies, has 3 voices.

Last updated by davidL-7 2 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#2294773

Tell us what you are trying to do?

Hi, I'm developing a site using the Divi theme and Toolset. The designer wants a single post template for a particular category of post, that includes a "teaser" section for the next post in that category (with thumbnail, title, date and excerpt). Here's the designer's static layout:

hidden link
u: flywheel
p: dancing-flamingo

Divi makes it easy for me to create a single post template, but my problem is with getting the next post in the category to display below "Read the next post" near the bottom. I thought I might be able to pull it off with Toolset, but I can't figure out how.

Any thoughts on how I could do this?

Thanks,
David

#2295205

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi David

However you display the teaser content, you are going to need custom code to determine which post to display.

If you are viewing a single post (of some category), it seems like you would need to run a query to get all of the posts in that category in the desired order, then work out the position of the current post in that order to be able to deduce which should be the next post.

Once you have determined that, you can use that information to display its content.

One way you could do that is using a View, set to query the posts of the relevant type, and then use the wpv_filter_query hook to modify the query arguments. Specifically, you would run code with the logic described above to get the ID of the next post, and then you could set the post__in query argument with that ID.

See https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query for details of the relevant hook.

#2295829

Thanks Nigel,

I was thinking in that direction, but you gave me some good pointers. I'll review the documentations, see if I can figure it out, then follow up here.

More to come,
David

#2295871

Hi Nigel,

Okay, I've reviewed the documentation on wpv_filter_query, but I'm a little bit out of my depth, so let me back up and ask a few more specific questions. Let's start from this page on the site-under-development, which is using a series of Views (three different ones) to produce a blog landing page:

hidden link

By the way, the posts shown are vanilla WordPress posts belonging to one specific category, "Executive Director's Blog".

From there, the reader will click on any post title or "continue reading" link to get to a single post. Let's use the May 6, 2021 "Spiked Proteins" post as our test case. So we click on the link and go to:

hidden link

So this is the single post work-in-progress, and what you'll currently see down beneath the Read the Next Post subheading are my failed attempts to display the next post from the Executive Director's Blog category chronologically, which should be October 1, 2020 "Crane-iotomy", but is currently the most recent post in that category.

An important note: Currently the actual content for the Spiked Protein post shown on the single page is displayed via native Divi functions, not a Toolset view. But I am employing a view (slug: next-post-executive-directors-blog) to try to get the "Next Post".

A few questions:

1) I'd love to stick with this approach (Divi for the main entry, View for the Next Post), but would somehow need my next-post-executive-directors-blog view to know what the current post is, and then to find the next one in the sort order. But I don't know how (or even if it's possible) to create a view that filters the query to begin with the current post (which of course only makes sense in the context of a single-post page or template).

2) I did have the idea to display the entire contents of the page with a view, but I still have a similar question: i.e., how within the context of a view to query for the current post? If the wpv_filter_query hook is part of the process, I'm not clear where I would utilize it; is it used somewhere in the view configuration, or is it dropped in somewhere else and then referenced somehow?

Looking at your directions, you wrote:

One way you could do that is using a View [so far so good], set to query the posts of the relevant type [done], and then use the wpv_filter_query hook to modify the query arguments [that's what I'm not sure how to do]. Specifically, you would run code with the logic described above to get the ID of the next post, and then you could set the post__in query argument with that ID. [makes sense, but not sure how actually do all that!]

Hope that helps you get a sense of my expertise level... any guidance you can provide would be appreciated.

Thanks!
David

#2296331

Hello,

There isn't such kind of built-in feature within Toolset plugins, I have searched it in google, and found the solution of below similar thread:
https://wordpress.stackexchange.com/a/208050

For your reference:

#2300047

Thanks for the link Luo, I'll see if I can figure something out.

Best,
David