Skip Navigation

[Resolved] How to create a “view template” for showing posts under different conditions?

This support ticket is created 2 years, 6 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 8 replies, has 2 voices.

Last updated by Martin 2 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#2365433

Hi,

Hope the solution is already there and I just messed with terms etc…

I want to create a template view for a list of posts that so can use in several views as each view is needed in certain places on my site to select a certain set of posts.

In order to have the styling in one place for displaying each of the lists, I wonder if there is such thing as a template )or how to apply it).

Example: on one page I select posts of a certain tag, on another of a certain category. I also need a list of posts under a CPT for brands so that I can display a post list for a brand that are related to the brand. Or a last example: I have a CPT events and want to display a list ot posts that are related to an event…

So, how can au define the styling of a post list in one place while using it his “template” in each view that I create to achieve the tasks above?

Thanks! Martin

#2365719

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

If you want different styling which includes different HTML per tags or category you will have to create different templates for that but if your case is that you build one content template and you want to reuse the same again for the tags, categories then you can reuse it.

Here is the Doc which shows how you can build conditional template to display single posts:
- https://toolset.com/course-lesson/assigning-templates-to-posts-conditionally/

Please let me know your requirement with a test case example and I would be happy to help you and guide you in the right direction.

#2365745

Hi,

if I get it right – applying a template to a post conditionally is more to enable different templates to one post.

But what I am looking for is to us different views in different templates that produce always a list of post (but with different selection criteria). And I want to design this list of posts as part of a template/page just once and re-use the design in the different views.

Does this makes sende to you?

#2365755

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Yes - but it will be more broader concept until and unless you share your specific requirement.

You can design content template having a view inside it but if you want to filter it with different terms and reuse the view then you will have to use the classic view.

For example - you create a view list posts and filter with different category that means you are using the same view but filtering it with different category:

[wpv-view name="list-posts" category="albums"]
[wpv-view name="list-posts" category="live"]

- Is the example shared above is related to your requirement or you still want something else.

If you can share problem URL and admin access details and tell me your goal with details what exactly you want to achieve that will help me to guide you in the right direction.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2365783

Hi Minesh,

the hint to the shortcode options for a view is fine good as I will be able to use theses in some cases. But in others a parameter is "missing". For narrowing down e.g. to categories ist works already. But I use the block editor to create views as I need to select them by some criteria.

See here:
hidden link

at the end there is a list of posts ( not very stylish so far...). On other pages I use completed different criteras, but again it prodices a list of posts...

Any idea if this is possible so that I do not have to style the "View Loop" so that the list of posts looks the same as in another template`

#2365799

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

If you want to reuse the content you put within the view's loop, you will have to create a content template in classic mode namely for example "reusable-template-view-loop" and add whatever content you want to display to that content template and then add that content template within the different view's loop.

I hope this makes sense.

#2366773

Hi MInesh,

currently, I switched nearly all work to the block editor. Do I get it right that there is no way to achieve this with the block editor? Only with the classic editor?

Or can I create a view in the block editor and use its name in the classical editor just inside the template and name it there?

#2367591

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Its great that all seems to work. With block editor you might get a issue with styling and all when other blocks are involved. That is why I suggest you to use the classic editor but if it works all fine as expected even with blocks then there is no harm using it. Using classic editor it will offer you more flexibility to edit your HTML and content compare to block editor.

#2369121

Okay, seems that this case is not covered already by Toolset. Hope for it in the future.... Thanks!