• Resolved shagen

    (@shagen)


    Have searched the forums but cannot quite find what I am looking for. I am trying to display various page layouts for my single.php file based on if a post is tagged with a certain tag or not. Have tried using is_tag() and an if statement at the top of my single.php template and it does not seem to honor it. So therefore I know I am off teh mark. Here is what I had tried…

    <?php if (is_tag('resource')) { ?>
    		Display resource loop here and layout here.
    		<?php }
    		else { ?>
    		Display all others here.
    		<?php
    	}; ?>

    The page before this contains a loop of various posts. Do I need to do something to special to the link on that page before clicking into a single post? Feels like it has no clue what the post is tagged with.

    Also sometimes the post could be tagged with this as well as others items. I am only interested when the resource tag shows up no matter how many other tags it has.

    I considered using tag-slug.php and creating a template but that did not seem like it was for the single post layout but is more designed for a loop of multiple post that have a certain tag.

    Any direction and help is much appreciated. Thanks for the time!

Viewing 3 replies - 1 through 3 (of 3 total)
  • https://codex.www.ads-software.com/Conditional_Tags#A_Tag_Page

    is_tag() targets the tag archive;

    for use in single posts, i would try
    has_tag()

    Thread Starter shagen

    (@shagen)

    Thank you thank you! Stared at that page for a while and was so stuck on is_tag() that I did not read the others close enough. Still getting the hang of all the syntax so your reply and time is greatly appreciated. has_tag() is working great. Here is what it looks like in case others need the exact code…

    <?php if (has_tag('resource')) { ?>
    		Display resource loop here and layout here.
    		<?php }
    		else { ?>
    		Display all others here.
    		<?php
    	}; ?>

    Thank you, thank you, thank you! This is exactly what I needed. I know it was over 9 months ago, but wanted to post my gratitude!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Want to display different single page layouts based on post tag?’ is closed to new replies.