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.

Customising URL to single blog post

October 03, 2011 9:46am

Subscribe [4]
  • #1 / Oct 03, 2011 9:46am

    Steve Holland

    7 posts

    Hi,

    I currently have my channels / templates set up for a blog, so that I have the following working urls (lists posts):

    http://example.com/posts
    http://example.com/posts/category/a-category
    http://example.com/posts/2011/
    http://example.com/posts/2011/02
    http://example.com/posts/2011/02/01

    These all work fine using the ‘index’ template with all the filtering working nicely out of the box.

    What I’m struggling to do is get the single post page working (different template called ‘post’). Currently I have it working at:

    http://example.com/posts/post/a-blog-post-title

    What I’d like to do is change it so this is the url:

    http://example.com/posts/2011/02/a-blog-post-title
    or,
    http://example.com/posts/2011/02/01/a-blog-post-title

    Is there a way to do this by configuring something or will I need to pop some code in to use the different segments? I’m fine doing it either way, I was just worried I’m about to start reinventing the wheel and there is a simple way to achieve this.

    Thanks in advance,
    Steve

  • #2 / Oct 03, 2011 10:04am

    Matt:P

    277 posts

    Hi Steve

    Is it an option for you to create another Template Group called /post/ (singular) and use the index template within that to render a single article?

  • #3 / Oct 03, 2011 10:13am

    Steve Holland

    7 posts

    Indeed it is! That’s saved me a whole heap of time. I had a feeling I was going about it in a totally long-winded way, glad I checked. Much appreciated.

    Many thanks,
    Steve

  • #4 / Oct 03, 2011 10:29am

    Steve Holland

    7 posts

    Sorry, I was a bit quick with the previous reply.

    Unfortunately it still filters the posts by the dates, so if I have multiple posts on the same day, it’ll pick the first post, regardless of what the post-title is. So I’m a step in the right direction, it’s using the correct template now.

    Thanks for the quick response though.

    Steve

  • #5 / Oct 03, 2011 10:33am

    Matt:P

    277 posts

    Hi Steve

    No trouble, welcome to the forums mate

    Am I correct in understanding you…. The template: http://example.com/post/a-blog-post-title is displaying more than one entry? i.e. it’s not necessarily displaying the Entry with the title “a blog post title” ???

    Matt

  • #6 / Oct 03, 2011 10:35am

    Boyink!

    5011 posts

    You’re working a bit against how EE wants to natively use URL’s to know what entries to pull.  EE knows how to do things natively by URL title or date parameters, but not both at the same time.

    In order to do that you’ll need to make sure the channel:entries tag on the single-entry template is set to “dynamic=no” so that EE stops working automatically with the URL.

    Then try a parameter of “url_title=”{last_segment}” so EE knows what is the entry you are actually looking to get.

  • #7 / Oct 03, 2011 10:37am

    Steve Holland

    7 posts

    Solved it!

    Looks like I need to specify the ‘url_title’ parameter e.g.

    {exp:channel:entries channel="posts" limit="1" url_title="{segment_4}”}

    So for my urls it would be:

    url_title=”{segment_4}” for /post/2011/02/the-post-title, or
    url_title=”{segment_5}” for /post/2011/02/05/the-post-title

    That all seems to work dandy. I knew there would be a straightforward way of doing it.

    Steve

  • #8 / Oct 03, 2011 10:39am

    Steve Holland

    7 posts

    Thanks Boyink! I was typing at the same time you replied. That works brilliantly.

    Steve

  • #9 / Oct 03, 2011 10:42am

    Matt:P

    277 posts

    Nice one Mike, thanks Sir.

    Well done Steve!

  • #10 / Oct 03, 2011 6:11pm

    Sue Crocker

    26054 posts

    Glad you have a solution, and thanks Matt and Mike for assisting.

    Feel free to start a new thread if you have any more questions.

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

ExpressionEngine News!

#eecms, #events, #releases