Fuel Blog Module: How to change url to display month name rather than number
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
https://github.com/daylightstudio/FUEL-CMS-Blog-Module/commit/187e897d23c966d38d7fb4c6bd4531722088714e
next_post: post_date asc, id asc
prev_post: post_date desc, id desc
It was missing the "asc" and "desc" after post_date.
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
$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
$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.
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.
$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.
$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