0

I am trying to reference an image field from blog posts (blog channel) to display on a staff profile page (pages channel).

On the blog post there is a matrix field "blog_smile":

  • Column 1: blog_smile_ortho (playa field - used to assign the staff member)
  • Column 2: blog_smile_image (assets field - to assign image)

How could I be on the profile page and say:

  1. Go look at the blog channel,
  2. Look in the matrix field "blog smile" and find "blog_smile_ortho" entries that are the same entry id as the profile page you're on
  3. Then get the "blog_smile_image" file from that same matrix field
  4. And repeat this process up to 6 times working back from todays date.

Thanks for any advice you can give.

1 Answer 1

1

This is possible, but limiting the output to just the last 6 photos is going to require some PHP in your template. So first go into your template’s preferences and enable PHP on Output.

Here’s the template code:

{exp:channel:entries channel="pages" ... }

    {!-- start the counter --}
    <?php $count = 0; ?>

    {!-- find the blog entries relating to this profile page --}
    {exp:playa:parents channel="blog"
                       field="blog_smile"
                       col="blog_smile_ortho"
                       orderby="date" sort="desc"
                       var_prefix="blogpost"}

        {!-- find the Matrix rows relating to this profile page --}
        {blogpost:blog_smile search:blog_smile_ortho="[{entry_id}]"}

            {!-- loop through the Assets images --}
            {blogpost:blog_smile_image}

                {!-- increase the counter --}
                <?php $count++ ?>

                {!-- only show this image if it’s within the first 6 --}
                <?php if ($count <= 6): ?>
                    <img src="{blogpost:url}" width="{blogpost:width}" height="{blogpost:height}">
                <?php endif ?>

            {/blogpost:blog_smile_image}

        {/blogpost:blog_smile}

    {/exp:playa:parents}

{/exp:channel:entries}

Hope that helps!

2
  • Thanks Brandon. could I use the {exp:playa:parents ...}{/exp:playa:parents} further up the page too to assign a class of hide to the div if there are no results? What conditional would be best? Thanks for all your help. Apr 3, 2013 at 15:06
  • Just wrap the whole thing with {if '{exp:playa:total_parents channel="blog" ...}'} ... {/if}. Use all the same parameters as your {exp:playa:parents} tag. Apr 3, 2013 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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