Blog module: remove date from url in posts

edited August 2015 in Modules


  • edited 2:20AM
    You can access a blog post also at blog/id/{id}, however, the generated URL is built into the module with the blog_post_model::get_url method (around line 608 in the fuel/modules/blog/models/blog_posts_model.php file). So to change it, you would need to change that method.
  • edited 2:20AM

    I changed this line $url = $year.'/'.$month.'/'.$day.'/'.$this->slug;

    to this $url = $this->slug;

    Now, posts have the desired href: but now, when i click on one of the post, it don't show the clicked post but the same page with all posts.

  • edited 2:20AM
    You will probably need to change the main fuel/modules/blog/controller/blog.php file since it looks for those URI parameters to query the database for the post.
  • edited 2:20AM
    how to change blog.php can u give me code for that.
  • edited July 2018

    Well, I have figured this out and wanted to help you guys.

    You need to do little change on two files:

    1) In fuel/modules/blog/models/blog_posts_model.php
    Find the get_url method and change
    $url = $year.'/'.$month.'/'.$day.'/'.$this->slug;
    $url = $this->slug;

    2) Now, open fuel/modules/blog/controller/blog.php
    near line no. 20 just add this below code after $view_by = 'page';

    // custom code for getting blog post by slug ( without date )

    if ($this->fuel->blog->uri_segment(2) && $this->fuel->blog->uri_segment(3)=="")
    $view_by = 'slug';
    $slug = $this->fuel->blog->uri_segment(2);
    if ($view_by == 'slug')
    return $this->post($slug, $year, $month, $day);
    //end of custom code for getting blog post by slug ( without date )

    That's it.

    It took time for to figure this out but finally i did it.

    I hope this will be helpful.

Sign In or Register to comment.