bmc

Next Entry/Previous Entry code?

Vote 0 Votes

Hello,
I'm looking to integrate some code onto my site that with give users the ability to go to the next/prevous most recent entry within the same category they are in. Once they've reached the end of the entries in that category, they are provided with a link to the next most recent entry in the next alphabetically category (the link will include the category name).

Can anyone help me with this? I haven't found the perfect documentation for what I need yet.

Thanks!
Bryan

Reported on Movable Type 5

4 Replies

| Add a Reply
  • I found a Japanese blog post explaining how to do it.
    http://bizcaz.com/archives/2008/06/24-020410.php

    You can use this example in mt:Entries or Entry Archive.

    <mt:IfNonEmpty tag="EntryCategory">
        <$MTEntryCategory setvar="entcat"$>
        <$MTEntryDate format="%Y%m%d%H%M%S" setvar="curdate"$>
     
        <$mt:SetVar name="entall" value="0"$>
        <MTEntries category="$entcat">
            <mt:SetVarBlock name="entdate[$entall]"><$MTEntryDate format="%Y%m%d%H%M%S"$></mt:SetVarBlock>
            <mt:SetVarBlock name="entname[$entall]"><$MTEntryTitle$></mt:SetVarBlock>
            <mt:SetVarBlock name="entlink[$entall]"><$MTEntryPermalink$></mt:SetVarBlock>
            <$mt:SetVar name="entall" value="1" op="+"$>
        </MTEntries>
     
        <ul>
        <mt:For var="x" from="0" to="$entall" increment="1">
            <mt:If name="entdate[$x]" eq="$curdate">
                <mt:SetVarBlock name="idx"><$mt:GetVar name="x" value="1" op="+"$></mt:SetVarBlock>
                <mt:If name="idx" lt="$entall">
                    <li class="list_entry">Prev Page: <a href="<mt:GetVar name="entlink[$idx]">" title="Previous"><mt:GetVar name="entname[$idx]"></a></li>
                </mt:If>
     
                <mt:SetVarBlock name="idx"><$mt:GetVar name="x" value="1" op="-"$></mt:SetVarBlock>
                <mt:If name="idx" ge="0">
                    <li class="list_entry">Next Page: <a href="<mt:GetVar name="entlink[$idx]">" title="Next"><mt:GetVar name="entname[$idx]"></a></li>
                </mt:If>
                <mt:SetVar name="x" value="$entall">
            </mt:If>
        </mt:For>
        </ul>
    <mt:Else>
        <ul>
        <MTEntryPrevious><li class="list_entry">Prev Page: <a href="<$MTEntryPermalink$>" title="Previous"><$MTEntryTitle encode_html="1"$></a></li></MTEntryPrevious>
        <MTEntryNext><li class="list_entry">Next Page: <a href="<$MTEntryPermalink$>" title="Next"><$MTEntryTitle encode_html="1"$></a></li></MTEntryNext>
        </ul>
    </mt:IfNonEmpty>
    
  • Great! That code works well! Thank you.

    I doesn't go to the next category when it gets to the end of the current one, but I like what it is doing with the next and previous posts within the same category.

    Thanks!

Add a Reply

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

Forum Groups

1774 6167

Last Topic: Template modules by Zielun on Feb 16, 2012

86 302

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

1434 5088

Last Topic: Maintenance announcement by Nick on Feb 17, 2012

695 2912

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

174 740

Last Topic: Captcha images rendering slowly by ScottM on Feb 12, 2012

190 568

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