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.

Single Entry Format While Multiple Entries

December 19, 2011 12:15pm

Subscribe [2]
  • #1 / Dec 19, 2011 12:15pm

    matyus

    6 posts

    I’m having a lot of trouble working out the logic for this certain webpage I’m building.
    I’m also wondering if there’s a certain plug-in that can help me, but I really don’t know where to start how exactly how to search for the solution.

    Ideally, I would like to use the {exp:channel:prev_page} and {exp:channel:next_page}  entry linking so that I can page through different projects I have set up as separate entries. It doesn’t seem like the {paginate} feature lets me format the URL using url_title, like index.php/projects/project-one, /project-two, etc., because the {auto_path} format is /P1, /P2, etc., and that isn’t an acceptable URL for me.

    This is all good, except below the single entry on this page, I need to show a list of all the projects in the same channel.

    Can anyone help enlighten me?:

    How do I set up the page so that I can have {exp:channel:entries channel="projects"} grabbing the single entry from the URL and then a second {exp:channel:entries channel="projects"} ignoring the URL so that it can display a list of the entries in that same channel? Because right now, both of my {exp:channel:entries} are treated like “single” entries and only display information for the entry displayed in the URL.

  • #2 / Dec 20, 2011 9:23am

    tidy

    196 posts

    Hi Matyus,
    For the entries tag where you want to ignore the URL add dynamic=“no”:

    {exp:channel:entries channel="projects" dynamic="no"}

    Also, re the first part of your post, to link to next/previous entries on a single entry page (with url_title friendly URLs) you can use next and previous entry tags outside your channel entries tag - see the user guide for info:
    http://ellislab.com/expressionengine/user-guide/modules/channel/entry_linking.html

     

     

  • #3 / Dec 20, 2011 12:18pm

    matyus

    6 posts

    Thanks Tidy,
    dynamic=“no” did the trick! I thought I tried that while I was scouring the documentation last week, but maybe I just implemented it incorrectly the first time.

    The problem I’m having with the tag pairs from the page you’ve provided is that they don’t automatically limit the pagination per category, and I don’t see a convenient way to specify the category parameter by using a URL segment.

    For instance, instead of having the default category indication “C1” “C2” etc, I have specified a category URL indicator, so everything looks like “category/design” “category/construction”, etc.

    Now my URL looks like this: index.php/projects/category/design/project-one

    I can’t specify the category=”{segment_3}” in the entry_linking tag pair because it’s not a number.

    Alternatively, when I use the {paginate} tag pair, the url ends up looking like index.php/projects/category/design/P1 because there’s no way to format the {auto_path} so that it displays a URL_TITLE instead of “P1” “P2” etc.

    I don’t see why Expression Engine lets me set a Category URL Indicator to override C1, C2, etc but not a Page URL Title option to override P1, P2, etc.

    Am I screwed?

  • #4 / Dec 20, 2011 1:34pm

    tidy

    196 posts

    I don’t think you’re screwed Matyus 😊

    I’m actually doing previous/next paging by category in a site I’m building.

    If you use Low’s excellent seg2cat add-on, you can map the category url in your segment to a category id which you can then use as a parameter in your next and previous entry tags like so:

    {!--segment_n_category_id is the low seg2cat add-on bit, match n to the url segment that has your category url in it to get the id--}
    {exp:channel:next_entry channel="projects" category="{segment_3_category_id}"}
    {!-- the path below should be to your single entry template, the project url title will be automatically added --}
    <a href="http://{path=projects/project}">next project</a>
    {/exp:channel:next_entry}
  • #5 / Dec 20, 2011 4:03pm

    matyus

    6 posts

    So if I’m understanding you correctly, the url will end up being something like index.php/projects/project-one/design instead of index.php/projects/design/project-one? How do you include that third segment into the path?

  • #6 / Dec 20, 2011 4:36pm

    tidy

    196 posts

    Well there may be multiple URL approaches. I tend to not have the category in the URL for single entry pages and just have one URL per entry of the form templategroup/template/URL_title
    Is there a reason you need to have the category in the URL for single entry pages?
    If you do, you can just add an extra segment to the end of the URL e.g

    href="{path='template group/template'}/{segment_3}"

    if segment 3 is your category URL title that should produce templategroup/template/URL_title/category format urls

  • #7 / Dec 20, 2011 4:50pm

    matyus

    6 posts

    I need to be able to limit the prev/next feature to the current category, relative to the project. Semantically speaking, index.php/projects/design/project-one makes sense to me, rather than index.php/projects/project-one/design. Keeping the category in the URL makes it easier for someone to navigate the URL themselves, if they delete the last segment themselves I’d rather have it be index.php/projects/design than index.php/projects/project-one because then it could potentially show them a list of projects in Design or at least bring them to the first entry in the Design category…

    Essentially what I want is for the {paginate} tag pair to generate the {auto_path} URL as the url_title of the next/previous entries and not “/P1” “/P0” because I need to limit the pagination to the current category… but P0 and P1 don’t make any sense.

    I’ve been trying to work it out with the seg2cat add-on but since I can’t have projects/design/project-one, I don’t think it’s going to work out for me. I think I may end up having to hardcode segment_2 for each category.

  • #8 / Dec 20, 2011 5:22pm

    tidy

    196 posts

    Think we are talking about different things. I’m not talking about using the paginate pair. instead, I have used the exp:channel:next_entry and previous equivalent tags. These go outside the channel entries tag. Using the path variable in this tag gives you a friendly URL of the form group/template/title.

    One part I had forgotten about was that my site single entry urls have the category appended to them which is how I can then use the seg2cat category id as the category parameter in the next_entry and previous tags which ensures that the next and previous links go to entries in the same category. So sorry for any confusion caused about that!

    If you do not want to include the category in the single entry URL (and it’s generally preferable not to to avoid duplicate urls if entries have multiple categories) then the category id is not readily available to plug into the next_entry tag, but there is probably an add-on for getting the category id of an entry outside a channel entries tag.

  • #9 / Dec 20, 2011 5:34pm

    matyus

    6 posts

    I haven’t actually been using or talking about the {paginate} tag pair, I was just trying to illustrate that I wanted the exp:channel:next_entry/exp:channel:prev_entry feature to emulate {paginate} except instead of “P1” “P2”, the URL would show the url_title.

    Your entry title_urls prefixed with the category name? Is that something you can specify in the EE preferences or do you need an add-on for that? It sounds like you’d need to have written some kind of segment parser in PHP for that?

  • #10 / Dec 21, 2011 6:11am

    tidy

    196 posts

    The code I’m using to do this is very simple - I’m obviously not getting that across though! 😊
    I’m sure there are other approaches and hopefully someone else can chip in on this, but as a last attempt, here is the full code I am using for next and previous nav within a category with friendly url titles which hopefully may help:

    My category list page is at say projects/category/design. I link to the entries in that template as follows:

    <a href="http://{title_permalink=projects/project}/{segment_3}">{title}</a>

    This gives me a single entry URL like projects/project/project-name/design.

    Then on the single entry template, here is the code for the next and previous nav.
    The segment_4_category_id bit is the seg2cat add-on, but everything else is core EE code.

    {exp:channel:next_entry channel="projects" category="{segment_4_category_id}"}
    <a href="http://{path=projects/project}/{segment_4}class=back">previous project</a>
    {/exp:channel:next_entry}
    
    {exp:channel:prev_entry channel="projects" category="{segment_4_category_id}"}
    <a href="http://{path=projects/project}/{segment_4}class=more">next project</a>
    {/exp:channel:prev_entry}

    This single entry code produces the following HTML:

    <a href="http://mydomain.com/projects/project/next-project-name/designclass=more">next project</a>
    <a href="http://mydomain.com/projects/project/previous-project-name/designclass=back">previous project</a>

    Perhaps, try using these code samples in your templates just to get the next and previous nav working. Then I think the only thing you would like to improve on is to try and have the category as an earlier segment of the single entry URL, which is a smaller issue and someone else may be able to advise on how to do that, but at least you should have the functionality working which is the main thing.

  • #11 / Dec 28, 2011 12:15pm

    matyus

    6 posts

    Thank you for your help!

    I decided to build a template for each project category, that way navigating to the Design category (index.php/projects/design/project-one) would preserve single entry mode for “project-one”.

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

ExpressionEngine News!

#eecms, #events, #releases