1

I have an issue with detecting the channel of an entry so I can apply schema for different types of entries based on the channel:

<head>
{exp:channel:entries limit="1"}
  {if channel == "blog_post"}
  my schema here... 
  {if:elseif channel == "recipe"}
  my schema here... 
  {/if}
{/exp:channel:entries}
</head>

When I put out the channel in the comments I'll see another channel and not the blog post or recipe channel that it's been posted on in the admin. I used {segment_1} with success since the URL structure is /recipe/{url_title} and /blog/{url_title} but I'm SOL if I create a custom URL. Why wouldn't {channel} be accurate and is there a better way to do this?

2
  • theoretically, this should work. What version of EE are you using? Mar 17 at 19:15
  • 6, I added my answer when I figured it out. I'm working on a client site so I assume there's some screwy configs or maybe it's just EE weirdness. ¯_(ツ)_/¯
    – Edward
    Mar 17 at 19:22

1 Answer 1

2

Figured it out. I needed to specify the channels at the top of the loop.

<head>
{exp:channel:entries limit="1" channel="recipe|blog_post" }
  {if channel_short_name == "blog_post"}
  my schema here... 
  {if:elseif channel_short_name == "recipe"}
  my schema here... 
  {/if}
{/exp:channel:entries}
</head>

I would expect exp:channel:entries to get the accurate info and I would not need to specify a scope of channels to search so I can use the specific fields for each channel. I'll have to remember to add the channel to the parameter list if I want to add more schema per channel content.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.