Skip Navigation

[Resolved] Conditionally display image in archive page

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

Problem:

The issue here is that the user wanted to conditionally display some images based on the taxonomy attached to a post on an Archive layout.

Solution:

It won't be exactly possible to do with the taxonomy archive, with the general archive like that. Instead it is possible on the individual term archive.

The reason is because you are going to need to know individually which term is attached to the current post being listed. So in the archive it won't be possible.

It is possible to do with a multiple view setup. Where at first you will need a view to first list the taxonomy terms in that taxonomy. Then a second view to list all the posts that belongs to each of those taxonomies.

Take a look at this documentation below.
https://toolset.com/documentation/user-guides/using-a-child-view-in-a-taxonomy-view-layout/#taxonomy-view-with-a-post-view-for-a-child

From the example you see there are 4 categories Technology,Sport,Environment,Auto and that each is listing their relevant posts below them.

This support ticket is created 6 years, 10 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.

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

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

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 3 replies, has 2 voices.

Last updated by hugoC-3 6 years, 10 months ago.

Assisted by: Shane.

Author
Posts
#607069
Schermafdruk 2018-01-17 11.44.30.png

Tell us what you are trying to do?
Display a different thumbnail image for each post category:
all posts in category A should have thumbnail imageA.jpg,
all posts in category B should have thumbnail imageB.jpg
etc. as shown in the screenshot.
using this code in the content template for my archive:

[wpv-conditional if="( '[wpv-archive-title]' eq 'categoryA' )"]
<img src="hidden link" class="mediumsize"/>
[/wpv-conditional]
[wpv-conditional if="( '[wpv-archive-title]' eq 'categoryB' )"]
<img src="hidden link" class="mediumsize"/>
[/wpv-conditional]
<h3 class="entry-header">[wpv-post-title]</h3>
<div class="entry-content">
[wpv-post-excerpt]
</div>

But I can't get this to work. Am I using the wrong conditional? How can I get this to work?
I also tried [wpv-conditional if="( '[wpv-taxonomy-slug]' eq 'verkennen' )"], but this didn't work either.

#607188

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Hugo,

Thank you for contacting our support forum.

Would you mind providing me with admin access to the website so that I can have a look ?

The private fields will be enabled for your next response.

Thanks,
Shane

#608029

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Hugo,

Thank you for contacting our support forum.

I took a look at this and gave some deep thought into it.

It won't be exactly possible to do with the taxonomy archive, with the general archive like that. Instead it is possible on the individual term archive.

The reason is because you are going to need to know individually which term is attached to the current post being listed. So in the archive it won't be possible.

It is possible to do with a multiple view setup. Where at first you will need a view to first list the taxonomy terms in that taxonomy. Then a second view to list all the posts that belongs to each of those taxonomies.

Take a look at this documentation below.
https://toolset.com/documentation/user-guides/using-a-child-view-in-a-taxonomy-view-layout/#taxonomy-view-with-a-post-view-for-a-child

From the example you see there are 4 categories Technology,Sport,Environment,Auto and that each is listing their relevant posts below them.

Please let me know if this helps.
Thanks,
Shane

#611996

Thanks for the explanation. I have set up a test site on discover-wp to find out how nested views work, so I can move on now!