Year, Month and URL Title in Weblog URL Structure / Permalink
Posted: 04 March 2009 06:05 AM   [ Ignore ]  
Summer Student
Total Posts:  16
Joined  08-09-2006

Hi,

I would like to standardise the URLs for my permalinks to follow the style adopted by Blogger, WordPress, BBC Blogs whereby they use.

http://www.yourdomain.com/blog/2009/02/entry_title/

I read a forum post suggesting this is possible but needs a lot of tweaks.

It would be great to know how to do this as I think the URL structure is really neat.

If anyone has any TAG examples that would be amazing.

Moved to HowTo by Moderator

Profile
 
 
Posted: 04 March 2009 09:08 AM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  20899
Joined  04-29-2002

Hi, domw. This is more of a HowTo kind of question. I’m going to move this thread there for additional community involvement.

 Signature 

EE 2.01PB - 2.x Bug Tracker | Docs | Upgrade from 1.x to 2.x | Build Update Instructions | 1.6.x Update Info

Most recent 2.x version: Build 20100215
Don’t forget to upgrade MSM and Forum as needed!

Profile
MSG
 
 
Posted: 03 July 2009 11:31 AM   [ Ignore ]   [ # 2 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  157
Joined  08-13-2007

This is also something I’m interested in, so +1.

Profile
 
 
Posted: 03 July 2009 02:11 PM   [ Ignore ]   [ # 3 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  3487
Joined  08-28-2003

Has there been a Feature Request on this?

I would love to be able to have EE’s URL structure adhere to some kind of default standard in addition to the current template_group/template/entry_name structure.

I don’t know as though there is a uniform URL structure standard, though the one used in WordPress comes to mind (year/month/date/entry_name).

Is that possible with EE?

 Signature 

grrramps
———
Honolulu, HI
———
Home | Old Hobby | New Hobby | Newer Hobby | Another update via CSS

Profile
 
 
Posted: 03 July 2009 02:19 PM   [ Ignore ]   [ # 4 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  157
Joined  08-13-2007

After some searching, I’ll probably try this technique.

Profile
 
 
Posted: 07 July 2009 07:18 PM   [ Ignore ]   [ # 5 ]  
Lab Assistant
RankRank
Total Posts:  286
Joined  09-28-2002

1. Remove index.php from the URL. (I usually use the “File and Directory Check” method.)

2. Make a new template group with “blog” as the Template Group Name. If you use the index template you don’t need “index” in the URLs.

3. Check the URL Segment Variables. Segment 2 should be the year, segment 3 should be the month, and segment 4 should be the URL title. Here’s some code to test:

Segment 1: {segment_1}<br />
Segment 2: {segment_2}<br />
Segment 3: {segment_3}<br />
Segment 4: {segment_4}<br />

4. Use conditional variables to (a) show the most recent entries (or whatever) if there isn’t a year, month, and URL title in the URL, (b) show the yearly archives if there’s a year but not a month, (c) show the monthly archives if there’s a month but not a URL title, (d) display the weblog entry if segment 4 is a valid URL title, and (e) redirect to the 404 message if segment 4 isn’t a valid URL title.

{if segment_2 == ''}
{
!-- show the most recent entries --}
{
/if}

{if segment_2
!= '' && segment_3 == ''}
{
!-- show the yearly archive --}
{
/if}

{if segment_2
!= '' && segment_3 != '' && segment_4 == ''}
{
!-- show the monthly archive --}
{
/if}

{if segment_4
!= ''}
{exp
:weblog:entries weblog="blog" url_title="{segment_4}" require_entry="yes" limit="1" dynamic="off"}
{title}
{if no_results}
{redirect
="404"}
{
/if}
{
/exp:weblog:entries}
{
/if}

The exp:weblog:entries tag uses the url_title and require_entry parameters to display the entry, and the if no_results conditional variable to redirect to the 404 message. (You could also pass the year and month as parameters if you wanted to require that the year and month in the URL match the entry.)

Edit: added dynamic=“off” parameter.

I’d use embedded templates to keep things simple. You might need to disable strict URLs

Finally, build your links to the blog posts:

{exp:weblog:entries weblog="blog"}
{if count
== '1'}<ul>{/if}
<li>[a href="/blog/{entry_date format="%Y/%m"}/{url_title}/"]{title}[/a]</li>
{if count == total_results}</ul>{/if}
{
/exp:weblog:entries}

(Note: I changed angled brackets to square ones so the code would display accurately.)

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1743, on December 02, 2009 03:47 PM
Total Registered Members: 119807 Total Logged-in Users: 49
Total Topics: 125952 Total Anonymous Users: 27
Total Replies: 662638 Total Guests: 341
Total Posts: 788590    
Members ( View Memberlist )