Publishing Related Entries Lists (That Stay Updated) with Movable Type

| 19 Comments | No TrackBacks |
Having a list of related, similar entries below each entry in your blog is a good way to entice your readers to stay on your site longer.  But how do you generate such a list, making sure only the most relevant entries are listed?  And how can such a list be kept up to date, especially on older entries? 
There is the classical way: get the main category of the entry, and display a list of entries in the same category, using a code snippet like this below each entry:

<mt:categorylabel setvar="thecategory">
<mt:if name="thecategory>
<h1>Related entries:</h1>

<mt:entries category="$thecategorylabel">
...
</mt:entries>​​​​​​​​​​​​​​​​​
</mt:if>

A little more sophisticated is to use the tags of the current entry as a basis for loading other entries:

<mt:setvarblock name="searchoptions"><mt:entrytags glue=" OR "><mt:tagname></mt:entrytags></mt:setvarblock>
<mt:if name="searchoptions">
<h1>Related entries:</h1>
<mt:entries category="$searchoptions">
...
</mt:entries>
</mt:if>

If you use many tags on your site, the above solution might return many matches based on only one or two (very frequent or common) tags.  To avoid this, you could use following snippet, which actually counts the number of matching tags and displays the entries with the most matches:

<mt:entrytags><mt:tagname setvar="thetag"><mt:var name="tags{$thetag}" value="1"></mt:entrytags>
<mt:setvarblock name="searchoptions"><mt:entrytags glue=" OR "><mt:tagname></mt:entrytags></mt:setvarblock>

<mt:if name="searchoptions">
<h1>Related entries:</h1>

<mt:entryid setvar="thisentryid">
<mt:entries tags="$searchoptions"><mt:unless tag="entryid" eq="$thisentryid">
<mt:var name="matches" value="0">
<mt:entrytags><mt:tagname setvar="thetag"><mt:if name="tags{$thetag}"><mt:var name="matches" op="+" value="1" setvar="matches"></mt:if></mt:entrytags>
<mt:setvarblock name="theentry">
...
</mt:setvarblock>
<mt:var name="allentries{$theentry}" value="$matches">
</mt:unless></mt:entries>

<mt:loop name="allentries" sort_by="value numeric reverse">
<mt:unless name="__counter__" gt="5"><mt:var name="__key__"></mt:unless>
</mt:loop>
</mt:if>

A little explanation: in the first line, the 'tags' hash is filled with all the tags for the current entry.  The second line is similar to the previous code snippet, as are most of the following lines: we grab the tags of the current entry and select entries that share one or more of the same tags. Where things get interesting is inside the mt:entries loop.  A 'matches' variable is set to zero, and it is incremented by one each time one of the tags of the current entry is present in the tags hash containing the tags of the 'original' entry.  Finally, we store whatever we want to display of the current entry in the 'theentry' variable, and we use this variable as the key in the 'allentries' hash, with the number of matches as the value.

Finally, we loop over this hash, in reverse numerical order by value, meaning the entries with most matches come first.

This will give us a nice list of entries that share tags with the current entry, which is exactly what we need.

Only one problem remains: what if a newer entry is written that has many tags in common with one or more older entries?  How can we make sure these entries receive an update so their 'Related entries' list is brought up to date?  Republishing the entire blog is a possibility, but not really practical if you have a large blog.

A better way is to use Endevver's Related Entries plugin, which automatically republishes all entries that share a tag with an entry that is being saved or published. If you have many entries sharing similar tags it could still be a drain on resources, but it is better than doing a full republish!  And of course you can use background publishing.



No TrackBacks

TrackBack URL: http://www.movabletips.com/cgi-bin/mt/mt-tb.cgi/2206

19 Comments

First of all, a huge THANK YOU for support on Movable Type. I am one of addicted readers of your blog.

Could you tell me if there is a possibility to create a Page with the list of all entries which are tagged with some "example" Tag.
I am trying to create a navigation bar with 5 most important topics on my site (Site with 5 Blogs) and I started to create 5 index-Templates. But I can not create a list of all entries taggt with "example-Tag".

My goal is to create 5 static html index templates, which are listing:
Topic1.Html - entries with Tag1,
Topic2.Html - entries with Tag2,
Topic3.Html - entries with Tag3,
Topic4.Html - entries with Tag4 and
Topic5.Html5 - entries with Tag5.

Is that possible with MT5.2 ???

Do you have any suggestions for making this perform faster in a static publishing environment? Once the number of posts and tags gets high, it takes a painful amount of time to build pages that include this code.

The Clad Pittsburgh Steelers Jerseys nfl jerseys sale cheap dagh ring has its traditions in the small fishing village of the same name in Galway County. You will see from the 1920 ads below that the marketing methods used by cheapest nfl jerseys manufacturers way back then are still being used just as successfully today. I also asked him if I could

Acquire the best cheap jersey mens wallet kind of Totes Choosing the best k Cheap China Nfl Jerseys nfl j ind of developer purse for a person is collection in the past purchasing the program. Rodriguez, age 36,Nfl Jersey From China, a true entrepreneurial soul with an innovative mind and has over 15+ years of progressive experie

Getting secret surveillan Authentic Nba Jerseys Cheap n ce footage is easy, all one has to do is switch on the spy cheap jersey and video,Nba Basketball Jersey, audio recording takes place. If this form of aluminum combines with maltol, a sugar-like flavoring agent, the resulting aluminum compound is able to get through the bloo

Decaf C NFL Game Jersey Cheap nike nfl jersey sale outlet wholesale \(1864\) offeeCaffeine BenefitsCaffeine stimulates the nervous system, says the International Coffee Organization. Ensure that you have thoroughly screened the potential caregivers you will hire. Great display: Aside from conveniently displaying your mugs or cups, a cheap nhl jerseys tree can also be

The concert i NHL Custom Jersey Cheap nike nfl jersey sale outle tself took place in the city of Utrecht, less than thirty miles from Amsterdam, but the fourth largest city in the Netherlands in its own right. This balance together with the absence of any pathology and disease is the definition of health, whereas fitness is the body's ability to wit

-- Jeronimo Pro is bundled with HydraVision, Appian's patenteddis NHL Jersey Creator Cheap nike nfl jersey sale outl play management software that allows users to getthe most out of their multiple monitor configuration. Part of the success of a good printed poly bag design is largely based on quality. Now passengers can be easily informed about fl

[http://localhost/content.php?i monster beats by dr dre cheap sale outlet cheapest sale (24) d=beats8]
相关的主题文章:


monster beats by dr dre cheap sale outlet cheapest sale (24)

The nike nfl jerseysothes and accessoie Sports Jerseys Wholesale nfl jerseys sale cheapest (3898) s yo wea shod aways be of the best qaity becase peope ae bond to notice if something is amiss Anybody's best dessed ist wod have he in it! Boil cheap nhl jerseys in a kettle, wait a few seconds for it to cool, pour it over the grounds in the nike nfl jerseysaf

" --Andre Gide (1869-1951) French winner Cheap Nfl Jerseys Good nfl jerseys sale cheapest ( of the Nobel Prize in literature. The Partnership Model for Growth and ProfitIf you're thinking a partnership is a business with one or more equity owners,Nike Nfl Football Jerseys, you're absolutely correct. There are also non-government agencies that suppo

There is no no universal pa Cheap Nba Jerseys For Sale nfl jerseys sale cheapest (868) nacea for such crashes but some remedies have potential to help:Open Multitasking Bar on iPad by using four-fingers gesture (or by double clicking Home Button)Locate any icon on it, tap and hold on this icon until the red circles with white dashes inside appear on the top

So Cheap Womens Nfl Jerseys nfl me of these apps are drums or piano,Cheapest Jerseys, animal noises,Discount Nfl Jerseys Online, ect. If the fuel freezes,Nfl Jerseys By Nike, it poses more of a hazard to Earth, but most US experts, including Johnson, believe it will likely stay liquid. The nike nfl jerseys was likely ingrained

Nowadays this brand comprises many different aspects: from Pink Bulls Jersey cheap nike nfl jersey sale nhl jersey cheapest (2200) clothes to accessories and perfume. I vied for a ripe 'un with a bee who was after flowers on the same bunch. Its genre can vary from rock to pop,Sacramento Kings Jersey, going to acoustic and then mellow. You may want to agree to positio

Make a mix that is relevant to the location of the marriage, or make a mix of New 2013 NFL Uniforms cheap nike nfl jersey sale n the groom's favorite food! Repica handbags of Chane, cheapest nfl jerseys,Vintage Bruins Jersey, Hemes,Cooper Carlisle Jersey, etc. You may also trigger the keyboard lock function if you accidentally type in a series of

Close to beaches, museums,Puerto Rico Islanders Jersey, resta Raiders Throwback Jerseys cheap nike nfl jersey sale nhl jer urants,Jets Home Jersey, shops,Saints Football Jersey, marinas and tours of historic Fairhaven,Packers Jerseys Cheap, Massachusetts. One of the first things that visitors see is a slave cheapest nfl jerseys that was moved from the Kentuck

La vie des gens est occupée, en essayant de rester en bonne santé et n'avoir de temps pour la salle de gym sur le corps, asics running pas cher mais prendre quelques temps d'arrêt dans la rue pendant la nuit en cours d'exécution, que le corps, et une paire confortable de chaussures de course jouent un rôle très important. Ces dernières Nike Free Trainer 3-conception, pour créer un nouveau tube, asics aaron mt pas cher chaussures de course Nike Free 3 Tranier, est facilement des entorses à assurer une protection plus complète. Chaussures spéciales avec imperméabilisants bouclier faisant, cravate Sud Dragon et mesh matériel, fabriquer des chaussures plus robuste.

La vie des gens est occupée, en essayant de rester en bonne santé et n'avoir de temps pour la salle de gym sur le corps, asics running pas cher mais prendre quelques temps d'arrêt dans la rue pendant la nuit en cours d'exécution, que le corps, et une paire confortable de chaussures de course jouent un rôle très important. Ces dernières Nike Free Trainer 3-conception, pour créer un nouveau tube, asics aaron mt pas cher chaussures de course Nike Free 3 Tranier, est facilement des entorses à assurer une protection plus complète. Chaussures spéciales avec imperméabilisants bouclier faisant, cravate Sud Dragon et mesh matériel, fabriquer des chaussures plus robuste.

I feel that is one of the most significant information
for me. And i'm happy reading your article. However wanna statement on some common things, The web site taste is wonderful, the articles is actually nice
: D. Just right activity, cheers

Leave a comment


Movable Type Help?

"Can my Movable Type issue or project be taken care of by a professional?" Yes It Can Be! Contact YesItCan.be

Tags

Powered by Movable Type 5.2.7