2

I have some Featured news entries which appear at the top of the rest of the news entries.

How do I set this so they are only on page 1 (before any pagination pages)?

{# Only show on page 1 of pagination #}

   {% for entry in craft.entries.section('newsEvents').highlightNews('1').limit(2) %}

   <div class="col-12 {% if loop.index is divisibleby(2) %}last{% endif %} panel ">

     {% if entry.listingImage|length %}
    {% for image in entry.listingImage %}
      <div class="panel__img">
        <a href="{{ entry.url }}"><img src="{{ image.getUrl('listingMedium')}}" alt="{{ image.title }}" /></a>
      </div>

    {% endfor %}

    {% endif %}

  </div>

{# End only show on page 1 of pagination #}



{% paginate craft.entries.section('newsEvents').limit(12) as entriesOnPage %}

  {% for entry in entriesOnPage %}

    ...

  {% endfor %} 


{% if paginate.totalPages > 1 %}

{% set pagination = true %}

  <ul class="pagination">
    {% if paginate.prevUrl %}<li><a href="{{ paginate.prevUrl }}">&#171;</a></li>{% endif %}

    {% for page, url in paginate.getPrevUrls(5) %}
        <li><a href="{{ url }}">{{ page }}</a></li>
    {% endfor %}

    <li class="current">{{ paginate.currentPage }}</li>


    {% for page, url in paginate.getNextUrls(5) %}
        <li><a href="{{ url }}">{{ page }}</a></li>
    {% endfor %}

    {% if paginate.nextUrl %}<li><a href="{{ paginate.nextUrl }}">&#187;</a></li>{% endif %}

 </ul>

{% endif %}
sarah3585
  • 899
  • 7
  • 14

1 Answers1

3

UPDATED/EDIT ANSWER:

If you only want to show the entries on the first page you should make an if statement to check if you are on the first page for your Featured Items by requesting the page number.

Option 1:

{% if craft.request.getPageNum() == 1 %} 

// Featured content here

{% endif %}

Option 2:

{% if craft.request.getLastSegment() == 'p1' %} 

// Featured content here

{% endif %}

The first option is the best / cleanest solution even though they give the same outcome. Option 2 is a nice work around but might be more usefull in other ways then this one.

More about craft requests can be found in the docs: https://craftcms.com/docs/templating/craft.request

Justin Dekkers
  • 1,427
  • 11
  • 27
  • It's not that I'm trying to remove Featured news out of the pagination. I need to remove the featured news items out of the template if the page isn't the first. So when the user goes to page 2 the Featured news items aren't at the top. – sarah3585 Mar 15 '17 at 16:15
  • Then I should make an if statement that that gets the page by your "last segment" Ill update the answer – Justin Dekkers Mar 15 '17 at 16:19
  • 1
    Thanks, I ended up using {% if craft.request.getPageNum() == 1 %} which you put me on the right path for. Update your answer and I'll mark it correct as you got me 99% there. – sarah3585 Mar 15 '17 at 17:11