Displaying the Next and Previous Entry in a Category with Movable Type

| 18 Comments | No TrackBacks |
Using the MTEntryNext and MTEntryPrevious tags it is very easy to display information about the previous or next entry in Movable Type, but only if you are interested in a purely chronological ordering.  But what if you want to limit the entries on display to those of a particular category?
There appear to be two solutions that you can find on-line, and neither of them work:

Fortunately, this problem can be solved with some template code (which you can put in an Entry archive or in any entry context:

<mt:entrycategory setvar="thisentrycategory">
<mt:entryid setvar="thisentryid">

<mt:entries category="$thisentrycategory" sort_order="ascend">
<mt:setvarblock name="links" index="$__counter__"><mt:entrypermalink></mt:setvarblock>
<mt:if tag="entryid" eq="$thisentryid"><mt:var name="__counter__" setvar="thiscounter"></mt:if>
</mt:entries> 

<mt:var name="thiscounter" op="-" value="1" setvar="previouscounter">
<mt:var name="links[$previouscounter]" setvar="previouslink">

<mt:var name="thiscounter" op="+" value="1" setvar="nextcounter">
<mt:var name="links[$nextcounter]" setvar="nextlink">

<mt:if name="previouslink">Previous entry: <mt:var name="previouslink"></mt:if><br>
<mt:if name="nextlink">Next entry: <mt:var name="nextlink"></mt:if>


How does it work:
  • First, the ID and main category of the current entry are stored in variables.
  • The entries loop goes over all entries in the aforementioned main category, in chronological order, and stores their URLs in a numbered array. (Note: you can store other info too, if you need it)
  • When we get to the entry we are trying to look up the next and previous entries for, we store its position in the array using the $thiscounter variable.
  • After the array has been constructed, we take the elements in it that come just before and just after the position we stored, and store their values in two new variables, $nextlink and $previouslink.   Note that if our entry was first or last in the array, the next or previous element will come up empty (which is what we want, in fact).
  • Finally, we display the values of the $previouslink and $nextlink variables (if they are not empty)


No TrackBacks

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

18 Comments

Martin, I used this code in the About this Page widget in MT 5.02, and has you can see:

http://www.franchise-info.ca/supply_chain/2010/09/how-%20to-reduce--pci-compliance-costs.html

it didn't quite work.

Any suggestions?

Thanks.

OutreAtlantique, seul le Dow Jones plie, tandis que le S 500 et le Nasdaq Composite essayent de grappiller quelques fractions (+ 0,eleven percent et + 0,eighteen % respectivement). One thing appears to be a number of: strengthening a state shield will never raise its transparency.

Des bonus qui

AICASA Indicators Articulation Agreement with Old Dominion University to create Study Abroad System

American International College of Arts and Sciences Antigua (AICASA) has signed an articulation agreement with Old Dominion University (ODU) that may permit their students to study abroad in Antig

Allen Stanford sentenced to 110 years

Former jetsetting Texas tycoon R. history. District Judge David Hittner handed down the sentence throughout a court hearing in which two people today spoke on behalf of Stanford's investors about how his fraud had impacted their lives.

Prosecutors had aske

The constructive side, New York is filmmakerfriendly and gave the 8180 actors, director and film crew an extra halfday since from the issues, she stated.. This has resulted within a sizeable influx of noisy motorcycles.. He went to Oakland and flourished. Actor Kin Shriner is 56.

I watched him g

Chiefs coach Andy Reid may not be terribly eager to discuss his return to Philadelphia on Thursday he repeatedly said the showdown is not about him but at least one Eagle is anticipating seeing his former coach. Even amid a job derailed by a seasonending knee injury in 2011 and dimmed by the Chiefs

For shoppers with combined balances of $50,000 or a great deal more and a checking or Merrill account, the bank is creating "Platinum Privileges," a rewards plan that offers specialized customer support, unique prices on mortgages, certificates of deposit and funds marketplace accounts and also a de

Limit one (1) Prize per household or household.. His practical experience in the major level is outstanding and fills our criteria of speaking fluent English. David Sproule (BA Honours [Political Science], University of Alberta, 1978; LLB, University of Alberta, 1981) joined the Division of External

convinced find http://www.militarytraveling.com//wholesale-nfl-jerseys-4138181.html ing information about startahedgef http://www.fotogrande.com/wp-content/wholesale-nfl-jerseys-9371798.html und.net shopping cheap authentic nike nfl jerseys free shipping per cheap nfl jerseys from china nike IPL working browns jerseys sale the actual market http://zbcode.com/cheapfootballjerseys/ secondary http://www.houseofschade.com/Scripts/authentic-louis-vuitton-bags-discount-7520572.html economy nfl jerseys china , and that i chiefs

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
Powered by Movable Type 5.2.7