<p>You need to find a way to get the right <a href="http://buildwithcraft.com/docs/templating/categorymodel" rel="nofollow">category model</a> to be able to receive all entries related to it.
As you didn't set up our categories to have their own URL, you could find it using the relevant slug in your URL.
Assuming that maches your categories slugs:</p>

<pre><code>{% set categorySlug = craft.request.getLastSegment() %}
{% set category = craft.categories.slug(categorySlug).first() %}

{% if category %}

    {% set entries = craft.entries.relatedTo(category).limit(12) %}
    {% for entry in entries %}
        {{ entry.title }}
    {% endfor %}

{% endif %}
</code></pre>

<p>Another, probably more elegant way would be to access a token set via a <a href="http://buildwithcraft.com/docs/routing#dynamic-routes" rel="nofollow">dynamic route</a>:</p>

<pre><code>'regions/[SLUG]' =&gt; 'regions/_index'
</code></pre>

<p>You would now be able to access that token from a variable "slug":</p>

<pre><code>{% set category = craft.categories.slug(slug).first() %}
</code></pre>

CC BY-SA 3.0
2015-05-07T23:21:27.820Z
I have to sit with this for a while and try and wrap my mind around it.  New concepts to dig into here!
Jam
CC BY-SA 3.0
2015-05-08T02:13:48.157Z
ok so the top solution worked (lovely!) but I want to make sure I understood how or why.  So you said assuming the slug ( in my url ) matches the category slugs, this is relevant to  l .getlastSegment( ),?  By having matched categories/ landing page slugs, craft grabs the slug from the landing page and  sets the category to match the same named slug?  Then it gets related entries, loops, outputs and that happy feeling came across me?  Do I understand?  As more elegant solution, truth be told I don't know what a token set is.  Read about routes and ran away waving my hands.  TY for solution.
Jam
CC BY-SA 3.0
2015-05-07T09:48:23.633Z
2015-05-07T09:57:48.207Z
2015-05-07T09:57:48.207Z
carlcs
<p>I have a site governed by a structure, including the homepage.  I have several "parental" landing pages with research areas (Atlantic, Pacific, Midwest etc ) intended to be the gateway to  the children entries in that area. (Boston, New York, DC etc).  </p>

<p>I have categories (without urls) corresponding to the landing pages (Atlantic, Pacific, Midwest etc ) and would like to pull teasers from each child entry onto the landing page, so that the Atlantic landing page has teasers from the Atlantic children's entries pulled in via the category field, the Pacific landing page has teasers from the Pacific children's entries via category etc...)</p>

<p>But I would like to do this in one template, rather than using multiple entry types.  </p>

<p>I know I can get entries by an array of sections</p>

<pre><code>{% for entry in craft.entries.section([atlantic, pacific, midwest]) %}
</code></pre>

<p>My mind cannot bend around how I could start at</p>

<pre><code>{% for entry in craft.entries.section('pages') %}
</code></pre>

<p>and trek on from there to grab both the appropriate landing page and the categories that go with it dynamically.  Can I keep using arrays in both the page id's and the categories?  How would can I make a template know to grab the Atlantic and fill it with teasers from the Atlantic category?  Is it even possible?  </p>

CC BY-SA 3.0
2015-05-07T09:39:59.247Z
How did you set up your landing pages? Singles? And you've set this up to load the same template, right?
carlcs
CC BY-SA 3.0
2015-05-07T23:28:28.393Z
no I have landing pages as part of the structure, too, with their own entry type.  And yes, same template . Thanks for the edit, BTW!
Jam
<entries><categories><structure><array>
Getting Entry By Category for Landing Pages In A Structure
# Getting Entry By Category for Landing Pages In A Structure

(Asked by: username_0 on 2015-05-07)

I have a site governed by a structure, including the homepage.  I have several "parental" landing pages with research areas (Atlantic, Pacific, Midwest etc ) intended to be the gateway to  the children entries in that area. (Boston, New York, DC etc).  
I have categories (without urls) corresponding to the landing pages (Atlantic, Pacific, Midwest etc ) and would like to pull teasers from each child entry onto the landing page, so that the Atlantic landing page has teasers from the Atlantic children's entries pulled in via the category field, the Pacific landing page has teasers from the Pacific children's entries via category etc...)
But I would like to do this in one template, rather than using multiple entry types.  
I know I can get entries by an array of sections
{% for entry in craft.entries.section([atlantic, pacific, midwest]) %}

My mind cannot bend around how I could start at
{% for entry in craft.entries.section('pages') %}

and trek on from there to grab both the appropriate landing page and the categories that go with it dynamically.  Can I keep using arrays in both the page id's and the categories?  How would can I make a template know to grab the Atlantic and fill it with teasers from the Atlantic category?  Is it even possible?

**Tags:** entries, categories, structure, array
> **Comments:**
> **username_1**: How did you set up your landing pages? Singles? And you've set this up to load the same template, right?  
> **username_0**: no I have landing pages as part of the structure, too, with their own entry type.  And yes, same template . Thanks for the edit, BTW!  

---

## 1 answers

### Answer by username_1 on 2015-05-07. Score: 1 | Accepted answer

You need to find a way to get the right category model to be able to receive all entries related to it.
As you didn't set up our categories to have their own URL, you could find it using the relevant slug in your URL.
Assuming that maches your categories slugs:
{% set categorySlug = craft.request.getLastSegment() %}
{% set category = craft.categories.slug(categorySlug).first() %}

{% if category %}

    {% set entries = craft.entries.relatedTo(category).limit(12) %}
    {% for entry in entries %}
        {{ entry.title }}
    {% endfor %}

{% endif %}

Another, probably more elegant way would be to access a token set via a dynamic route:
'regions/[SLUG]' => 'regions/_index'

You would now be able to access that token from a variable "slug":
{% set category = craft.categories.slug(slug).first() %}

> **Comments:**
> **username_0**: I have to sit with this for a while and try and wrap my mind around it.  New concepts to dig into here!  
> **username_0**: ok so the top solution worked (lovely!) but I want to make sure I understood how or why.  So you said assuming the slug ( in my url ) matches the category slugs, this is relevant to  l .getlastSegment( ),?  By having matched categories/ landing page slugs, craft grabs the slug from the landing page and  sets the category to match the same named slug?  Then it gets related entries, loops, outputs and that happy feeling came across me?  Do I understand?  As more elegant solution, truth be told I don't know what a token set is.  Read about routes and ran away waving my hands.  TY for solution.  

---

