Thanks to Lynda and Jenn there is a way to navigate between next and previous entries only within a category. But there has been many requests on the forums for a way to go between the category archives with next and previous like the date-based archives have.
This script will show the linked title of the previous and next categories, alphabetically, on each category archive page.
This is a PHP-based solution. The pages that you put this on should be named with a .php extension. It requires that to parse the code, and won't show anything in this section otherwise. To set your Archives to be .php, follow these steps:
- Change the extension of the archives by going into the Blog Config under Preferences and entering php in the archive extension box.
- Rebuild all.
- Log into your server with your FTP client and delete the archives and index files which are .html. This will insure that the browser goes to the php versions.
Paste this code into the Category Archive Template, wherever you'd like the navigation to appear.
Required: MTGlue Plugin (available for MT2.21 and higher) to make the array easier to work with.
<?
//If you use an Archive Filename, you can use these fields to put what goes before
//and after the category name. So if your files are in category/index.php,
//put "category/" in the prefix and nothing in the suffix. Extention will be .php
//The default cat_categoryname.php is default.
$filename_prefix = "cat_";
$filename_suffix = "";
//This is the separator which goes between the titles and MAIN link.
$separator = " | ";
$archpath = "<$MTBlogArchiveURL$>";
$mainpath = "<a href=\"<$MTBlogURL$>\">main</a>";
$file_pre = "<a href=\"".$archpath.$filename_prefix;
$file_suf = $filename_suffix.".php\">";
$thisarch = "<$MTArchiveTitle dirify="1"$>";
$categories = array(<MTGlueContainer><MTArchiveList archive_type="Category">'<$MTArchiveTitle dirify="1"$>'<MTGlue>, </MTGlue></MTArchiveList></MTGlueContainer>);
$count = count($categories);
for($c = 0; $c <= $count; $c++){
if ($thisarch==$categories[$c]) {
//Check to see if this is the first element of the array
if ($c==0) {
$next = intval($c+1);
echo $mainpath, $separator;
echo $file_pre, $categories[$next];
echo $file_suf, $categories[$next], " ?</a>";
//no previous
}
//check to see if this is the last element of the array
elseif ($c==$count) {
$next = intval(0);
$prev = intval($c-1);
echo $file_pre, $categories[$prev];
echo $file_suf, "? ", $categories[$prev], "</a>";
echo $separator, $mainpath;
//no next
}
//all else are normal
else {
$next = ($c+1);
$prev = ($c-1);
echo $file_pre, $categories[$prev];
echo $file_suf, "? ", $categories[$prev], "</a>";
echo $separator, $mainpath, $separator;
echo $file_pre, $categories[$next];
echo $file_suf, $categories[$next], " ?</a>";
}
}
}
?>
Brenna has an alternate version of this script in the original thread – we both were working on it at the same time!!
Post any questions or suggestions in the comments!