Skip to main content
added 41 characters in body
Source Link
Brad Bell
  • 67.6k
  • 6
  • 75
  • 145

I'm using Craft3Craft 3 and have created a section (channel type) for my project entries. At the bottom of each project page I have my Prev and Next Project buttons. How do I target the first and last project entry based upon the post date? I want to add some space between the buttons when they're together, but dispense with it on the first and last entries because.

Below is my current code from my project _entry template for the buttons:

{% set params = {section: 'projectEntries', order: 'postDate desc', limit: null} %} {% set entry_prev = entry.getPrev(params) %} {% set entry_next = entry.getNext(params) %}

{% set params = {section: 'projectEntries', order: 'postDate desc', limit: null} %}
{% set entry_prev = entry.getPrev(params) %}
{% set entry_next = entry.getNext(params) %}

Then on the buttons I'm using an if statement to show the next or prev urlsURLs.

To target the first entry I've tried using :

{% if craft.entries.section('projectEntries').order('postDate desc').one() %} show alt button code {% else %} show regular button code {% endif %}

{% if craft.entries.section('projectEntries').order('postDate desc').one() %}
    show alt button code
{% else %}
    show regular button code
{% endif %}

Which shows my alt button code, but shows it on every project page, instead of just on the first entry.

What do I need to do?

Thanks,

Richard

I'm using Craft3 and have created a section (channel type) for my project entries. At the bottom of each project page I have my Prev and Next Project buttons. How do I target the first and last project entry based upon the post date? I want to add some space between the buttons when they're together, but dispense with it on the first and last entries because.

Below is my current code from my project _entry template for the buttons:

{% set params = {section: 'projectEntries', order: 'postDate desc', limit: null} %} {% set entry_prev = entry.getPrev(params) %} {% set entry_next = entry.getNext(params) %}

Then on the buttons I'm using an if statement to show the next or prev urls.

To target the first entry I've tried using :

{% if craft.entries.section('projectEntries').order('postDate desc').one() %} show alt button code {% else %} show regular button code {% endif %}

Which shows my alt button code, but shows it on every project page, instead of just on the first entry.

What do I need to do?

Thanks,

Richard

I'm using Craft 3 and have created a section (channel type) for my project entries. At the bottom of each project page I have my Prev and Next Project buttons. How do I target the first and last project entry based upon the post date? I want to add some space between the buttons when they're together, but dispense with it on the first and last entries because.

Below is my current code from my project _entry template for the buttons:

{% set params = {section: 'projectEntries', order: 'postDate desc', limit: null} %}
{% set entry_prev = entry.getPrev(params) %}
{% set entry_next = entry.getNext(params) %}

Then on the buttons I'm using an if statement to show the next or prev URLs.

To target the first entry I've tried using :

{% if craft.entries.section('projectEntries').order('postDate desc').one() %}
    show alt button code
{% else %}
    show regular button code
{% endif %}

Which shows my alt button code, but shows it on every project page, instead of just on the first entry.

What do I need to do?

Thanks,

Richard

Source Link

Targeting the first entry item

I'm using Craft3 and have created a section (channel type) for my project entries. At the bottom of each project page I have my Prev and Next Project buttons. How do I target the first and last project entry based upon the post date? I want to add some space between the buttons when they're together, but dispense with it on the first and last entries because.

Below is my current code from my project _entry template for the buttons:

{% set params = {section: 'projectEntries', order: 'postDate desc', limit: null} %} {% set entry_prev = entry.getPrev(params) %} {% set entry_next = entry.getNext(params) %}

Then on the buttons I'm using an if statement to show the next or prev urls.

To target the first entry I've tried using :

{% if craft.entries.section('projectEntries').order('postDate desc').one() %} show alt button code {% else %} show regular button code {% endif %}

Which shows my alt button code, but shows it on every project page, instead of just on the first entry.

What do I need to do?

Thanks,

Richard