OK, another problem with Expression Engine. I know it pretty well but i'm sort-of just learning categories!
I've searched around for this answer but can only find the same thing. I need to have a next button on a title_permalink page that goes to the next entry in that category. I know how to manually specify a category but that won't work as it will only ever give me entries from that category! I need a way for ee to know what category the entry is in. My code is very simple at the moment, it's :
{exp:channel:next_entry}<a href="{path='projects-test/view'}" style="color:#fff;">Next Project</a>{/exp:channel:next_entry}
I could add category_id="2" but then what happens whenever the person goes into a category that isn't 2, they are all using the same view template.
My structure is like follows:
Category Selection page - list of categories using category_name tag
Project List page - links here using channel:entries tag
Project View page - linked here by a title_permalink tag
Thanks for any help!
The default ExpressionEngine Next/Previous Entry Linking Tag Pairs allow you to generate links to the next or previous entry, based on the date of the current entry.
However, the biggest limitation is that they not as robust when it comes to restricting or filtering entries with multiple categories.
If your needs are simple, you can use the following code to restrict the Previous/Next links to showing entries within the current entry's category:
{exp:channel:entries channel="channel_name"}
...
{exp:channel:prev_entry category="{categories}{category_id}|{/categories}"}
« <a href="{id_path=template_group/template}">Previous</a>
{/exp:channel:prev_entry}
{exp:channel:next_entry category="{categories}{category_id}|{/categories}"}
<a href="{id_path=template_group/template}">Next</a> »
{/exp:channel:next_entry}
...
{/exp:channel:entries}
You'll notice that the {exp:channel:prev_entry}
and {exp:channel:next_entry}
links are nested inside the {exp:channel:entries}
tag and use the {categories}
tag pair to restrict the Next/Previous links to the current entry's category.
Realize, however, that this code works best when entries are classified using a single category.
Otherwise, when using the {categories}
tag pair with an entry having multiple categories, the Previous/Next links will default to the first category output ... which may be different than the next or previous entry's order of categories.
For a more robust solution, you'll find there are many third-party solutions on Devot-ee for entry linking.
Two of my favorite plugins for handling linked entries are Nearby Entries by Adam Khan and Entries List by Laisvunas.