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.

Force template URL to act as single entry?

August 01, 2009 9:34am

Subscribe [4]
  • #1 / Aug 01, 2009 9:34am

    somwicked

    26 posts

    Ok, lets see if I can explain this.

    I’m trying to set a template, i.e. blog, to act as a single entry page so I can use the prev_entry and next_entry tags to move between posts.

    In other words, I have the blog template created and it pulls the latest entry just fine. However, when the template is called directly, the URL is /blog/, not /blog/post_title as a single entry page would be. Since this is not treated as a single entry page, the prev_entry and next_entry tags do not work. I am trying to figure out a conditional or some other way of forcing this. Maybe even a redirect. No dice yet.

    I am not looking to actually display the URL as /blog/post_title - just to act like it - although that would work if there was a way to do it.

    I’ve tried using pagination but that throws me into the loop of /blog/p1, /blog/p2 and so on .. not what I’m looking for.

    This is not an issue linking to the blog template from another template since I can set the link to include the title and the prev_entry/next_entry tags work as expected. Its just that first time if someone calls the blog template directly that I’m stumbling on.

    I would think has to be some kinda voodoo that will get this working. Any ideas?

  • #2 / Aug 01, 2009 10:03am

    somwicked

    26 posts

    Duh, got it. Must have been a long night.

    {if segment_2 ==''}
    {exp:weblog:entries weblog="blog" orderby="date" limit="1"}
    {redirect='/blog/{title}'}
    {/exp:weblog:entries}
    
    {if:else}
    
    {exp:weblog:entries weblog="blog" orderby="date" sort="desc" limit="1"}
    <strong>{title}</strong>
    {summary}
    {body}
    {/exp:weblog:entries}
    
    {exp:weblog:prev_entry}
    Prev entry: <a href="http://{path=blog}">{title}</a>
    {/exp:weblog:prev_entry}
    
    {exp:weblog:next_entry}
    Next entry: <a href="http://{path=blog}">{title}</a>
    {/exp:weblog:next_entry}
    {/if}
  • #3 / Aug 01, 2009 10:39am

    somwicked

    26 posts

    And .. if anyone else finds it useful .. I should point out a correction.

    I’m actually using the url_title field and not the title field to generate the redirect.

    {exp:weblog:entries weblog="blog" orderby="date" limit="1"}
    {redirect='/blog/{url_title}'}
    {/exp:weblog:entries}
  • #4 / Aug 02, 2009 10:20pm

    KomodoDave

    39 posts

    Have you got a comment submission form working somewhere, somwicked? Could you post the code for me if so? Despite being at the sort of level where I write plugins for EE, I can’t get the comment submission form to display, even though comments are allowed in CP. I pass all the parameters it requires: weblog, entry_id, preview, url_title. It’s doing my head in, so I’m hoping seeing an example would help me identify what’s going on!

  • #5 / Feb 02, 2010 3:28pm

    kenny2

    90 posts

    Nice tip, I was wondering how to do this with out using pagination which would have left my uri’s ending in /P1 etc

    And .. if anyone else finds it useful .. I should point out a correction.

    I’m actually using the url_title field and not the title field to generate the redirect.

    {exp:weblog:entries weblog="blog" orderby="date" limit="1"}
    {redirect='/blog/{url_title}'}
    {/exp:weblog:entries}
  • #6 / Mar 06, 2010 9:21am

    gazaston

    128 posts

    When I try this I get a warning: Too many HTTP redirects.

    Any idea why that is happening?

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

ExpressionEngine News!

#eecms, #events, #releases