Well, as you may or may not have noticed, I've been futzing around with the pages here. Robyn and Christine both asked about category next/previous links in MT… and though it was said (on the MT boards) that it can't be done, I've gotten *very very* close. But! no cigar…
So, welcome to another part of this blog – as collaboration tool. Here's what I've got so far:
My thought was I'd create an array with a list of links. A different array for each category. (An additional array – a list of IDs was created to be parallel to the links array – you'll see why in a minute)
So I created a seperate index page with this code:
<?
$i = 0;
$j = 0;
$k =0;
$l = 0;
$m = 0;
?>
<MTCategories>
<MTEntries>
<?
if ("<$MTEntryCategory$>"=="how to's") {
$howtoidarraytemp[$i] = "<$MTEntryID encode_php="qq"$>";
$howtolinkarraytemp[$i] = "<$MTEntryLink encode_php="qq"$>";
$i++;
} else if ("<$MTEntryCategory$>"=="MT hacks") {
$mthacksidarraytemp[$j] = "<$MTEntryID encode_php="qq"$>";
$mthackslinkarraytemp[$j] = "<$MTEntryLink encode_php="qq"$>";
$j++;
} else if ("<$MTEntryCategory$>"=="bookmarks") {
$bookmarksidarraytemp[$k] = "<$MTEntryID encode_php="qq"$>";
$bookmarkslinkarraytemp[$k] = "<$MTEntryLink encode_php="qq"$>";
$k++;
} else if ("<$MTEntryCategory$>"=="lessons learned") {
$lessonsidarraytemp[$l] = "<$MTEntryID encode_php="qq"$>";
$lessonslinkarraytemp[$l] = "<$MTEntryLink encode_php="qq"$>";
$l++;
} else if ("<$MTEntryCategory$>"=="suggested reading") {
$readingidarraytemp[$m] = "<$MTEntryID encode_php="qq"$>";
$readinglinkarraytemp[$m] = "<$MTEntryLink encode_php="qq"$>";
$m++;
}
?>
</MTEntries>
</MTCategories>
So the idea was to include the page above on the individual entries page. Since each category has it's own array – I would
1) check which category we were looking at
2) transfer the category specific arrays into a standard array
2) get the key in which the current ID lives (in the current ID array)
3) add 1 to that key to get the next link, subtract 1 to get the previous link
4) display the links…
So here's that code:
<?
include("/home/pathtofile/categoryArrays.php");
if ("<$MTEntryCategory$>"=="how to's") {
$idarraytemp = each($howtoidarraytemp);
$linkarraytemp = each($howtolinkarraytemp);
} else if ("<$MTEntryCategory$>"=="MT hacks") {
$idarraytemp = each($mthacksidarraytemp);
$linkarraytemp = each($mthackslinkarraytemp);
} else if ("<$MTEntryCategory$>"=="bookmarks") {
$idarraytemp = each($bookmarksidarraytemp);
$linkarraytemp = each($bookmarkslinkarraytemp);
} else if ("<$MTEntryCategory$>"=="lessons learned") {
$idarraytemp = each($lessonsidarraytemp);
$linkarraytemp = each($lessonslinkarraytemp);
} else if ("<$MTEntryCategory$>"=="suggested reading") {
$idarraytemp = each($readingidarraytemp);
$linkarraytemp = each($readinglinkarraytemp);
} else {
$abort = "true";
// this prevents errors from occuring if
// it's a category that doesn't have an array associated with it
}
//$idarray = array_reverse($idarraytemp);
//$linkarray = array_reverse($linkarraytemp);
if (!$abort =="true"); {
print("<p>");
$thisKey = array_search("<$MTEntryID$>", $idarraytemp);
$thisKeyNext = $thisKey + 1;
$thisKeyPrevious = $thisKey – 1;
if ($thisKeyPrevious < 0) {
// do nothing
} else {
print('<a href="');
print($linkarraytemp[$thisKeyPrevious]);
print('">see the previous post in this category</a>');
$previouslinkshown = "true";
}
if ($thisKeyNext >= count($linkarraytemp)) {
// do nothing
} else {
if ($previouslinkshown == "true") {
print(" || ");
}
print('<a href="');
print($linkarraytemp[$thisKeyNext]);
print('">see the next post in this category</a>');
}
print("<br>");
print("This current category is: ");
print("<$MTEntryCategory$>");
print("</p>");
}
?>
As you can tell… it's not working. Something I think I might be doing wrong – the way I'm transfering the values of the array into that standard-named array… I know the array is currently reversed… I commented out the 'fix' for now.
If you have any suggestions… leave 'em in the comments, and I'll give it a try.
Some notes – I'm only paying attention to MAIN categories here, I decided for simplicity sake (ha!) to ignore the mutliple categories thing… that's why I'm using the MT tags that you see – MTCategoryLabel will display ALL categories… etc.