SportsterPaul

Making breadcrumbs

Vote 0 Votes

I set up a blog to be date-based, like a classic conventional blog. I read how to make breadcrumbs based on category--
<a href="http://www.xxxx.com">xxxx Company</a> »
<MTEntryCategories>
<a href="<$mt:BlogURL$>"><$mt:BlogName$></a> »
<MTParentCategories glue = " » "><a href="<$MTCategoryArchiveLink$>"><$MTCategoryLabel$></a></MTParentCategories>
</MTEntryCategories> »
<$mt:EntryTitle$>

This works well, especially since I only had two levels of categories. What I also wanted was a second breadcrumb based on the date. I was disappointed to learn Movable Type considers a folder not to be where the permalink is, but the category. My site structure was:
http://www.xxxx.com/Journal/2015/03/basename/index.html

So it didn't take long to figure out I could make a date-based breadcrumb using:

<a href="http://www.xxxx.com">xxxx Company</a> »
<a href="<$mt:BlogURL$>"><$mt:BlogName$></a> »
<a href="<mt:ArchiveLink trim_to="33">"><mt:EntryDate format="%Y"></a> »
<a href="<$mt:EntryLink type="Monthly"$>"><$mt:EntryDate format="%m"$></a> »
<$mt:EntryTitle$>


Where 33 counted from left to the right to yield the desired abbreviated URL. But see, what if I changed the site to be secure and use https://? Then the counting 33 from the left would break things since there was one more character. It look a lot of messing with regex-replace, but I finally got the two URLs I needed. So given the permalink:
http://www.domain.com/Journal/2015/03/14th-Saturday/
you can use
<mt:ArchiveLink regex_replace="/([^/]+)\/([^/]+)\/?$/","">
to get
http://www.domain.com/Journal/2015/
and
<mt:ArchiveLink regex_replace="/([^/]+)\/?$/","">
to get
http://www.domain.com/Journal/2015/03/

Working back from the right-side end seems like a better way to do things, and I feel pretty confident with the code. I used the online regex evaluator: http://regexr.com/ but it took two hours to learn you hover over the gray trailing slash to add a "g" or a "m" or an "i" to the expression. It does not matter in this case, but nice to know. Don't make my mistake, spending 5 hours figuring out how to match to http://www.domain.com/Journal/2015/03/ using ^(?:[^/]*\/){6}([^/]*?) You want to match to what you want to throw away, the end part you strip off, since that is what you can replace with null "". There are examples of finding an inverse to an expression but it looks really ugly. I hope this helps you deal with regex and date-based breadcrumbs.

5 Replies

| Add a Reply

Add a Reply

Forum Groups

Movable Type

1 12

Last Topic: Uploading Assets in Entry/Page by Michael Webster on Mar 2, 2015

3 9

Last Topic: Making breadcrumbs by SportsterPaul on May 24, 2017

Documentation

Be the first to post a topic in this forum

Performance

Be the first to post a topic in this forum

Pricing and Licensing

Be the first to post a topic in this forum

Product Ideas

Be the first to post a topic in this forum