Condition for checking archive type

Hi everyone! Does anyone know if the there is a condition for checking the archive type? I’m trying to keep my templates to a minimum and hoping I could use one archive template, and conditionally show hide some elements depending on what archive is viewed.

Hey @muotoco,

there are WordPress functions to check for different archives (see documentation).

is_archive()
is_category()
is_tag()
is_author()
is_date()
is_post_type_archive()
is_tax()

You could use those functions in combination with the dynamic echo tag.

{echo:is_archive}

Best,

André

1 Like

Thanks André! This was helpful :smiley:
Best, Jesse

Hi returning to this after some time. Tried a bunch of combinations with the functions @aslotta pointed out, but still no luck.

In some context

I’m trying to conditionally show/hide elements in a archive template based on its type. The template has two different query loops:

Where the first is for post_type_1
and the second for post_type_2

I’ve tried something like this

{echo:is_post_type_archive}
==
post_type_1

Wich should only show first loop when on archive for post_type_1

{echo:is_post_type_archive}
!=
post_type_1

Wich should only show second loop on all other archives

Any tips would be greatly appreciated
Cheers

Hey @muotoco,

probably you did not allow the is_post_type_archive function to be used with the dynamic echo tag? See NO BUG: {echo} dynamic tag not working - #2 by aslotta.

Best,

André

just because of this reason I stopped using echo functions and started just coding my own custom elements or data tags.

Ah I missed this, thanks for pointing this out. I added the echo tags to my functions php, but still no luck :sweat: Do the condition and tags I posted look right to you?

I’ve tried the following formatting and any combination i can think of on a simple text block

{echo:is_post_type_archive}
==
custom_post_type
{echo:is_post_type_archive(custom_post_type)}
==
true
{echo:is_post_type_archive(custom_post_type)}
==
1

Cheers!

Hey @muotoco,

the last one looks correct to me:

{echo:is_post_type_archive(my_custom_post_type)}
==
1

CleanShot 2024-08-15 at 14.30.20

Best,

André