I want to iterate through my entries on the click of a 'next' and 'previous' button.
I have started off using getNext() and getPrev() by I'm in a bit of a rut.
{% set entry = craft.entries.section('comics').first() %}
{% set asset = entry.comic.first() %}
{% set params = craft.entries.section('comics').order('id asc') %}
{% set prevEntry = entry.getPrev(params) %}
{% set prevAsset = prevEntry.comic.first() %}
{% set nextEntry = entry.getNext(params) %}
{% set nextAsset = nextEntry.comic.first() %}
This is the Twig code. To display the prevEntry I have been using jQuery. Here is that code.
function prevComic() {
var $prevTitle = "{{ prevEntry.title }}";
$(".comic-title").text($prevTitle);
$(".comic").attr('src', '{{ prevAsset.url }}');
$(".comic-caption").text("{{ prevEntry.body }}");
};
function nextComic() {
var $nextTitle = "{{ nextEntry.title }}";
$(".comic-title").text($nextTitle);
$(".comic").attr('src', '{{ nextAsset.url }}');
$(".comic-caption").text("{{ nextEntry.body }}");
};
Then I'm using onclick() on the buttons to call the functions. All I really want is for the 'previous' button to give me the previous entry to the entry currently displayed, and for the 'next' button to give me the next entry to the entry currently displayed. Can anyone help me? Thank you :)