1

Is there a way to get the prev and next entry from the current entry, when this entry is inside a channel and not a structure?

query ($id: [QueryArgument], $rel: Int) {
  entry: entry(id: $id) {
    id
    slug
    title
    uri
  }
  next: entry(nextSiblingOf: $rel) {
    id
    slug
    title
    uri
  }
  previous: entry(prevSiblingOf: $rel) {
    id
    slug
    title
    uri
  }
}

Output when the entry is in a structure:

{
  "data": {
    "entry": {
      "id": "145",
      "slug": "neuigkeiten",
      "title": "Neuigkeiten",
      "uri": "neuigkeiten"
    },
    "next": {
      "id": "150",
      "slug": "leistungen",
      "title": "Leistungen",
      "uri": "leistungen"
    },
    "previous": {
      "id": "141",
      "slug": "unsere-praxis",
      "title": "Unsere Praxis",
      "uri": "unsere-praxis"
    }
  }
}

and the result when the entry is inside a channel:

{
  "data": {
    "entry": {
      "id": "182",
      "slug": "david-hellmann-1-2",
      "title": "David Hellmann",
      "uri": "team/david-hellmann-1-2"
    },
    "next": null,
    "previous": null
  }
}

is there a way to get this data?

3

You should be able to use next and prev (see documentation and this issue).

query getEntryData($id: [QueryArgument]) {
  entry(id: $id) {
    id,
    slug,
    title,
    uri,
    prev(section: "blog", orderBy: "postDate desc") {
      id,
        slug,
        title,
        uri
    },
    next(section: "blog", orderBy: "postDate desc") {
      id,
        slug,
        title,
        uri
    }
  }
}
1
  • Thanks @oli that means orderby id required here? – davidhellmann Mar 16 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.