<p>This is commonly called 'reverse-related entries' and is achievable using <strong>relatedTo()</strong>. <a href="https://straightupcraft.com/articles/introduction-to-relations-and-reverse-relations-in-craft-cms-with-examples#displaying-reverse-relations" rel="nofollow noreferrer">See here for some info</a>... </p>

<blockquote>
  <p>My question is if I chose to show the entry selected on a new page how would I show the relationship to the page it appears on / came from? Perhaps as a title from the previous page or a back button.</p>
</blockquote>

<p>For example, if a visitor were on an <strong>Audio Entry page</strong>, your template code would look something like:</p>

<pre><code>{% set relatedResearchProject = craft.entries.section('researchProjects').relatedTo(entry) %}
{% for researchProject in relatedResearchProject %}
    &lt;li&gt;&lt;a href="{{ researchProject.url }}"&gt;{{ researchProject.title }}&lt;/a&gt;&lt;/li&gt;
{% endfor %}
</code></pre>

<p>The above, would display any Research Projects which contain related "audio" Entries.</p>

<hr>

<p>The logic is as follows:</p>

<pre><code>{% set relatedResearchProject = craft.entries.section('researchProjects').relatedTo(entry) %}
</code></pre>

<ol>
<li>Create a new variable called "relatedResearchProject" (in fact the variable name can be any word which makes sense to you)</li>
<li>The new variable should contain any entries from the <strong>Research Projects Section</strong> which are related to the the (Audio) entry being displayed on the current page.</li>
</ol>

<p>Then...</p>

<pre><code>{% for researchProject in relatedResearchProject %}&lt;li&gt;&lt;a href="{{ researchProject.url }}"&gt;{{ researchProject.title }}&lt;/a&lt;/li&gt;{% endfor %}
</code></pre>

<p>Loop through and display any entries which are in the 'relatedResearchProject' variable.</p>

<hr>

<p>In a different example below, you can see that "Third news entry..." contains the Entry field. then, on /news/we-just-installed-craft you can see the rendered link back to the "Third news entry..." page.</p>

<p>Sorry, Scott - I hope illustrating two examples isn't confusing! Let us know how you get on.</p>

<p><a href="https://i.sstatic.net/Oz8BH.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Oz8BH.png" alt="enter image description here"></a>
<a href="https://i.sstatic.net/1dPEv.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/1dPEv.png" alt="enter image description here"></a></p>

<pre><code>{% for researchProject in relatedResearchProject %}&lt;li&gt;&lt;a href="{{ researchProject.url }}"&gt;{{ researchProject.title }}&lt;/a&lt;/li&gt;{% endfor %}
</code></pre>

CC BY-SA 3.0
2016-05-26T17:16:10.227Z
Hi Matt, just responded below as I maxed out the character count.
Scott Robinson
CC BY-SA 3.0
2016-05-26T17:26:15.863Z
Looking back out your response it seems the two solutions work as a way of navigating back to the related project as long as the item isn't related to multiple projects. This may actually be okay for my current situation. Am I to assume that there is no way in craft to refer to the page I have just come from? I guess that could be achieved by JS maybe.
Scott Robinson
CC BY-SA 3.0
2016-05-27T16:33:55.450Z
Hey Scott. I agree, I would handle a 'back' link with JS. I've also updated my answer to explain the template code. If multiple Research Projects contain relationships to Audio entries, then the above template code would display all of the Research Projects. Hope that helps
Matt P
CC BY-SA 3.0
2016-06-04T15:25:42.037Z
Hey Matt, thanks for your help. I've got my head around relatedTo and am actually using the many to many plugin with success.
Scott Robinson
CC BY-SA 3.0
2016-06-05T06:02:35.010Z
Well done Scott! Glad we could help :)
Matt P
CC BY-SA 3.0
2016-05-26T14:46:15.807Z
2016-05-27T15:09:23.867Z
2016-05-27T15:09:23.867Z
Matt P
<p>Thanks for the response. I had a feeling that RelatedTo might help but I'll admit I was having difficulty understanding the logic.</p>

<p>Just so I understand the first example:</p>

<p>{% set relatedResearchProject = craft.entries.section('researchProjects').relatedTo(entry) %}</p>

<p>The above sits on the audio file template page and basically defines relatedResearchProject as the entry in the section 'researchProjects' that the details propagating the template relate to. This is essentially creating a relationship from the page I have just come from?</p>

<p>{% for researchProject in relatedResearchProject %}
    <li>{{ researchProject.title }}</li>
{% endfor %}</p>

<p>The above just lists out the title and url from the related project page.</p>

<p>I just wanted to check that you are providing 2 solutions to the problem. </p>

<p>Your second example would allow me to show the relationship to a project or multiple projects. Which I did consider. But it wouldn't help in navigating back to the previous page or show my audio page as a sub-page of the project I'd come from. Is that about right? </p>

CC BY-SA 3.0
2016-05-26T17:17:05.843Z
Hey Scott - No. The template code I mentioned all applies to 1 example. I'll amend my answer to make it more clear...
Matt P
CC BY-SA 3.0
2016-05-26T16:40:32.240Z
2016-05-26T16:40:32.240Z
Scott Robinson
<p>Not sure that is the best title but:</p>

<p>I have a Section called Research Projects. An entry from this section contains a number of images, videos and audio entries in a grid chosen through an Entry Field. At the moment when one of the grid items is selected it displays a modal showing the details of that entry. There is no issue is showing a relationship as the info is displayed on the same page.</p>

<p>My question is if I chose to show the entry selected on a new page how would I show the relationship to the page it appears on / came from? Perhaps as a title from the previous page or a back button.</p>

<p>I am not using a structure as video, image items can appear in multiple projects.</p>

<p>Hope that makes sense and thank for any help anyone can offer.</p>

<p>Scott</p>

<entries-field><parents>
Maintaining a relationship of parent from children selected through entry field
# Maintaining a relationship of parent from children selected through entry field

(Asked by: username_0 on 2016-05-26)

Not sure that is the best title but:

I have a Section called Research Projects. An entry from this section contains a number of images, videos and audio entries in a grid chosen through an Entry Field. At the moment when one of the grid items is selected it displays a modal showing the details of that entry. There is no issue is showing a relationship as the info is displayed on the same page.

My question is if I chose to show the entry selected on a new page how would I show the relationship to the page it appears on / came from? Perhaps as a title from the previous page or a back button.

I am not using a structure as video, image items can appear in multiple projects.

Hope that makes sense and thank for any help anyone can offer.

Scott

**Tags:** entries-field, parents


---

## 2 answers

### Answer by username_1 on 2016-05-26. Score: 1

This is commonly called 'reverse-related entries' and is achievable using relatedTo(). See here for some info... 

My question is if I chose to show the entry selected on a new page how would I show the relationship to the page it appears on / came from? Perhaps as a title from the previous page or a back button.

For example, if a visitor were on an Audio Entry page, your template code would look something like:
{% set relatedResearchProject = craft.entries.section('researchProjects').relatedTo(entry) %}
{% for researchProject in relatedResearchProject %}
    {{ researchProject.title }}
{% endfor %}

The above, would display any Research Projects which contain related "audio" Entries.

The logic is as follows:
{% set relatedResearchProject = craft.entries.section('researchProjects').relatedTo(entry) %}


Create a new variable called "relatedResearchProject" (in fact the variable name can be any word which makes sense to you)
The new variable should contain any entries from the Research Projects Section which are related to the the (Audio) entry being displayed on the current page.

Then...
{% for researchProject in relatedResearchProject %}{{ researchProject.title }}{% endfor %}

Loop through and display any entries which are in the 'relatedResearchProject' variable.

In a different example below, you can see that "Third news entry..." contains the Entry field. then, on /news/we-just-installed-craft you can see the rendered link back to the "Third news entry..." page.
Sorry, Scott - I hope illustrating two examples isn't confusing! Let us know how you get on.


{% for researchProject in relatedResearchProject %}{{ researchProject.title }}{% endfor %}

> **Comments:**
> **username_0**: Hi Matt, just responded below as I maxed out the character count.  
> **username_0**: Looking back out your response it seems the two solutions work as a way of navigating back to the related project as long as the item isn't related to multiple projects. This may actually be okay for my current situation. Am I to assume that there is no way in craft to refer to the page I have just come from? I guess that could be achieved by JS maybe.  
> **username_1**: Hey Scott. I agree, I would handle a 'back' link with JS. I've also updated my answer to explain the template code. If multiple Research Projects contain relationships to Audio entries, then the above template code would display all of the Research Projects. Hope that helps  
> **username_0**: Hey Matt, thanks for your help. I've got my head around relatedTo and am actually using the many to many plugin with success.  
> **username_1**: Well done Scott! Glad we could help :)  

---

### Answer by username_0 on 2016-05-26. Score: 0

Thanks for the response. I had a feeling that RelatedTo might help but I'll admit I was having difficulty understanding the logic.

Just so I understand the first example:

{% set relatedResearchProject = craft.entries.section('researchProjects').relatedTo(entry) %}

The above sits on the audio file template page and basically defines relatedResearchProject as the entry in the section 'researchProjects' that the details propagating the template relate to. This is essentially creating a relationship from the page I have just come from?

{% for researchProject in relatedResearchProject %}- {{ researchProject.title }}
{% endfor %}

The above just lists out the title and url from the related project page.

I just wanted to check that you are providing 2 solutions to the problem.

Your second example would allow me to show the relationship to a project or multiple projects. Which I did consider. But it wouldn't help in navigating back to the previous page or show my audio page as a sub-page of the project I'd come from. Is that about right?

> **Comments:**
> **username_1**: Hey Scott - No. The template code I mentioned all applies to 1 example. I'll amend my answer to make it more clear...  

---

