Breadcrumbs

From MovableType

Contents

Breadcrumbs for pages and folders

On an MT4+ powered site that has pages and folders, the following code delivers a completely effective breadcrumb navigation trail:

<a href="<MTBlogURL>">Home</a> »
<MTParentFolders> 
  <a href="<MTBlogURL><MTFolderPath>"><MTFolderLabel></a> »
</MTParentFolders>
<strong><MTPageTitle></strong>


Sidebar listing of folders/pages

Error in MT Template Tag Reference Appendix Documentation for SubFoldersRecurse

The MT4 documentation on the <MTSubFoldersRecurse> tag has an error in the code:

<MTTopLevelFolders>
  <MTSubFolderIsFirst><ul></MTSubFolderIsFirst>
    <MTIfNonZero tag="MTFolderCount">
        <li><a href="<$MTFolderArchiveLink$>"
        title="<$MTFolderDescription$>"><MTFolderLabel></a>
    <MTElse>
        <li><MTFolderLabel>
    </MTElse>
    </MTIfNonZero>
    <mt:SubFolderRecurse>
    </li>
<MTSubFolderIsLast></ul></MTSubFolderIsLast>
</MTTopLevelFolders>

There's simply no such thing as <MTSubFolderIsFirst>, <MTSubFolderIsLast> and <MTFolderArchiveLink> (duh?) tags.

Recipe 1: List all pages and folders in the system

This will list all pages (contained in a folder) and folders across the weblog.

<ul>
<MTTopLevelFolders>
    <li><a href="<MTFolderPath>"><MTFolderLabel></a></li>
    <ul>
    <MTPages>
    <li><a href="<MTPagePermalink>"><MTPageTitle></a></li>
    </MTPages>
    </ul>
    <ul><MTSubFolderRecurse></ul>
</MTTopLevelFolders>
</ul>

Recipe 2: List only folders, not pages

This lists only the folders and sub-folders, but no pages.

<ul>
<MTTopLevelFolders>
    <li><a href="<MTFolderPath>"><MTFolderLabel></a></li>
    <ul>
    </ul>
    <ul><MTSubFolderRecurse></ul>
</MTTopLevelFolders>
</ul>

Recipe 3: List only top level folders

This lists only the top level folders, no sub-folders or pages.

<ul>
<MTToplevelFolders>
<li><a href="<MTBlogURL><MTFolderBasename>/index.php"><MTFolderLabel></a></li>
</MTToplevelFolders>
</ul>

Recipe 4: List all pages and sub-folders in the present folder

Conceivably useful in a sidebar on every page, this lists all the pages and sub-folders in the present page folder. Note that it also lists the current page.

<ul>
<MTPageFolder>
  <MTPages sort_by="date">
     <li><a href="./<MTPageBasename>.php" id="<MTPageBasename>"><MTPageTitle></a></li>
  </MTPages>
  <MTSubFolders>
   <li><a href="<MTBlogURL><MTFolderPath>/index.php"><MTFolderLabel>  »</a>
      <ul>
        <MTPages><li><a href="<MTPagePermalink>"><MTPageTitle></a></li></MTPages>
        <MTSubFolderRecurse> 
    </ul>
     </li>
  </MTSubFolders>
</MTPageFolder>
</ul>

Recipe 4.5: List all pages except the current page and sub-folders in the present folder

This works very well. It eliminates the current page from the listing, and lists all the other pages, sub-folders and sub-folder pages in the present page folder.

<ul>
<mt:setvarblock name="curpage"><mt:pageid></mt:setvarblock>
<MTPageFolder>
  <MTPages sort_by="title" sort_order="ascend">
  <mt:setvarblock name="listpage"><mt:pageid /></mt:setvarblock>
  	<mt:unless name="listpage" eq="$curpage">
     <li><a href="./<MTPageBasename>.php" id="<MTPageBasename>"><MTPageTitle></a></li>
     </mt:unless>
  </MTPages>
  <MTSubFolders>
   <li><a href="<MTBlogURL><MTFolderPath>/index.php"><MTFolderLabel>  »</a>
      <ul>
        <MTPages><li><a href="<MTPagePermalink>"><MTPageTitle></a></li></MTPages>
        <MTSubFolderRecurse> 
    </ul>
     </li>
  </MTSubFolders>
</MTPageFolder>
</ul>

CREDITS

Almost all of this is from caribou's post at the sixapart forums.

--Gautam Patel 22:03, 15 December 2007 (PST)