Blog module: remove date from url in posts

edited August 2015 in Modules

Comments

  • edited 4:25PM
    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 4:25PM
    Thanks!

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

    to this $url = $this->slug;

    Now, posts have the desired href: http://www.mywebsite.com/blog/my-post 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 4:25PM
    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 4:25PM
    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;
    to
    $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.
    Thanks!

Sign In or Register to comment.