<p>You could use the <a href="https://craftcms.com/docs/templating/entrymodel#getNext" rel="nofollow noreferrer"><code>getNext()</code></a> and <a href="https://craftcms.com/docs/templating/entrymodel#getPrev" rel="nofollow noreferrer"><code>getPrev()</code></a> methods on your entry like this:</p>

<pre><code>{% set params = craft.entries.section('yoursection').order('postDate asc') %}

{% set prevEntry = entry.getPrev(params) %}
{% set nextEntry = entry.getNext(params) %}
{# to access url, I use #}
{{ prevEntry.url }}
{# to access title, I use #}
{{ prevEntry.title }}
</code></pre>

<p>NOTE: I've shamelessly pinched this code from the answer <a href="https://craftcms.stackexchange.com/questions/14755/best-way-to-access-getprev-and-getnext-asset-fields">here</a>.</p>

<p>You need to setup the <code>params</code> variable so that it would create a list of entries which would include your current entry and the next/prev entries you expect. So include your ordering by <code>postDate</code> etc.</p>

CC BY-SA 3.0
2017-11-29T15:03:34.430Z
2017-11-29T15:03:34.430Z
Steve Holland
<p>You should read about how to create a plugin from the <a href="https://craftcms.com/docs/plugins/introduction" rel="nofollow noreferrer">Craft docs</a>, then you can create one with <a href="http://Pluginfactory.io" rel="nofollow noreferrer">Pluginfactory.io</a></p>
<p>I'll reload the entries with javascript in my example since I don't like reloading the page every single time and ajax is the way to go in these days. You can achieve this without any javascript/php code with only twig but users would have to refresh and reload the entire page then.</p>
<p>First you need a Controller that loads your entry and return a template. You could as well increase your limit and show/hide the rest of the entries via javascript or css but since you asked for only one I'll provide the code to only show one.</p>
<pre><code>public function actionSearchEntry()
{
    $offset = craft()-&gt;request-&gt;getParam('offset');
    $criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
    $criteria-&gt;section = &quot;news&quot;;
    $criteria-&gt;orderBy = &quot;postDate&quot;;
    $criteria-&gt;limit = 1;
    $criteria-&gt;offset = $offset;
    $entries = $criteria-&gt;find();
    $template = '';
    // to let your javascript know if it was successfuly
    $success = false;
    if($entries){
        $template = craft()-&gt;templates-&gt;render('path/to/your/template', array(
            'entry' =&gt; $entries[0]
        ));
        $success = true;
    }else{
        // render some not found template or search again to show the first one or so
    }
    $this-&gt;returnJson([
        'html'      =&gt; $template,
        'success'   =&gt; $success
    ]);
}
</code></pre>
<p>And this is your javascript file</p>
<pre><code>var offset = 0;
$(&quot;#reloadButtonClick&quot;).change(function(){
    offset++;
    var data = {
        action: &quot;pluginname/controllerName/searchEntry&quot;,
        offset: offset
    };
    $.ajax({
        type: &quot;post&quot;,
        url: '',
        data: data,
        success: function(data){
            if(data.success === true){
                $(&quot;#idOfYourDiv&quot;).html(data.html);
            }else{
                // display some errors or so
                offset = 0;
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            console.log(&quot;Status: &quot; + textStatus);
        }
    });
});
</code></pre>
<p>When you want to &quot;scroll&quot; to the previous entry you have to decrease your offset at some point.
Note: this is just a very basic example to show you the direction, I did not include much error handling you should to that on your own</p>

CC BY-SA 4.0
2022-02-15T18:22:55.940Z
I am needing an 'endless loop' through my entries for a kiosk application, and was wondering if this approach would work for that?  I had been using just Twig on a template, cycling through my selected entries with Javascript, but after running the loop for several hours, it crashes with a 500 error (incomplete load/timeout).  It always loads incomplete at a different place in the load.  Thanks for any leads.
buck1112
CC BY-SA 4.0
2022-02-16T10:34:48.033Z
I would suggest you to create a new question for this as it's more complicate to answer.. Furthermore this is for Craft 2 and I'm sure you are running a Craft 3 instance as of now
Robin Schambach
CC BY-SA 4.0
2022-02-18T16:20:09.853Z
Thanks.  It's a Craft 2 site I inherited.  Here's my new question: https://tinyurl.com/4y726svw.
buck1112
CC BY-SA 3.0
2017-11-29T14:18:06.900Z
2017-11-29T14:24:09.727Z
2020-06-17T08:56:27.903Z
Robin Schambach
<p>I need to display entries that contain an image, and a piece of text, on the home page of my website. <br /></p>

<p>When someone clicks 'next', I would like it to go to the next entry (by post date) and display that entries image and text. I also need the user to be able to click on 'previous' (by post date again) and 'random'. <br /></p>

<p>How do I go about this? <br /></p>

<p>Thanks! </p>

<entries><craft.entries>
How do I display entries 1 by 1?
# How do I display entries 1 by 1?

(Asked by: username_0 on 2017-11-29)

I need to display entries that contain an image, and a piece of text, on the home page of my website.

When someone clicks 'next', I would like it to go to the next entry (by post date) and display that entries image and text. I also need the user to be able to click on 'previous' (by post date again) and 'random'.

How do I go about this?

Thanks!

**Tags:** entries, craft.entries


---

## 2 answers

### Answer by username_1 on 2017-11-29. Score: 4 | Accepted answer

You could use the getNext() and getPrev() methods on your entry like this:
{% set params = craft.entries.section('yoursection').order('postDate asc') %}

{% set prevEntry = entry.getPrev(params) %}
{% set nextEntry = entry.getNext(params) %}
{# to access url, I use #}
{{ prevEntry.url }}
{# to access title, I use #}
{{ prevEntry.title }}

NOTE: I've shamelessly pinched this code from the answer here.
You need to setup the params variable so that it would create a list of entries which would include your current entry and the next/prev entries you expect. So include your ordering by postDate etc.


---

### Answer by username_2 on 2017-11-29. Score: 1

You should read about how to create a plugin from the Craft docs, then you can create one with Pluginfactory.io
I'll reload the entries with javascript in my example since I don't like reloading the page every single time and ajax is the way to go in these days. You can achieve this without any javascript/php code with only twig but users would have to refresh and reload the entire page then.
First you need a Controller that loads your entry and return a template. You could as well increase your limit and show/hide the rest of the entries via javascript or css but since you asked for only one I'll provide the code to only show one.
public function actionSearchEntry()
{
    $offset = craft()->request->getParam('offset');
    $criteria = craft()->elements->getCriteria(ElementType::Entry);
    $criteria->section = "news";
    $criteria->orderBy = "postDate";
    $criteria->limit = 1;
    $criteria->offset = $offset;
    $entries = $criteria->find();
    $template = '';
    // to let your javascript know if it was successfuly
    $success = false;
    if($entries){
        $template = craft()->templates->render('path/to/your/template', array(
            'entry' => $entries[0]
        ));
        $success = true;
    }else{
        // render some not found template or search again to show the first one or so
    }
    $this->returnJson([
        'html'      => $template,
        'success'   => $success
    ]);
}

And this is your javascript file
var offset = 0;
$("#reloadButtonClick").change(function(){
    offset++;
    var data = {
        action: "pluginname/controllerName/searchEntry",
        offset: offset
    };
    $.ajax({
        type: "post",
        url: '',
        data: data,
        success: function(data){
            if(data.success === true){
                $("#idOfYourDiv").html(data.html);
            }else{
                // display some errors or so
                offset = 0;
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            console.log("Status: " + textStatus);
        }
    });
});

When you want to "scroll" to the previous entry you have to decrease your offset at some point.
Note: this is just a very basic example to show you the direction, I did not include much error handling you should to that on your own

> **Comments:**
> **username_3**: I am needing an 'endless loop' through my entries for a kiosk application, and was wondering if this approach would work for that?  I had been using just Twig on a template, cycling through my selected entries with Javascript, but after running the loop for several hours, it crashes with a 500 error (incomplete load/timeout).  It always loads incomplete at a different place in the load.  Thanks for any leads.  
> **username_2**: I would suggest you to create a new question for this as it's more complicate to answer.. Furthermore this is for Craft 2 and I'm sure you are running a Craft 3 instance as of now  
> **username_3**: Thanks.  It's a Craft 2 site I inherited.  Here's my new question: https://tinyurl.com/4y726svw.  

---

