<p>I'm rolling the same thing with </p>

<pre><code>{% extends 'layouts/_entry_layout' %}
{# sets the name for the css file to be pulled #}
{% set pageType = 'search' %}
{% set catSlug = craft.request.getSegment(2) %}
{% set title = craft.categories.slug(catSlug).first() ~ ' Channel' %}

{% block content %}

&lt;section class="search-results"&gt;

{% paginate craft.entries.relatedTo(category) as entriesOnPage %}


&lt;h1 class="category__title"&gt;{{ category.title }}&lt;/h1&gt;

    {% for entry in entriesOnPage %}
        {% include 'modules/_article_listing' %}
    {% endfor %}

{% include 'inc/_pagination' %}

{% endpaginate %}

&lt;/section&gt;

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

<p>my article listing module contains the usual things like {{ entry.title }} etc</p>

<p>and pagination include is like so:</p>

<pre><code>{% if paginate %}

{% set currentPage = paginate.currentPage %}
{% set startPage = currentPage - 2 %}
{% set endPage = currentPage + 2 %}
{% if query is defined %}
{% set queryString = "?q=" ~ query %}
{% endif %}


{% if paginate.totalPages &gt; 1 %}
&lt;nav class="pagination" role="navigation"&gt;

    &lt;ol class="pagination__list"&gt;

        {% if paginate.prevUrl %}
        &lt;li class="pagination__item"&gt;
            &lt;a class="btn  btn-2  btn-2a" href="{{ paginate.prevUrl }}{% if queryString is defined %}{{ queryString }}{% endif %}"&gt;
                &amp;larr;
                &lt;span class="visuallyhidden"&gt;Previous Page&lt;/span&gt;
            &lt;/a&gt;
        &lt;/li&gt;
        {% endif %}
        {% for i in startPage..endPage %}
        {% if paginate.getPageUrl( i ) %}
        {% if i != currentPage %}

        &lt;li class="pagination__item"&gt;
            &lt;a class="btn  btn-2  btn-2a" href="{{ paginate.getPageUrl( i ) }}{% if queryString is defined %}{{ queryString }}{% endif %}"&gt;
                &lt;span class="visuallyhidden"&gt;Page &lt;/span&gt;{{ i }}
            &lt;/a&gt;
        &lt;/li&gt;

        {% else %}

        &lt;li class="pagination__item btn  -current"&gt;
            &lt;span class="visuallyhidden"&gt;Current Page &lt;/span&gt;{{ i }}
        &lt;/li&gt;

        {% endif %}
    &lt;/li&gt;
    {% endif %}
    {% endfor %}

    {% if paginate.nextUrl %}
    &lt;li class="pagination__item"&gt;
        &lt;a class="btn  btn-2  btn-2a" href="{{ paginate.nextUrl }}{% if queryString is defined %}{{ queryString }}{% endif %}"&gt;
            &lt;span class="visuallyhidden"&gt;Next Page&lt;/span&gt;
            &amp;rarr;
        &lt;/a&gt;
    &lt;/li&gt;
    {% endif %}

&lt;/ol&gt;



&lt;/nav&gt;
{% endif %}

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

CC BY-SA 3.0
2015-05-27T20:07:12.257Z
2015-05-27T20:07:12.257Z
Steven Grant
<p>My category field was inside a Matrix field.</p>

<p>These links helped with the twig logic:</p>

<p><a href="https://craftcms.stackexchange.com/questions/4830/is-it-possible-to-have-category-listing-page-of-entries-if-the-category-is-defin?rq=1">Is it possible to have category listing page of entries if the category is defined within a matrix block inside said entries?</a></p>

<p><a href="https://craftcms.stackexchange.com/questions/8463/find-entries-that-have-a-category-selected-from-a-category-field-within-a-matrix">Find entries that have a category selected from a category field within a matrix block</a></p>

CC BY-SA 3.0
2015-05-27T23:27:22.873Z
2015-05-27T23:27:22.873Z
Niall Thompson
<p>I am trying to display entries based on the last segment in the url and then paginate.</p>

<p>Here's what I have so far but it's not displaying any entries:</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) %}
      &lt;ul&gt;

      {% paginate entries as entries %}

      {% for entry in entries %}

      {% for block in entry.resource.type('resource') %}

      &lt;li class="summary m-all t-all d-all"&gt;
      &lt;a href="{{ entry.url }}"&gt;
      &lt;article&gt;
      &lt;header class="article-header"&gt;
      &lt;h1&gt;{{ block.resourceTitle }}&lt;/h1&gt;
      &lt;h5&gt;{{ block.resourceAuthors }}&lt;/h5&gt;
      &lt;p&gt;{{ block.resourceSummary }}
      &lt;span class="link"&gt;Read more&lt;/span&gt;
      &lt;/p&gt;
      &lt;/header&gt;
      &lt;/article&gt;
      &lt;/a&gt;
      &lt;/li&gt;
      &lt;hr class="m-all t-all d-all"&gt;

      {% endfor %}

      {% endfor %}

      &lt;/ul&gt;

      {% if paginate.prevUrl %}
          &lt;a href="{{ paginate.prevUrl }}"&gt;Previous&lt;/a&gt;
      {% endif %}

      {% if paginate.nextUrl %}
          &lt;a href="{{ paginate.nextUrl }}"&gt;Next&lt;/a&gt;
      {% endif %}
      {% endpaginate %}

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

<p>Even this simplified version outputs zero entries:</p>

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

  {% set entries = craft.entries.relatedTo(category) %}

  {# Output them #}
  {% for entry in entries %}
      &lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;
  {% endfor %}
</code></pre>

<p>Any thoughts?</p>

CC BY-SA 3.0
2015-05-27T20:07:09.410Z
Your simplified version, which is generic enough for me to test without modification, works fine for me. So, I'm wondering if the problem doesn't lie elsewhere than in the code snippet.
Jack McKenzie
<entries><categories><pagination>
Display Category Entries Based on Slug
# Display Category Entries Based on Slug

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

I am trying to display entries based on the last segment in the url and then paginate.
Here's what I have so far but it's not displaying any entries:
{% set categorySlug = craft.request.getLastSegment() %}
  {% set category = craft.categories.slug(categorySlug).first() %}

  {% if category %}

      {% set entries = craft.entries.relatedTo(category).limit(12) %}
      

      {% paginate entries as entries %}

      {% for entry in entries %}

      {% for block in entry.resource.type('resource') %}

      
      
      
      
      {{ block.resourceTitle }}
      {{ block.resourceAuthors }}
      {{ block.resourceSummary }}
      Read more
      
      
      
      
      
      

      {% endfor %}

      {% endfor %}

      

      {% if paginate.prevUrl %}
          Previous
      {% endif %}

      {% if paginate.nextUrl %}
          Next
      {% endif %}
      {% endpaginate %}

  {% endif %}

Even this simplified version outputs zero entries:
  {% set categorySlug = craft.request.getLastSegment() %}
  {% set category = craft.categories.slug(categorySlug).first() %}

  {% set entries = craft.entries.relatedTo(category) %}

  {# Output them #}
  {% for entry in entries %}
      {{ entry.title }}
  {% endfor %}

Any thoughts?

**Tags:** entries, categories, pagination

> **Comments:**
> **username_1**: Your simplified version, which is generic enough for me to test without modification, works fine for me. So, I'm wondering if the problem doesn't lie elsewhere than in the code snippet.  

---

## 2 answers

### Answer by username_2 on 2015-05-27. Score: 1

I'm rolling the same thing with 
{% extends 'layouts/_entry_layout' %}
{# sets the name for the css file to be pulled #}
{% set pageType = 'search' %}
{% set catSlug = craft.request.getSegment(2) %}
{% set title = craft.categories.slug(catSlug).first() ~ ' Channel' %}

{% block content %}



{% paginate craft.entries.relatedTo(category) as entriesOnPage %}


{{ category.title }}

    {% for entry in entriesOnPage %}
        {% include 'modules/_article_listing' %}
    {% endfor %}

{% include 'inc/_pagination' %}

{% endpaginate %}



{% endblock %}

my article listing module contains the usual things like {{ entry.title }} etc
and pagination include is like so:
{% if paginate %}

{% set currentPage = paginate.currentPage %}
{% set startPage = currentPage - 2 %}
{% set endPage = currentPage + 2 %}
{% if query is defined %}
{% set queryString = "?q=" ~ query %}
{% endif %}


{% if paginate.totalPages > 1 %}


    

        {% if paginate.prevUrl %}
        
            
                ←
                Previous Page
            
        
        {% endif %}
        {% for i in startPage..endPage %}
        {% if paginate.getPageUrl( i ) %}
        {% if i != currentPage %}

        
            
                Page {{ i }}
            
        

        {% else %}

        
            Current Page {{ i }}
        

        {% endif %}
    
    {% endif %}
    {% endfor %}

    {% if paginate.nextUrl %}
    
        
            Next Page
            →
        
    
    {% endif %}






{% endif %}

{% endif %}


---

### Answer by username_0 on 2015-05-27. Score: 0

My category field was inside a Matrix field.

These links helped with the twig logic:

[Is it possible to have category listing page of entries if the category is defined within a matrix block inside said entries?](https://craftcms.stackexchange.com/questions/4830/is-it-possible-to-have-category-listing-page-of-entries-if-the-category-is-defin?rq=1)

[Find entries that have a category selected from a category field within a matrix block](https://craftcms.stackexchange.com/questions/8463/find-entries-that-have-a-category-selected-from-a-category-field-within-a-matrix)


---

