ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Next and Previous entry within a catagery

January 31, 2011 10:14am

Subscribe [4]
  • #1 / Jan 31, 2011 10:14am

    James Hurst

    48 posts

    Hi -

    We are trying to display the next and previous entry of the curent item on display.

    We are trying to keep the template code as lean as possible and have:

    {exp:channel:next_entry channel="{segment_1}" {if segment_3}category="{segment_3_category_id}"{/if}}
                <em>Next entry: </em><a href="http://{path=%27{segment_1}{if">{title}</a>
    
                {/exp:channel:next_entry}
                {exp:channel:prev_entry channel="{segment_1}" {if segment_3}category="{segment_3_category_id}"{/if}}
                <em>Previous entry: </em><a href="http://{path=%27{segment_1}{if">{title}</a>
                {/exp:channel:prev_entry}

    Which displays the next and previous entry when viewed from the primary navigation; but when a detail page is viewed from within a category; we can’t seem to pick up the next and previous items within a category.

    To check that our conditionals aren’t out of whack we have simplified the above to say

    {exp:channel:next_entry category="2"}
                <em>Next entry: </em>{title}
    
                {/exp:channel:next_entry}
                {exp:channel:prev_entry category="2"}
                <em>Previous entry: </em>{title}
                {/exp:channel:prev_entry}

    And still we aren’t able to see - when viewing a detail page under a category - the next or previous item within that cateogry.

    What are we missing?

    Many thanks -
    James

    Moved to CodeShare Corner by Moderator

  • #2 / Feb 01, 2011 4:07am

    John Henry Donovan

    12339 posts

    James,

    What version and build of EE are you using?
    Any third_party add-ons?

    Can you give an example of your URLs for both particular pages?

    These links can only be used on pages displaying a single entry, such as a “comment” page, since they are designed to provide navigation from one entry to another.

  • #3 / Feb 01, 2011 8:03am

    James Hurst

    48 posts

    Hi John -

    Thanks for getting in touch

    Version: v2.1.3
    Build: 20101220

    Third party apps:
    Build with Structure
    Field Frame
    Low Seg2Cat
    Matrix
    Playa
    Structure

    The two URLs are:
    From the first level navigation
    Work > Work Detail
    http://www.curestudio.com/work/work_test_4
    Where the next and previous navigation items work

    From a category:
    Work > Category > Detail
    http://www.curestudio.com/work/category/case_studies/work_test_4
    Where the next and previous items don’t work

    Thanks in advance for your help!

    All the best
    James

  • #4 / Feb 01, 2011 5:49pm

    Ingmar

    29245 posts

    I am afraid you can’t use conditionals in your EE tags quite like that. Try with a reduced template:

    {if segment_3 != ""}
    {exp:channel:next_entry channel="{segment_1}"}
                <em>Next entry: </em><a href="http://{path={segment_1}}">{title}</a>
    
                {/exp:channel:next_entry}
    {if:else}
    {exp:channel:next_entry channel="{segment_1}" category="{segment_3_category_id}"{/if}}
                <em>Next entry: </em><a href="http://{path={segment_1}/{segment_2}/{segment_3}}">{title}</a>
    
                {/exp:channel:next_entry}
    {/if}

    When you hardcode the category_id, does that work?

  • #5 / Feb 02, 2011 10:07am

    James Hurst

    48 posts

    Hi Ingmar - thanks for the tip -

    The next / previous items work when navigating from the primary navigation (so viewing a detail page from the primary navigation ‘work’ I can see the next and previous items.

    But when I look at the same detail page within a category - I dont see any next and previous options. If I hardcode it and remove the ‘channel’ (so just using the category ID to get the next and previous) it always shows (irrespective of which entry is being viewed) the next entry as the first entry added to a category…

    Any other ideas?

    Many thanks!

    All the best
    James

  • #6 / Feb 02, 2011 5:15pm

    Sue Crocker

    26054 posts

    I’m confused. A detail page within a category? Normally your detail pages are stand alone templates that can use next and previous…

  • #7 / Feb 06, 2011 8:52am

    James Hurst

    48 posts

    Hi Sue - i’ll try and be completely clear:

    There are a number of items - lets say 100. When viewing those 100 items under the channel that they are posted in - I would like to cycle through all 100 items using next and previous.

    However - that big bag of 100 items can also be categorised into different smaller piles; lets say 4 piles of 25 items. I would like; at that stage in the process the ability to cycle through the next and previous items posted in that smaller pile of 25 items.

    Thankfully - the URL changes to help us achieve that:

    When viewing the big bag of 100 items - I will have one word in my segment_1 which will be the channel name and one word in my segment_2 which will be my title. When i’m viewing one of the smaller piles (with 25 items in) - i’ll have the word ‘category’ in my segment_2 and the title of the category in question in segment 3 and the title of the item in my segment 4.

    So - to achieve what I’d think is a pretty basic function - i’ve used Low’s seg2cat - so I can pull out the category id of that segment_4 item - but my next and previous options aren’t working as expected on the front end.

    I have since tried to hardcode the category ID to make sure it isn’t the third party add on - and still - I am unable to see the next and previous items when viewing a detail page of an item from within a category. To avoid any confusion - I can see the next and previous items when viewing from the main navigation.

    Does that make more sense Sue? If you have any advice it would be greatly appreciated.

    All the best
    James

  • #8 / Feb 07, 2011 7:53am

    Sue Crocker

    26054 posts

    I honestly don’t think that’s going to work.. that kind of pagination isn’t meant to work with categories. What I’m going to do is move this to the CodeShare Corner so that other members can offer advice. Failing that, feel free to make a Feature Request for that functionality.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases