Fuel Blog Module: How to change url to display month name rather than number

edited November 2013 in Modules
Hi

Firstly just wanted to say how much I am enjoying working with fuelcms. It really is easy to work with.

While creating my own site, I wanted to implement a breadcrumb for the blog in order to aid user friendliness. Part of this required the need to display the month within the url as a short textual month rather than a numeric month.

E.g.
Numeric = /index.php/blog/2013/11/01
Textual = /index.php/blog/2013/Nov/01

I was unable to find a method via the forums, so I thought I would figure it out myself and share the methodology here.

File: /blog/models/blog_posts_model.php
change
$month = date('m', strtotime($this->date_added));
to
$month = date('M', strtotime($this->date_added));

File: /blog/libraries/fuel_blog.php
change
$key = date('Y/m', strtotime($post->date_added));
to
$key = date('Y/M', strtotime($post->date_added));

Alternatively, you could use F to display the full textual month e.g. November

Hope this helps someone else in the future.

Mark

Comments

  • edited 9:28AM
    Nice... thanks for sharing. As an FYI, I just posted a fix earlier today to the blog module to fix the next_post and prev_post:
    https://github.com/daylightstudio/FUEL-CMS-Blog-Module/commit/187e897d23c966d38d7fb4c6bd4531722088714e
  • edited 9:28AM
    You're welcome. And thanks for the FYI. Btw, what was the problem with the next_post and prev_post? I hadn't spotted that one.
  • edited 9:28AM
    The sort order should have been the following:
    next_post: post_date asc, id asc
    prev_post: post_date desc, id desc

    It was missing the "asc" and "desc" after post_date.
  • edited 9:28AM
    Hi Admin

    I upgraded to V1 today, which went relatively smoothly. However when I updated /blog/libraries/fuel_blog.php with $key = date('Y/F', strtotime($post->date_added)); in order to change the archive url to use a full textual month, it causes the href label to display the previous month. Using 'm' or 'M' is works fine and the label remains the same as the month within the url, but not for 'F'.

    Any ideas why?

    Thanks
  • edited 9:28AM
    So you are saying something like the following is happening (say the month is December)?
    $key = date('Y/m', strtotime($post->date_added)); // 2013/12
    $key = date('Y/M', strtotime($post->date_added)); // 2013/Dec
    $key = date('Y/F', strtotime($post->date_added)); // 2013/November
  • edited 9:28AM
    Sorry, should have gave an example.

    $key = date('Y/m', strtotime($post->date_added));
    url = /blog/2013/12 correct
    placeholder = December 2013 (1) correct
    $key = date('Y/M', strtotime($post->date_added));
    url = /blog/2013/Dec correct
    placeholder = December 2013 (1) correct
    $key = date('Y/F', strtotime($post->date_added));
    url = /blog/2013/December correct
    placeholder = November 2013 (1) WRONG

    When I say placeholder, I mean the hyperlink text inbetween the 'a' tags. Not too sure what it is meant to be called.
  • edited 9:28AM
    It also seems to work if you do "y/F". You'll need to modify the code in the fuel/modules/blog/views/themes/{yourtheme}/_blocks/archives.php file where it calculates the $month_str value.
  • edited 9:28AM
    Thanks for that. I managed to reformat the links to display correctly.

    The next thing I have noticed, is that in order to filter the archive by month that I need to parse month number through the url
    /index.php/blog/2013/12
    By using
    /index.php/blog/2013/december
    it displays all posts regardless of month.

    Any pointers on where I need to modify to allow full textual months to be recognised.
  • edited 9:28AM
    You would need to look in the main blog controller at the very top of the _remap function where it says:
    $year = ($this->uri->rsegment(2) != 'index') ? (int) $this->uri->rsegment(2) : NULL;
    Note that it casts it to an int value. I'm guessing that's the problem.
  • edited 9:28AM
    Thanks Admin, that was the problem. I found that if I changed
    $month = (int) $this->uri->rsegment(3);
    to this
    $month = (int) date('m', strtotime($this->uri->rsegment(3)));
    then I could use
    /blog/2013/december
    /blog/2013/dec
Sign In or Register to comment.