You are doing it wrong on many levels here:
-
You should not be using a custom query in place of the main query. Rather use
pre_get_posts
to alter the main query accordingly. Go back to the main loop and add the following in your functions file or in a custom pluginadd_action( 'pre_get_posts', function ( $q ) { if ( $q->is_home() && $q->is_main_query() ) { $q->set( 'post_type', ['photo', 'video', 'web'] ); $q->set( 'posts_per_page', -1 ); } });
-
is_singular()
is the wrong check here.is_singular()
checks if you are on a singular post page, so it will always return false on any page that is not a singular post page.What you need is
get_post_type()
to get the post type the post belongs to and test against thatif ( 'photo' === get_post_type() ) : echo "<a href="https://wordpress.stackexchange.com/photo">photo</a>"; elseif ( 'video' === get_post_type() ) : echo "<a href="http://wordpress.stackexchange.com/video">video</a>"; elseif ( 'web' === get_post_type() ) : echo "<a href="http://wordpress.stackexchange.com/web">web</a>"; endif;
-
Lastly, if you want to link to the archive pages of those post types, you should be using
get_post_type_archive()
. Something like the following would work<a href="https://wordpress.stackexchange.com/questions/220376/<?php echo get_post_type_archive_link("Photo' ); ?>">Photo</a>
instead of
echo "<a href="https://wordpress.stackexchange.com/photo">photo</a>"
EDIT
From comments, I have done an extensive answer on why not to use custom queries in place of the main query. Feel free to check it out here. It should answer quite a few questions for you