All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

exp:low_reorder:next_entry - retrieving category_id on single entry templates without using the category in a URL segment

Jon 20 Nov 2013 01:39 question, complete

Using exp:low_reorder:next_entry on sets using "show entries per single category", how can I get a category_id within a single entry template where I do not use categories in the URL for the single entry template?

For listing entries by category, I use a URL structure like this:
topics/list/category/{cat_url_title}

Then those listed entries link to a template to display the single entry:
topics/detail/{entry_url_title}

Each entry is assigned to a "last child" category (and auto assigned to that category's parent). My sets are sorted by the last child categories and those sets are all I am interested in using to display the next/prev entry.

When I display an entry, I would like the template to be able to pluck out the last child category it is assigned to and provide a next/prev entry link within that last child category.

One suggestion might be to use the category url title as a segment of the URL, and use Seg2Cat to convert it to the category_id. This would require installing an additional addon, modifying my URL structure, and editing multiple templates to reflect the new URL structure. In addition, I would not be able to include that category segment in my URLs in search results.

Is there an easier or better way to do what I want?

I use gwcode_categories elsewhere in my templates, so I have been experimenting with that. No luck so far.

Replies

  1. Low 20 Nov 2013 07:27

    Well, since an entry can belong to multiple Low Reorder sets, you need to feed the prev/next entry tags both the set name/id and category id. Also, an entry can belong to multiple categories, so it's extra important to pass through a valid category ID here, too. If you're not using categories in your URLs, you'll need to use the {categories}{/categories} var pair to generate the ID, and nest the prev/next tags inside the Entries tag.

    {exp:low_reorder:prev_entry 
    set="my_set"
    category="{categories limit="1"}{category_id}{/categories}"
    } ... {/exp:low_reorder:prev_entry}


    You might need to exclude the parent IDs from it by using the show parameter, which you'll probably need to hard-code.

  2. Jon 20 Nov 2013 20:27

    Thanks for your reply.

    I had thought of nesting the prev/next_entry tags inside of the Entries tag pair to make use of the categories pair, but I thought the prev/next_entry tags didn't work properly inside of the Entries tags.

    I tried your suggestion with this code:

      
    {exp:channel:entries channel="topic" require_entry="yes" limit="1" disable="category_fields|member_data|pagination"}
    <div id="prev-next" class="prev-next pagination pagination-large pagination-right">
    <ul>
    {exp:low_reorder:prev_entry set="topics_per_category" url_title="{segment_3}" category="{categories limit="1" show="not 1|22"}{category_id}{/categories}"}
    <li><a href="{path="topics/detail/{url_title}"}" title="{title}" data-toggle="tooltip" data-placement="bottom"><i class="icon-chevron-left icon-gray"></i> Prev</a></li>
    {if no_results}{/if}
    {/exp:low_reorder:prev_entry}

    {exp:low_reorder:next_entry set="topics_per_category" url_title="{segment_3}" category="{categories limit="1"show="not 1|22"}{category_id}{/categories}"}
    <li><a href="{path="topics/detail/{url_title}"}" title="{title}" data-toggle="tooltip" data-placement="bottom">Next<i class="icon-chevron-right icon-gray"></i></a></li>
    {if no_results}{/if}
    {/exp:low_reorder:next_entry}
    </ul>
    </div>
    {/exp:channel:entries}


    Next/Prev links are built, but they do not link to the correct entry. Instead they link to the entry currently being displayed on the same page.

  3. Low 20 Nov 2013 20:36

    Use the prefix parameter to avoid variable name conflicts: http://gotolow.com/addons/low-reorder...

  4. Jon 20 Nov 2013 20:51

    Should I use the prefix parameter on the exp:low_reorder:next_entry tags or the exp:channel:entries tag?

    I added a prefix="loworder" to the next_entry tag, and then used {loworder_title} inside the tags. It did not parse it.

  5. Low 20 Nov 2013 21:04

    The prefix parameter should include the entire prefix, including the (optional) underscore. So use something like:

    {exp:low_reorder:next_entry ... prefix="pfx_"} 
    {pfx_title}
    {/exp:low_reorder:next_entry}

  6. Jon 20 Nov 2013 21:33

    Thanks, that seemed to do the trick!

    How does the prefix affect the {if no_results} conditional?

  7. Low 20 Nov 2013 22:24

    It does not. But you should be able to use {if low_reorder_no_results} too.

  8. Jon 21 Nov 2013 01:08

    Thanks for your support.