tips and tricks for movable type
previous and next by category
November 29, 2002
I implemented this how-to from Scriptygoddess and modified it a little more to my liking: using entry titles and changing the visual display a bit. Here's what my code looks like (I've removed all of the author's comments for simplicity).
In the new Category Archive Template you need to make:
$a = 0;
$this_category = "<$MTArchiveCategory dirify="1"$>";
?>
<MTEntries>
<?
if ("<$MTEntryCategory dirify="1"$>"==$this_category) { $<$MTArchiveCategory dirify="1"$>idarraytemp[$a] = "<$MTEntryID encode_php="qq"$>"; $<$MTArchiveCategory dirify="1"$>linkarraytemp[$a] = "<$MTEntryLink encode_php="qq"$>"; $<$MTArchiveCategory dirify="1"$>titlearraytemp[$a] = "<$MTEntryTitle encode_php="qq"$>";
$a++;
}else{
// do nothing
}
?>
</MTEntries>
In the Individual Archive Template (where you want the link navigation to appear):
$thisCat = "<$MTEntryCategory dirify="1"$>";
if (!$thisCat == "") {
include("/home/username/public_html/path/to/arrays/<$MTEntryCategory dirify="1"$>.php");
for ($i =0; $i < count($<$MTEntryCategory dirify="1"$>idarraytemp); $i++) {
$idarraytemp[$i] = $<$MTEntryCategory dirify="1"$>idarraytemp[$i];
$linkarraytemp[$i] = $<$MTEntryCategory dirify="1"$>linkarraytemp[$i];
$titlearraytemp[$i] = $<$MTEntryCategory dirify="1"$>titlearraytemp[$i];
}
if ($idarraytemp >= 1) {
$titlearray = array_reverse($titlearraytemp);
$idarray = array_reverse($idarraytemp);
$linkarray = array_reverse($linkarraytemp);
print("<p>");
$thisKey = array_search("<$MTEntryID$>", $idarray);
$thisKeyNext = $thisKey + 1;
$thisKeyPrevious = $thisKey - 1;
if ($thisKeyPrevious < 0) {
// do nothing
} else {
print('<a href="');
print($linkarray[$thisKeyPrevious]);
print('" title="previous entry in this category">« ');
print($titlearray[$thisKeyPrevious]);
print('</a>');
print(" | ");
$previouslinkshown = "true";
}
print('<a href="<MTBlogArchiveURL><$MTEntryCategory dirify="1"$>.php" title="see all entries in this category">');
print("<$MTEntryCategory$>");
print('</a>');
if ($thisKeyNext >= count($linkarray)) {
// do nothing
} else {
print(" | ");
if ($previouslinkshown == "true") {
// do nothing
}
print('<a href="');
print($linkarray[$thisKeyNext]);
print('" title="next entry in this category">');
print($titlearray[$thisKeyNext]);
print(' »</a>');
}
print("</p>");
} else {
// do nothing
}
}
?>
Change /home/username/public_html/path/to/arrays/ to your server path. You may also need to change <MTBlogArchiveURL><$MTEntryCategory dirify="1"$>.php to match where your Category Archives are located.
TrackBack: 3
(URL: http://www.thegirliematters.com/sf/mt-track.cgi/116)
» What scripts and plug-ins do you use with Movable Type?
Excerpt: If it weren't for the generous people who create plugins and share their code, this site would have long ago lost it's fizz. The related resources to the right list all the script sources I've used on this site at one time or another. [MT plugins] To ...
Weblog: Electrosketch!
Tracked: 09.14.03 10:03 AM
» I Rawk!
Excerpt: Had a little bit of fun tonight with PHP. You'll soon notice that all of my navigation links are now at the bottom of the entries on my individual archives. But there's something new! You can now navigate through categories...
Weblog: Nosey Little Crook
Tracked: 11.18.03 10:42 PM
» What code resources do you use?
Excerpt: The JavaScript Source is a great place to find javascript resources and Scripty Goddess is a goldmine of PHP and other scripts tailored for the movable type environment. Also, another good source for tips is Girlie Matters. You may also want to check o...
Weblog: Electrosketch!
Tracked: 12.28.03 11:11 AM
Comments
This is probably a stupid question, but how would I do this for previous and next by date? Like how you have yours set up at the bottom of the page?
Here's the code I'm using:
<a class="side" href="<MTEntryLink archive_type="Individual">" title="previous entry by date">« <$MTEntryTitle$></a> |
</MTEntryPrevious>
<a class="side" href="<$MTBlogURL$>" title="main page">main</a>
<MTEntryNext>
| <a class="side" href="<MTEntryLink archive_type="Individual">" title="next entry by date"><$MTEntryTitle$> »</a>
</MTEntryNext>
Does that help? ;-)
Thank you so much! I really appreciate that. :)
Sorry for pinging you twice! :P Also wanted to say thank you for being such an awesome resource. I owe more than half my MT knowledge to your website.
This is also another stupid question, but how can you make rel links to the first/last entry (to an individual entry) as in prev/next entry?
Of course, when you are looking at the first/last entry you don't want the link to show up.
I was wondering if it is possible do that without using any PHP.
hi girlie! thanks for this code. i'm using it on my archives already, but there's only one thing that confuse me, whenever i click on the category name that's supposed to show the list of entries associated with it, it gives me a blank page? no errors, just blank page to that link. did i miss something?