Skip Navigation

[Résolu] Conditionally display image in archive page

Ce fil est résolu. Voici une description du problème et la solution proposée.

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 Il y a 6 années et 3 mois. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. 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 réponses, has 2 voix.

Last updated by hugoC-3 Il y a 6 années et 2 mois.

Assisted by: Shane.

Auteur
Publications
#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: Anglais (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: Anglais (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!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.