- Posts: 438
COMMUNITY FORUM
All Tags If Condition
- Joe Campbell
-
Topic Author
- Offline
- Platinum Member
Less
More
8 years 8 months ago #157263
by Joe Campbell
All Tags If Condition was created by Joe Campbell
I know how to target a tag based on its position:
<?php if($this->item->tags[0]->name == 'K2 Tips'): ?>
Is it possible to target all the tags of an item?
<?php if($this->item->tags[0]->name == 'K2 Tips'): ?>
Is it possible to target all the tags of an item?
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
8 years 8 months ago - 8 years 8 months ago #157275
by Krikor Boghossian
Replied by Krikor Boghossian on topic All Tags If Condition
This code checks only the first tag of that item.
In order to check the entire array of tags (all of the item's tags), you need a foreach statement like the one which prints them.
In order to check the entire array of tags (all of the item's tags), you need a foreach statement like the one which prints them.
<?php foreach ($this->item->tags as $tag): ?>
<?php if($tag->name == 'K2 Tips'): ?>
// Do something
<?php endif; ?>
<?php endif; ?>
<?php endiforeach; ?>
Last edit: 8 years 8 months ago by Krikor Boghossian.
Please Log in or Create an account to join the conversation.
- Joe Campbell
-
Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 438
8 years 8 months ago #157279
by Joe Campbell
Replied by Joe Campbell on topic All Tags If Condition
Thanks @Krikor - it works, with one small change
<?php foreach ($this->item->tags as $tag): ?>
<?php if($tag->name == 'K2 Tips'): ?>
// Do something
<?php endif; ?>
<?php endforeach; ?>
<?php foreach ($this->item->tags as $tag): ?>
<?php if($tag->name == 'K2 Tips'): ?>
// Do something
<?php endif; ?>
<?php endforeach; ?>
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
8 years 8 months ago #157281
by Krikor Boghossian
Replied by Krikor Boghossian on topic All Tags If Condition
Oops, it seems I missed a spot.
Please Log in or Create an account to join the conversation.
- Joe Campbell
-
Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 438
8 years 8 months ago #157282
by Joe Campbell
Replied by Joe Campbell on topic All Tags If Condition
No worries - I always have your back buddy :)
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
8 years 8 months ago #157299
by Krikor Boghossian
Replied by Krikor Boghossian on topic All Tags If Condition
I know :)
I really appreciate it Joe.
I really appreciate it Joe.
Please Log in or Create an account to join the conversation.