1

I'm looping through my entries, and I want to check if my entry has a certain entry as his playa parent.

Right now I'm using this code, which works, but I'm wondering if it can be done without PHP.

{exp:channel:entries channel="project"}
    <?php $hasParent = false; ?>

    {project_categorie}
      {if segment_2 == url_title}
        <?php $hasParent = true; ?>
      {/if}
    {/project_categorie}

    <?php if($hasParent){ echo "wooptidoo"; }?>
{/exp:channel:entries}

so, this runs through my playa related entries, checks to see if the url_title matches my quert ( segment_2 in this case ) and displays this once.

Another example of this functionality would be: checking to see if you entry is in a certain category. f.ex:

{exp:channel:entries channel="project"}
    <?php $isInCategory = false; ?>

    {categories}
      {if segment_2 == category_url_title}
        <?php $isInCategory = true; ?>
      {/if}
    {/categories}

    <?php if($isInCategory){ echo "wooptidoo"; }?>
{/exp:channel:entries}

can this be done without having to use PHP ?



EDIT:
--------------------

Ok, I have not idea why I didn't think of this before, but this works perfectly..

{exp:channel:entries channel="project"}
    {project_categorie}
      {if segment_2 == url_title}
        wooptidoo
      {/if}
    {/project_categorie}
{/exp:channel:entries}

stuuupid. :)

1

You can check if an entry has a parent with the {exp:playa:parents} tag, it accepts all the channel entries parameters also. Something like this could work:

{exp:channel:entries channel="project"}
    {exp:playa:parents channel="channel" entry_id="{entry_id}"}
        wooptidoo
        {if no_parents} ... {/if}
    {/exp:playa:parents}
{/exp:channel:entries}

You could also use a addon like Low's Seg2Cat to filter the entries even more:

{exp:playa:parents channel="channel" category="{segment_2_category_id}" "entry_id="{entry_id}"}
2
  • This might be a better answer. I wasn't sure what @janvl meant by using Playa when I saw the code examples relating to categories, so I got kinda thrown off. My code pertains to categories more than it does playa. – Justin Kimbrell Dec 13 '12 at 14:07
  • this won't work, because that will output the "wooptidoo" for every playa parent. I just want to check if the entry has one specific playa parent. – janvl Dec 13 '12 at 14:18
0

Take a look at my new free add-on. It's not 100% ready for prime time, but that method should work. I do stuff like that all the time. Let me know if there are methods missing that you need.

http://objectivehtml.com/entries

Edit... Not 100% sure those methods exist currently, but here would be a good proposed API.

{exp:entries:has_parent_category entry_id="{entry_id}"}

    {if no_results}
        This does not belong to parent category
    {/if}

{/exp:entries:has_parent_category}

{exp:entries:in_category entry_id="{entry_id}"}
    {if no_results}
        This does not belong to category
    {/if}
{/exp:entries:in_category}

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.