default userpic

Matching tags across top categories for cross links

Vote 0 Votes

We have a cross links template that lists the entries with the same tag as the current entry. Thing is, there are 6 top level categories and all the entries within a given category with a matching tag cross link just fine. But say we had the tag "bacon" in entries in 2 different top level categories, they will not cross link to each other. We were expecting a global tag match in the blog, but it seems we are getting only tag matches within a top level category. Our code:

<mt:Entries lastn="1">
<mt:EntryIfTagged>
   <mt:EntryID setvar="current_entry">
   <mt:SetVarBlock name="related_tags">
       <mt:EntryTags include_private="1" glue=" OR ">
           <mt:TagName>
       </mt:EntryTags>
   </mt:SetVarBlock>
   <mt:Var name="related_tags" strip_linefeeds="1" setvar="related_tags">
</mt:EntryIfTagged>
</mt:Entries>
<mt:If name="related_tags"> 
   <mt:SetVarBlock name="list_items">
      <mt:Entries tags="$related_tags" limit="15" include_subcategories="1">
         <mt:Unless tag="EntryID" eq="$current_entry">
            <mt:If tag="EntryDataSearch_url">
            <li><a href="<mt:EntryDataSearch_url>"><mt:EntryTitle></a></li>
            <mt:Else>
            <li><a href="<mt:EntryLink>"><mt:EntryTitle></a></li>
            </mt:If>
            <$mt:Var name="items_found" value="1"$>
         </mt:Unless>
      </mt:Entries>
   </mt:SetVarBlock>
   <mt:If name="items_found">
   <div class="xnav">
      <h2>Cross Links</h2>
      <ul>
         <$mt:Var name="list_items"$>
      </ul>
   </div>
   <script type="text/javascript" charset="utf-8">
    $(document).ready(function  () {
    xLinkColors();
    });
   </script>
   </mt:If>
</mt:If>

Since we were using include_subcategories I figured maybe it's category based. So I grabbed a category listing and used Category to specifically point to each category in my Entries:

<mt:Entries lastn="1">
<mt:EntryIfTagged>
   <mt:EntryID setvar="current_entry">
   <mt:SetVarBlock name="related_tags">
       <mt:EntryTags include_private="1" glue=" OR ">
           <mt:TagName>
       </mt:EntryTags>
   </mt:SetVarBlock>
   <mt:Var name="related_tags" strip_linefeeds="1" setvar="related_tags">
</mt:EntryIfTagged>
</mt:Entries>
<!-- cross category debug -->
<mt:SetVarBlock name="topcats">
<mt:Categories glue=" AND " strip_linefeeds="1">
   #<$mt:CategoryID$>
</mt:Categories>
</mt:SetVarBlock>
<!-- end cross category debug -->
<mt:If name="related_tags"> 
   <mt:SetVarBlock name="list_items">
      <mt:Entries tags="$related_tags" category="$topcats" limit="15">
         <mt:Unless tag="EntryID" eq="$current_entry">
            <mt:If tag="EntryDataSearch_url">
            <li><a href="<mt:EntryDataSearch_url>"><mt:EntryTitle></a></li>
            <mt:Else>
            <li><a href="<mt:EntryLink>"><mt:EntryTitle></a></li>
            </mt:If>
            <$mt:Var name="items_found" value="1"$>
         </mt:Unless>
      </mt:Entries>
   </mt:SetVarBlock>
   <mt:If name="items_found">
   <div class="xnav">
      <h2>Cross Links</h2>
      <ul>
         <$mt:Var name="list_items"$>
      </ul>
   </div>
   <script type="text/javascript" charset="utf-8">
    $(document).ready(function  () {
    xLinkColors();
    });
   </script>
   </mt:If>
</mt:If>

That resulted in this error:

An error occurred publishing category '2': Publish error in template 'Landing Page': Error in <mtInclude> tag: error in module Cross Links - Landing Page: Publish error in template 'Cross Links - Landing Page': Error in <mtIf> tag: Error in <mtSetVarBlock> tag: Error in <mtEntries> tag: You have an error in your 'category' attribute: #46 AND #47 AND #21 AND #31 AND #2 AND #98 AND #105 AND #32 AND #51 AND #25 AND #26 AND #24 AND #7 AND #1 AND #29 AND #108 AND #27 AND #35 AND #34 AND #33 AND #22 AND #110 AND #6 AND #4 AND #53 AND #106 AND #42 AND #36 AND #49 AND #45 AND #5 AND #37 AND #48 AND #44 AND #38 AND #28 AND #3 AND #40 AND #39 AND #41 AND #50 AND #43 AND #9 AND #107 AND #52 AND #8

I researched and came to believe that was the character bug from MT 4.2 so I upgraded to MT 4.32. That didn't fix my problem. I had also tried this with CategoryBasename instead of ID's to see if it was the #'s holding me up but no dice. I had also tried a similar approach where I kept include_subcategories and grabbed just the top level categories, but that yielded the same results.

So, is there a way I can get this template to match tags for entries that are not living under the same top level category as the current entry? I could do the cross linking manually with a widget set but that would be a big re-arch and a re-launch so I'd like to get this template working if I can.

Reported on Movable Type 4.3

1 Reply

| Add a Reply
  • If you check the docu for mt:Entries you will see that you need to use the category names instead of basenames (or ids).
    So when you are building the topcats variable use the
    mt:CategoryLabel tag.
    There were some problems in case of Category Names containing spaces so you might need to adjust your categories to not to contain spaces.

Add a Reply

If you need to share template code, replace all the "<" signs with "&lt;" or use this utility.

Forum Groups

1773 6162

Last Topic: Excluding categories from blog by kholechek on Feb 9, 2012

86 302

Last Topic: website entries by masoud on Oct 26, 2011

1429 5077

Last Topic: What apocalypse hit this community in the middle of 2011? by 75th on Feb 10, 2012

695 2910

Last Topic: Insert Image / File Fails by Russ Miller on Feb 10, 2012

84 291

Last Topic: How to have some other characters in entry basename automatically written by Afshin Haghighatnia on Dec 22, 2011

173 737

Last Topic: About the MT version stated in HTML source by Alex E. Schneider on Feb 7, 2012

190 567

Last Topic: Analytics Reporting by michael webster on Feb 5, 2012

48 210

Last Topic: An idea and also a request by Afshin Haghighatnia on Jun 29, 2011

64 246

Last Topic: jQuery in MT 5.1 still at 1.4 - why? by perlmonkey on May 25, 2011

code.sixapart.com

137 478

Last Topic: Getting a thumbnail with xpath by Peter on Mar 13, 2011

222 720

Last Topic: Custom Field for Asset Not Appearing by android on Feb 9, 2012