1

I hope someone can help me to understand this.

I have a Channel called eg. "My channel". In that channel i have two entries:
Post 1 and Post 2. Those two entries have different titles and content.

If I go to "my-channel/post-1" in the browser, and then to "my-channel/post-2" they have the same content based on the Post 2 (last created entry).

If I make "Post 2" inactive, then Post 1 will have the correct content.

What am i forgetting here?

4
  • How is your section Entry URI Format and Template setup? Commented Dec 11, 2018 at 13:00
  • My entry URI is: my-channel/{slug} , and in the folder templates I have the folder my-channel with a _entry.twig file in it. It is like it takes the latest created entry and then all the slugs goes to that content.
    – Joe
    Commented Dec 11, 2018 at 13:17
  • Is your _entry.twig file setting the entry manually or are you retrieving all of the channel at some point in the template? Commented Dec 11, 2018 at 13:21
  • Do you mean like the for loop: {% for entry in craft.entries.section('my-channel').limit(1).all() %}
    – Joe
    Commented Dec 11, 2018 at 13:25

1 Answer 1

2

Because your Entry URI is setup as my-channel/{slug} , When you go to my-channel/post-slug-1 Craft automatically sets the variable 'entry' to the entry post-slug-1. You don't need to loop through the channel at this point. You can just use the entry variable.

entry.fieldName
entry.slug
entry.url 

etc...

So just remove your for loop and use 'entry'

Using

{% for entry in craft.entries.section('my-channel').limit(1).all() %}

Will get the first entry of the my-channel section. That's useful for pages where you need to list out all of your entries in that section or get specific ones.

1
  • 1
    Thank you for the reply and the explanation. It worked out Great :)
    – Joe
    Commented Dec 11, 2018 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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