Feature Request: Additional Element Conditions

I’m trying to build an Archive Layout that will serve as the layout for most of the collection views on a particular site. Specifically, this Layout will be used for the Blog page, Category Archive, Tag Archive, and Search Result pages.

Basically, I have a grid built to display the individual posts (so they’re consistent across all those pages, and I don’t have to manage 4 different Layouts). And above that, I have a few sections that I want to conditionally show or hide depending on which particular page is being viewed. For example, a section that displays only when viewing a Category Archive, another that only displays when viewing a Tag Archive, another when viewing the Blog page, and another that only displays on the Search Results page.

I can get Search Results working fine, however there don’t seem to be Element Conditions that allow me to target Blog is being viewed or Taxonomy is Category, etc… I see options that will let me do this up in the overall Layout Conditions - but not down at the Element level.

Is this a technical constraint, or just something you haven’t implemented? If the latter, can you add some monumental additional conditionals please :pray:

  • Archive: Select a taxonomy type
  • Blog: being viewed
  • (I’m sure there are others related to Archives that’d be helpful too, but I can’t think of any other examples at the moment)
4 Likes

Hi @devinelston,

You’re right, looks like those are missing. I’ll make a note to revisit that. Meanwhile, one thing you could do is add some custom Dynamic Content directives that you can use in String Expression Conditions. For example:

add_filter('cs_dynamic_content_condition', function( $result, $field, $args ){

  if ($field === 'is-blog') {
    return is_blog() ? 'true' : 'false';
  }
  return $result;
},10, 3);

Then the condition would go something like:

{{dc:condition:is-blog}} | is | true

The other conditions would need respective entries as well, but it’s the same concept.

3 Likes

Awesome, thanks @alexander!

So as my issue seems to be similar.

Edited as I got it working, needed to use is_product_tag(). This is really awesome and super helpful. These are the types of things we need in the documentation :slight_smile:

add_filter('cs_dynamic_content_condition', function( $result, $field, $args ){

  if ($field === 'is-product-tag') {
    return is_product_tag() ? 'true' : 'false';
  }
  
  return $result;
  
},10, 3);

Glad you got it working!

I just came to request the same thing. Thanks for providing an interim solution!

You’re welcome!

@alexander, I know there’s no chance for this release, but just noting that I’d still love to see some additional conditionals find their way in there :pray:

Hi @devinelston,

I’m pretty sure we fixed the main one here, but there are still a few more we need to get added. Kory has a list going somewhere in our issue tracker so I’ll make sure these are on there as well.

Interesting, I don’t see the option of Blog is being viewed within the element conditions. Is it called something else?

@devinelston, my apologies - I must have been thinking of a different condition we fixed recently. There is a “Blog” assignment type but it only shows under the “Archive” when assigning a layout/header/footer. I’ve made some adjustments:

  • Renamed Blog to Front Page since that accurately reflects the WordPress function used for detection
  • Added a Blog assignment option under Archive
  • Added a Blog element condition that is true if you’re on anything related to a blog (post single, archive, author, etc)

Was able to get those in quickly but we’ll have to hold off on the others.

1 Like

Awesome, thanks @alexander!

You’re welcome!

@kory I know this is old, and outside the scope of this release, but just flagging that it would still be really useful to have some extra conditionals – particularly around viewing different taxonomy archives. (I’ve looked, and didn’t notice them in the latest beta… unless I completely missed them)

@devinelston, the blog “being viewed” should be in there for this release, is the main big win here being able to select an archive type and then choose which taxonomy it is related to? I’m not sure we can get to it, but I just want to confirm exactly what would be most helpful to you.

Hey @kory,

I want to set up a single Archive Layout so I can have a consistent UI across all the different archive pages a user might view. However, I want to handle things slightly differently depending on whether the user is looking at a Tag archive, a Category Archive, Search Screen, or just as the General Blog (or Date Archive, etc. etc. etc.).

Up at the Layout level, I can assign conditions like Post Taxonomy is Tag to target an entire layout to specific types of archives. However, on elements within the layout, I don’t have a similar type of logic to tap into.

So, for example, say I wanted to use a slightly different page heading section for a Tag archive than a Category archive, I can’t do that except by duplicating the entire layout, setting up the different headings, and targeting each Layout to different conditions.

So, the big win for me would be Element-level conditions that are similar to the Layout-level conditions for things like tags, categories, dates.

For example, being able to put a condition on an element for something like Archive is Tag. Or Archive is Category. (I don’t think I’m using the proper naming conventions there, so you’ll have a better idea how something like that should be worded)

That make sense? Or am I missing something that’s already there?

Hey, @devinelston! Thank you for that, that detail does help. I have noted this down and while I would love to say we’ll have some time to get this in, I’m just not sure at the moment as the primary task at hand is cleaning up bugs from this major refactor and addressing any issues closely related to that. We’re working to get this release out and into the wild as quickly as possible after such a long cycle as our main focus. That being said, I have certainly noted these things down and when we have time to review Element conditions more holistically, I would love to take some time to include this along with thinking through other ways that system can be improved overall.

Thanks!

Of course! And thanks!

You got it!

@Charlie with the work you’ve been doing around conditions… is this something that’s straightforward to add in? (Short version, having element conditions that are in line with what’s possible for layout conditions - specifically things like Post Taxonomy is Tag, etc.)