- Posts: 438
COMMUNITY FORUM
Add PHP Condition Recursively
- Joe Campbell
- Topic Author
- Offline
- Platinum Member
Less
More
8 years 1 month ago #156895
by Joe Campbell
Add PHP Condition Recursively was created by Joe Campbell
How can I add a condition recursively to a category and its sub-categories.
So instead of doing:
if($this->item->category->name == 'AAA' OR $this->item->category->name == 'BBB' OR $this->item->category->name == 'CCC')
How do I do something like this
if recursive(category->name ==('AAA'))
Is this possible?
So instead of doing:
if($this->item->category->name == 'AAA' OR $this->item->category->name == 'BBB' OR $this->item->category->name == 'CCC')
How do I do something like this
if recursive(category->name ==('AAA'))
Is this possible?
Please Log in or Create an account to join the conversation.
- Mohamed Abdelaziz
- Offline
- Platinum Member
- Joomla Developer
8 years 1 month ago #156899
by Mohamed Abdelaziz
Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store
Replied by Mohamed Abdelaziz on topic Add PHP Condition Recursively
I don't think there is a straight forward method to do it.
At least it needs a loop to traverse the category and its sub-categories.
At least it needs a loop to traverse the category and its sub-categories.
Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store
Please Log in or Create an account to join the conversation.
- Joe Campbell
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 438
8 years 1 month ago #156901
by Joe Campbell
Replied by Joe Campbell on topic Add PHP Condition Recursively
Ok - thanks @MohamedAbdelaziz
Please Log in or Create an account to join the conversation.
- Joe Campbell
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 438
7 years 10 months ago #159222
by Joe Campbell
Replied by Joe Campbell on topic Add PHP Condition Recursively
I would greatly appreciate if someone would provide a PHP Snippet :)
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
Less
More
- Posts: 15920
7 years 10 months ago #159229
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic Add PHP Condition Recursively
The most straightforward way to do this would be to map the categories ID into a simple array - php.net/manual/en/language.types.array.php
Then use the in_array() - php.net/manual/en/function.in-array.php - check for the category's id. $this->item->category->id.
This is more bulletproof than the name method. Furthermore you won't have to query the database in order to retrieve the IDs manually (-1 query).
Then use the in_array() - php.net/manual/en/function.in-array.php - check for the category's id. $this->item->category->id.
This is more bulletproof than the name method. Furthermore you won't have to query the database in order to retrieve the IDs manually (-1 query).
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Joe Campbell
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 438
7 years 10 months ago #159232
by Joe Campbell
Replied by Joe Campbell on topic Add PHP Condition Recursively
Thanks @Krikor
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
Less
More
- Posts: 15920
7 years 10 months ago #159240
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic Add PHP Condition Recursively
You 're welcome buddy :)
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.