Next/Prev Links Specific to Categories in MT - v.2
Jenn and I spent all day long working on earlier versions of this script, however we believe that this is the quickest, most automated way to do things.
NOTE: This will only work with MT 2.0 + as it relies on the ability to create multiple archive templates.
Step 1: Go to your template section in MT and click “Create new archive template” (near the middle of the page). You can select any Name you’d like. In the template body place the following text exactly as it appears:
<?
$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”$>”;
$a++;
}else{
// do nothing
}
?>
</MTEntries>
Save the new template.
Step 2: Go to your Blog Config, click the Archiving link then select the ADD NEW button.
Step 3: Select Archive Type: “CATEGORY” and select the template name you just created in Step 1 under Template. Hit the Add button.
Step 4: You should now see two templates next to the Category Archive Type. Make sure the category box is checked:

You’ll notice there’s a Category Archive Template with the radio box checked (That’s the DEFAULT - you don’t want to switch it!) and there’s CategoryArray, which is the name of the archive template I created.
In the box next to the name of the archive template you created, place the following:
arrays/<$MTArchiveCategory dirify="1"$>.php
This will create a page for each category with the array we’ll need to execute the code. It will place it inside a folder named “arrays” in your archive directory. Your archive directory should already be CHMOD 777.
Hit SAVE.
Step 5: Rebuild your Category Archives Only. Make sure the pages have been created in your archives directory in a folder named arrays.
Step 6: Inside your Individual Archive Template, place the following code where you’d like your previous/next links to appear. I’ve highly commented this up to give you an idea of what’s going on (hopefully I understand it correctly myself)
You only need to change one line here and that’s in red:
<?
# If you have no category selected, this will keep
# the script from breaking
$thisCat = “<$MTEntryCategory dirify=”1″$>”;
if (!$thisCat == “”) {
# You want to change this line. Everything before arrays should be
# the path to your archives directory.
include(”/home/username/public_html/pathtoarchives/arrays/<$MTEntryCategory dirify=”1″$>.php”);
# This line sets the variable $i to zero, then counts the total number
# of ‘entries’ in your category, then makes sure we stop the script
# when the total number of entries has been reached, so it doesn’t
# loop and loop and waste CPU cycles.
for ($i =0; $i < count($<$MTEntryCategory dirify=”1″$>idarraytemp); $i++) {
$idarraytemp[$i] = $<$MTEntryCategory dirify=”1″$>idarraytemp[$i];
$linkarraytemp[$i] = $<$MTEntryCategory dirify=”1″$>linkarraytemp[$i];
}
# If you only have one entry in a category, this will prevent
# the script from breaking
if ($idarraytemp >= 1) {
# This reverses the array so the links will appear in the correct order
$idarray = array_reverse($idarraytemp);
$linkarray = array_reverse($linkarraytemp);
# Here’s where the HTML comes in. Anything with a print next
# to it can be customized to fit your needs, but be careful or
# you might end up breaking the script.
print(”<p>”);
# Searches in your array file for the current MTEntry ID in order
# to get the idarray. Then adds 1 to get the next entry idarray
# and subtracts 1 to get the previous entry idarray
$thisKey = array_search(”<$MTEntryID$>”, $idarray);
$thisKeyNext = $thisKey + 1;
$thisKeyPrevious = $thisKey - 1;
# If there is no previous entry, do nothing. Otherwise
# Print a link to the previous entry. Again, you can
# change this to fit your needs, but be sure you know
# what you’re doing.
if ($thisKeyPrevious < 0) {
// do nothing
} else {
print(’<a href=”‘);
print($linkarray[$thisKeyPrevious]);
print(’”>see the previous post in this category</a>’);
$previouslinkshown = “true”;
}
# Same as with the previous entry.
if ($thisKeyNext >= count($linkarray)) {
// do nothing
} else {
if ($previouslinkshown == “true”) {
# Here’s the Next/Prev separator. Might want to change it
print(” || “);
}
print(’<a href=”‘);
print($linkarray[$thisKeyNext]);
print(’”>see the next post in this category</a>’);
}
print(”<br>”);
print(”This current category is: “);
print(”<$MTEntryCategory$>”);
print(”</p>”);
} else {
// do nothing
}
}
?>
All you need to do is replace the line in red with the server path to your archives.
And that’s it! Please let us know if you have any questions or run into any glitches with this script.
April 17th, 2002 at 9:07 pm
YOU ROCK!!! YAY!
Sorry I bailed out towards the end… Our moving company finally showed up to pack our stuff, and now I’m hit with a mega-migraine… off to bed! THANK YOU!!!
April 17th, 2002 at 9:19 pm
I had to make one more adjustment to the script in what to put into the category archive template. If you don’t do it that way, it won’t break the script, per se, but it won’t link right. Can’t explain it well. The main post is updated.
April 17th, 2002 at 10:49 pm
This rocks! I just finished implementing this on the galleries on my site. Granted, I only have one category active right now, but more are in the works, and I won’t have to create multiple blogs to handle them!
Thank you!
bcj.
April 18th, 2002 at 6:58 pm
You know, because of you girls, I’m going to give MT another chance. I was having major problems with comments before, with 1.4 I think.
But now you’ve gone and created this blog and it’s so inspiring! I want to try everything, lol.
April 19th, 2002 at 3:14 pm
Please excuse this if I’m asking a stupid question: will this still work even if you aren’t using php on your site (in Step 4)?
April 19th, 2002 at 3:23 pm
Jeff, nope, sorry. You have to be using PHP. It’s a PHP script.
April 30th, 2002 at 7:27 pm
Just wanted to post a big THANK YOU for making this available! I just finished implementing it on my new photoblog, Snap!, but changed what was actually being printed to suit my sidebar a bit better. Now I have next and previous by date and next and previous by category - really nice way to navigate!!!
thanks
May 1st, 2002 at 12:54 am
As soon as I get this implemented (Saturday. Must do on Saturday.) I will be set up similar to Kristine. I’m leaving the next/previous by date that is below the photos on Pixelog, but next to the category I will offer the next/previous within the category. Yeah!
YOU GUYS ROCK!!! Thanks *so* much for writing this!
May 1st, 2002 at 6:59 am
I have it setup on my photoblog as well. It works great for photo sites.
May 9th, 2002 at 6:07 pm
I just tried to use this script and keep ending up with part of the code in my individual listing like this:
= 1) { $idarray = array_reverse($idarraytemp); $linkarray = array_reverse($linkarraytemp); print(”
“); $thisKey = array_search(”48″, $idarray); $thisKeyNext = $thisKey + 1; $thisKeyPrevious = $thisKey - 1; if ($thisKeyPrevious = count($linkarray)) { // do nothing } else { if ($previouslinkshown == “true”) { print(” | “); } print(’Next post in this category’); } print(”
“); print(”This current category is: “); print(”Photography”); print(”
“); } else { // do nothing } } ?>
I know it must be something simple like a missing } or something. Can you please point me in the right direction to track down the problem?
Thanks much.
May 9th, 2002 at 7:16 pm
Are you sure you have PHP installed on your server? And that your extensions are .php ?
A link to the place you’re trying to do this would be helpful.

May 9th, 2002 at 9:13 pm
Yes, it appears PHP is working, because it created the PHP archive files fine, and the extra Category Template option as well.
The site is a friend’s, I’m trying to get his blog up for him. All of the posts there are just crud.
Thanks
May 9th, 2002 at 9:39 pm
Devoid, the creating of the Category Template is done in moveable type - it’s just outputting text as far as it’s concerned and without PHP installed on your server and called up with a .php extension, the server just reads it as text.
The files on your site are coming up as .html which means it isn’t parsing the php. PHP has to know when to execute.
To test to see if your server is capable of PHP, create a new file in a text editor and put the following code inside:
<?php
phpinfo()
?>
Then upload it to your server as phpinfo.php and point your browser to it. If all you see is that text, PHP isn’t setup for you. If you see a big long list of PHP configurations, then you CAN execute PHP and need to change the extensions to your individual archives (or any other page you want to execute PHP code) to .php instead of .html
May 9th, 2002 at 9:48 pm
Thanks for the quick response Lynda. It comes back with lots of info:
http://www.lifesignsphoto.com/phpinfo.php
May 9th, 2002 at 9:49 pm
Okay, then again - you need to have your file extensions as .php, not .html - That’s how the server figures out it needs to parse the php and not just output it as text.
May 9th, 2002 at 10:07 pm
OK, so php is working. I deleted all entries, changed my archive extension to php, and added 2 new entries. What I end up with is the category entries listed normally, and broken links to the individual entries, since they still reference an html extension! So I went and changed the blog prefs to point to the arrays folder for archives, but still have the same trouble.
What am I messing up here?
Thanks for your patience.
May 9th, 2002 at 10:20 pm
Got it! I put the archive path back to archives, not arrays and it’s working!! Yippie. So now that I got that solved, what I really wanted was to be able to click on the category off the main page, then do the prev/next in category from there. Is that doable?
May 9th, 2002 at 10:30 pm
Yes, it is doable, just insert the code into your main index template the same way and change the output to index.php instead of index.html
May 9th, 2002 at 10:51 pm
Ok, last Q, promise. Do I repeat all of the above, or just from Step 6 on?
Thanks again for your great code and your help.
May 9th, 2002 at 10:56 pm
Just from step 6 onward.
May 11th, 2002 at 12:16 am
Excellent instructions! It works great!
Thank you for making this script (and site) available for all of us tweaking types!
Is there a straightforward way to capture the title of the prev/next category entry to use that instead of “prev” or “next” (or other static text)?
May 11th, 2002 at 12:22 am
You’d have to put it into the category arrays which would make them that much more difficult. (In other words, yes, it could be done, but the script would need to be majorly revised)
What I do is put the category name and use it in the title tag of the link so it displays “Previous entry in ” or something like that.
May 11th, 2002 at 12:29 am
Actually, I don’t think it would be all that hard….. (sorry, it’s been a while since I’ve looked at the script. hehe)
Inside the if statement up in step one, place the following:
$<$MTArchiveCategory dirify=”1″$>titlearraytemp[$a] = “<$MTEntryTitle encode_php=”qq”$>”;
then inside the for statement in step six:
$titlearraytemp[$i] = $titlearraytemp[$i];
After: if ($idarraytemp >= 1) {
add this;
$titlearray = array_reverse($titlearraytemp);
And then I think you can use $titlearray to change to the title of the post. I haven’t tried that out though, so don’t quote me on it. You might just want to try it and fiddle with it and change it back if it doesn’t work.
But I’m sure it wouldn’t be all that hard to include if you want me to take a closer look at it.
May 12th, 2002 at 7:40 pm
Lynda, I just wanted to pass along that if a user follows the MT doc’s suggestions regarding Archive file templates, and then they want to use this cool script, they must change the Archive file template’s suffixes to .php.
May 27th, 2002 at 6:11 pm
Yup, this script rocks!
I made one (itty bitty) change that you might want to too — I changed <br> to <br /> for XHTML compliance. Not to be nit-picky, I just thought you might like to know.
Like Cheryl, I too would enjoy being able to provide my users with the title of the next link within a given category (ideally in the format: Next entry in the X category: Entry_title_here), but your insturctions above seemed a bit confusing.
You’ve already done more than enough, but it would be grand if you solved this problem too.
Thanks ever so much. -s!
June 14th, 2002 at 12:17 am
I’ve modified this script to use entry titles instead of static text (i.e., “prev” and “next”) for the previous and next links. I’ve posted the code I’m using on my site here. If you have questions, please continue to post comments at scriptygoddess instead of my site. Thanks.
June 19th, 2002 at 5:08 pm
Yeah, this didn’t work for me.
I kept getting the same error as Deviod (yes php is installed) as well as my category page linked to a “category.php” that just came up blank.
When I tried opening the individual archive files (00001.php or something) I got an error “Warning: Failed something something etc.) on it.
Hrm.
Cheers,
Glacius-Vector
http://madrant.com
June 21st, 2002 at 12:40 pm
Does Lynda have an e-mail?
Can anyone take a look at this thread and offer any advice?
Thanks!
http://www.movabletype.org/support/ib3/ikonboard.cgi?s=3d123f3f5010ffff;act=ST;f=14;t=860
June 21st, 2002 at 3:17 pm
Glacius: It sure looks like maybe you have made a change somewhere inthe code - the link shoudn’t point to cat_CATEGORYNAME.php on your individual entry pages, but it is. (example - the previous and next are both pointing towards the main category archive page.) When going through the tutorial above, I can’t see where you may have changed to make it do that. But maybe you need to start again with step 6 and repaste in the code into your Individual Archive.
June 21st, 2002 at 3:35 pm
I repasted the code, but I still only changed the same thing - the path to my archives, and it’s still linking back to the categories. Damn, what am I doing wrong?
Wow.
I used to be able to pull this kind of stuff in college - errors nobody knew how I generated. Hehe.
Incredibly frustrating.
Thanks for the help tho!
June 21st, 2002 at 5:17 pm
I’m not sure, this is just a guess…. do you have Category as the default archive type in the blog config? I wonder if that was changed to Individual if it would work. I don’t *see* that Jenn and Lynda used an MTEntryLink in here, which is what I would suppose would cause that, but maybe its in the underlying coding.
If you check this and that’s really the problem (and you don’t want Individual to be your default), I bet that Jenn or Lynda could help adjust the code to make it work for you
June 21st, 2002 at 8:11 pm
Okay -
I changed the default to “individual” and when I click on “archives” I get a big listing with every entry from every category.
When I select a record, I can navigate through that category, yes, but is it possible to get my category selection page back?
Thanks!
Gettin’ there!
June 22nd, 2002 at 5:05 pm
I’m really confused still because it doesn’t appear that anything is different on your page from the last time I looked. On the MT forums, you said: “now I need a solution so I can use the next/prev thing, but still have my “select category” page.”
I guess I don’t understand what you are looking for in a “select category page?” Maybe you mean the category index page that has the 4 links to each category index page? If so, you can modify your archives.html page to be category based even while the default archive type is Individual (if that really worked for you with the next/previous option.)
Put this in the center of your archive.html template:
<MTArchiveList archive_type=”Category”>
<a href=”<$MTArchiveLink$>”><$MTArchiveTitle$></a><br />
</MTArchiveList>
That will give you your list of 4 categories like you have up right now.
Try that and post back
June 22nd, 2002 at 5:35 pm
I always switch my site back if something doesn’t work - BUT - with your new advice…
IT WORKS NOW - WOOOOO!
Thanks!
June 27th, 2002 at 10:14 pm
Oh, thank you so much! I was just looking for this type of thing… didn’t think it would be so complicated, but oh well, it works. And yes, I actually understand it all… just not PHP enough to actually write it. Yet. ^_~
July 14th, 2002 at 12:06 pm
hi, i was hoping that you could help. i went over the instructions a few times, but i can’t seem to get the script to work.
see here: http://fruitloop.org/albums/8_days_in_melbourne/
the .php links to the individual entries have been generated, but it always returns with this sort of error: Parse error: parse error, expecting `T_VARIABLE’ or `’$” in /home/fruitloop/public_html/albums/8_days_in_melbourne/11.php on line 48
any ideas?
(i’ve tested for php on my server using the phpinfo method above)
thanks!
July 15th, 2002 at 6:12 pm
I tried to rebuild my category archives but am getting this error (within MT):
Build entry ‘cat-and-dog’ failed: Build error in template ‘Category-based Archive’: Error in tag: You used an ‘MTEntryCategory’ tag outside of the context of an entry; perhaps you mistakenly placed it outside of an ‘MTEntries’ container?
Any ideas?
July 15th, 2002 at 6:15 pm
good gawd - never mind
July 15th, 2002 at 11:33 pm
Hey there - I was wondering if you would think this would be cutomizable for cycling through PAGES of categories…
For more info: http://www.movabletype.org/support/ib3/ikonboard.cgi?s=3d3393906896ffff;act=ST;f=12;t=543
July 17th, 2002 at 11:57 am
hi, just to update (and hopefully get a response, too!):
I’ve managed to get the script running on 2 out of the 2 categories in my blog (see category listing at http://fruitloop.org/albums/). It returns an error for the first one, but works for the other 2.
can anyone help?
August 3rd, 2002 at 1:47 pm
This should answer brenmae’s post about her category “8 days in melbourne”.
PHP does not allow variables that start with a number. Change this category to “eight days in melbourne”, rebuild all entries, and try it again.
I had this same problem when I added a “1000 Words” category. After changing it to “One Thousand Words” the problem was corrected.
August 12th, 2002 at 2:08 pm
Thanks for making this script available. I had a couple of dramas during installation - nothing that hasn’t already been mentioned - and my site is all the better for the effort.
Initially I thought the script would scroll through the category archives pages, which is what I wanted to do, but of course I was wrong.
So I have linked my category headings to the first post within each category, rather than the category page itself, with the links from the script at the base of each entry.
What I have noticed with this use of the script is that any entry assigned multiple category is only visible from within its main category heading.
Once again thanks.
September 11th, 2002 at 8:49 pm
I’m working on a photolog- http://deanmckenzie.org/photolog/ I’m trying to get these category index’s working. I’ve followed the directions, and rebuild the pages, I don’t get any errors, but the code doesn’t show up. I’ve made sure that I have two entries in at least one of my categories, but it’s not showing up. When I view source on the page, the place where my code should be, is empty, my guess is that php is parsed and returns nothing. Anyone have any ideas?
September 26th, 2002 at 11:22 am
is it possible to add a link to first and last post?
November 25th, 2002 at 5:39 pm
Thank you VERY MUCH for this script!!! To anyone who can’t get the code to show up, make sure you have the correct /home/…. path in there - that was my error (I was using the http: version of the path) and once I corrected that, it was a piece of cake!!!!! You scriptygoddesses rock!
November 29th, 2002 at 2:56 pm
On June 14, 2002, I commented above and included a link to my site but have since had to place a password on my site. So, I thought I’d post the code I used here so others could have access to it. The following is the entry I made in my journal about the previous/next categories hack.
-Cheryl
June 13, 2002
Darren emailed me about whether I ever got the previous-next category script from scriptygoddess to work using entry titles instead of static text (such as “prev” and “next”). His email reminded me that I had even asked such a question in a comment about the script.
So, I tried Lynda’s suggestions (thank you, Lynda) in response to my comment and, with the exception of one correction, it’s working.
The correction is: Instead of adding this to the for statement:
$titlearraytemp[$i] = $titlearraytemp[$i];
you need to enter this line:
$titlearraytemp[$i] = $<$MTEntryCategory dirify=”1″$>titlearraytemp[$i];
It is working on this site and can be seen on each of the individual archive pages.
I’ve included the actual code I’m using on *my* site below. If you use it, you are responsible for any resulting damages.
Before piddling with this piece of code tonight, I had previously modified it so it may look a little different from the script on the scriptygoddess site.
PLEASE POST YOUR QUESTIONS AT THE SCRIPTYGODDESS SITE.
…
ORIGINAL CODE AND INSTRUCTIONS ARE AVAILABLE AT
ScriptyGoddess.com: http://www.scriptygoddess.com/archives/000902.php
MY CODE FOR STEP 1 of scriptygoddess.com’s Previous/Next Category Script for MT:
<?
$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++;
}
?>
</MTEntries>
MY CODE FOR STEP 6:
<!– From ScriptyGoddess (scriptygoddess.com - For prev/next category links;
with modifications by cheryl @ pixelsintime.com to make sure the text
between the previous and next links (I used the category name with
a link) showed up on the very first entry and the very last entry in the
category. In addition, I modified the bit of code provided by Lynda at
ScriptyGoddess to use an entry’s title instead of "prev" or "next" as
the link label.
–>
<?php
# If you have no category selected, this will keep
# the script from breaking
$thisCat = "<$MTEntryCategory dirify="1"$>";
if (!$thisCat == "") {
# You want to change this line. Everything before arrays should be
# the path to your archives directory.
include("/home/username/public_html/pathtoarchives/arrays/<$MTEntryCategory dirify="1"$>.php");
# This line sets the variable $i to zero, then counts the total number
# of ‘entries’ in your category, then makes sure we stop the script
# when the total number of entries has been reached, so it doesn’t
# loop and loop and waste CPU cycles.
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 you only have one entry in a category, this will prevent
# the script from breaking
if ($idarraytemp >= 1) {
# This reverses the array so the links will appear in the correct order
$idarray = array_reverse($idarraytemp);
$linkarray = array_reverse($linkarraytemp);
$titlearray = array_reverse($titlearraytemp);
# Here’s where the HTML comes in. Anything with a print next
# to it can be customized to fit your needs, but be careful or
# you might end up breaking the script.
print(’<p>’);
# Searches in your array file for the current MTEntry ID in order
# to get the idarray. Then adds 1 to get the next entry idarray
# and subtracts 1 to get the previous entry idarray
$thisKey = array_search("<$MTEntryID$>", $idarray);
$thisKeyNext = $thisKey + 1;
$thisKeyPrevious = $thisKey - 1;
# If there is no previous entry, do nothing. Otherwise
# Print a link to the previous entry. Again, you can
# change this to fit your needs, but be sure you know
# what you’re doing.
if ($thisKeyPrevious >= 0) {
print(’<a href="’);
print($linkarray[$thisKeyPrevious]);
print(’">’);
print($titlearray[$thisKeyPrevious]);
print(’</a>’);
print(’ << <a href="<$MTEntryLink archive_type="Category"$>"><$MTEntryCategory$></a>’);
$previouslinkshown = "true";
}
# Same as with the previous entry.
if ($thisKeyNext < count($linkarray)) {
if ($previouslinkshown == "true") {
# Here’s the Next/Prev separator. Might want to change it
print(" >> ");
}
else {
# this is the first entry in the category
print(’<a href="<$MTEntryLink archive_type="Category"$>"><$MTEntryCategory$></a> >> ‘);
}
print(’<a href="’);
print($linkarray[$thisKeyNext]);
print(’">’);
print($titlearray[$thisKeyNext]);
print(’</a>’);
}
print("</p>");
}
}
?>
<!– End ScriptyGoddess –>
December 1st, 2002 at 11:27 am
You are heroines! I’m new to MT, but I managed to get this working on my site in half an hour or so. Just what I wanted!
Note: if you don’t want to change all your existing html files to php extensions you can use an archive file template for your individual entry files to make them .php while leaving the default at html for everything else.
Thanks again!
February 10th, 2003 at 8:29 pm
Excellent! I just used this modification for a photo blog, and it works just great. Thank you so much!
I didn’t get the $titlearray to work… it will display $titlearray, but no actual title. Instead I am now displaying a thumbnail of the previous and next pictures, which I think looks great. So instead of the static word “previous” I put:
<MTEntryPrevious><img src=”<$MTBlogArchiveURL$>/<$MTEntryMore$>-thumb.jpg” width=”80″ align=”middle” alt=”previous photo” /></MTEntryPrevious></a><br />« previous
and of course the same for “next”:
<MTEntryNext><img src=”<$MTBlogArchiveURL$>/<$MTEntryMore$>-thumb.jpg” width=”80″ align=”middle” alt=”next photo” /></MTEntryNext></a><br />next »
where $MTBlogArchiveURL is my image directory and $MTEntryMore is my image name. I put width=”80″ because the actual thumbnail has a width of 160 and I wanted it to look a little smaller. I don’t do scripts or anything, but I thought I’d share this.
Thanks again for this cool hack!
April 25th, 2003 at 1:56 am
I have a quick question on this. I’ve been looking at the code to long and now could just use a quick couple of ideas from you guys.
I am swapping out the link text and instead putting in rollover images. No big deal, however I need the “||” to go away and not be there anymore.
What would the easiest way to do this?
***background***
So, a couple of things…I have a three images. one variable one back and one forward. The variable image will replace the back image if needed.
So I placed the variable (large) under thisKeyPrevious (the first one)…
Then I swapped out the url links for the images in the appropriate place, and placed a blank spacer (for the forward image when it isn’t there…just above the else and previouslinkshown == “true”
So…
***issues***
so the swaps have worked for the entries at the end and middle of a catagory. but I am getting an error for the entry at the beginning.
Parse error: parse error, unexpected T_ELSE
Also, anytime I try to take out the “||” and the text related to the current entry the script breaks.
Any help would be great.
Thanks.
April 25th, 2003 at 8:16 pm
Problem Solved!
After a full night sleep and becoming fully and properly caffeinated I figured out that I had one to many conditional statements.
So now it is working and onto figuring out the content to put into the blog!
Thanks for the script.
–
Todd
May 2nd, 2003 at 5:27 pm
This might sound like a stupid question, but if you want to do the prev/next by date instead of category, how do you do that (i.e. what codes do you use)?
May 25th, 2003 at 9:20 pm
I’m doing about the same thing as Jael, but I’m using the <MTEntryExcerpt> tag between the <MTEntryPrevious> and the <MTEntryNext> tags. Anyway, I get a parse error (unexpected T_STRING) if there is no previous entry. Every other entry works fine except the first one.
May 25th, 2003 at 10:06 pm
Jim, I didn’t get that error, but the setup of using MTEntryMore/MTEntryExcerpt was actually a bit more complicated than the way I posted about it here. It worked fine at first, but some things got mixed up and it didn’t work the way I wanted it to.
I got it all going now, so if anyone needs help with it, I’ll be glad to send my code to you.
May 25th, 2003 at 11:15 pm
Jael, thanks for the quick response. I’d would greatly appreciate your code so I can see what I’m doing wrong. Thanks again
May 26th, 2003 at 10:17 am
Here is what I really did to use $more, $excerpt, and $title tags in my category-specific templates. You can see an example of what it looks like here. (I took the “Browse all photos” out of this template.)
***********************************
CATEGORY-SPECIFIC BROWSING TEMPLATE
***********************************
<?
$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″$>morearraytemp[$a] = “<$MTEntryMore encode_php=”qq” convert_breaks=”0″$>”;
$<$MTArchiveCategory dirify=”1″$>excerptarraytemp[$a] = “<$MTEntryExcerpt encode_php=”qq” convert_breaks=”0″$>”;
$<$MTArchiveCategory dirify=”1″$>titlearraytemp[$a] = “<$MTEntryTitle encode_php=”qq”$>”;
$a++;
}else{
// do nothing
}
?>
</MTEntries>
>>> NOTES: Added a line for every extra tag I will be using (copy+paste, then replace i.e. “link” wih “excerpt” or “link” with “more”).
************************
INDIVIDUAL ENTRY ARCHIVE
************************
<?php
# If you have no category selected, this will keep
# the script from breaking
$thisCat = “<$MTEntryCategory dirify=”1″$>”;
if (!$thisCat == “”) {
# You want to change this line. Everything before arrays should be
# the path to your archives directory.
include(”/FULL/PATH/arrays/<$MTEntryCategory dirify=”1″$>.php”);
# This line sets the variable $i to zero, then counts the total number
# of ‘entries’ in your category, then makes sure we stop the script
# when the total number of entries has been reached, so it doesn’t
# loop and loop and waste CPU cycles.
for ($i =0; $i < count($<$MTEntryCategory dirify=”1″$>idarraytemp); $i++) {
$idarraytemp[$i] = $<$MTEntryCategory dirify=”1″$>idarraytemp[$i];
$linkarraytemp[$i] = $<$MTEntryCategory dirify=”1″$>linkarraytemp[$i];
$morearraytemp[$i] = $<$MTEntryCategory dirify=”1″$>morearraytemp[$i];
$excerptarraytemp[$i] = $<$MTEntryCategory dirify=”1″$>excerptarraytemp[$i];
$titlearraytemp[$i] = $<$MTEntryCategory dirify=”1″$>titlearraytemp[$i];
}
# If you only have one entry in a category, this will prevent
# the script from breaking
if ($idarraytemp >= 1) {
# This reverses the array so the links will appear in the correct order
$idarray = array_reverse($idarraytemp);
$linkarray = array_reverse($linkarraytemp);
$morearray = array_reverse($morearraytemp);
$excerptarray = array_reverse($excerptarraytemp);
$titlearray = array_reverse($titlearraytemp);
# Here’s where the HTML comes in. Anything with a print next
# to it can be customized to fit your needs, but be careful or
# you might end up breaking the script.
print(”<b>Currently browsing: “);
print(”<$MTEntryCategory$></b><br /><br />”);
print(”<table border=\”0\” align=”center”><tr><td align=\”center\”>”);
# Searches in your array file for the current MTEntry ID in order
# to get the idarray. Then adds 1 to get the next entry idarray
# and subtracts 1 to get the previous entry idarray
$thisKey = array_search(”<$MTEntryID$>”, $idarray);
$thisKeyNext = $thisKey + 1;
$thisKeyPrevious = $thisKey - 1;
# If there is no previous entry, do nothing. Otherwise
# Print a link to the previous entry. Again, you can
# change this to fit your needs, but be sure you know
# what you’re doing.
if ($thisKeyPrevious >= 0) {
print(’<table border=”0″><tr><td align=”center”><a href=”‘);
print($linkarray[$thisKeyPrevious]);
print(’”><img src=”<$MTBlogURL$>/<$MTEntryCategory dirify=”1″$>/’);
print($morearray[$thisKeyPrevious]);
print(’/thumbs/thumb_’);
print($excerptarray[$thisKeyPrevious]);
print(’.jpg” width=”150″ height=”30″ class=”thumb” align=”middle” alt=”"’);
print($titlearray[$thisKeyPrevious]);
print(’"” /></a><br />« previous</td></tr></table>’);
$previouslinkshown = “true”;
}
# Same as with the previous entry.
if ($thisKeyNext < count($linkarray)) {
if ($previouslinkshown == “true”) {
# Here’s the Next/Prev separator. Might want to change it
print(”</td><td align=\”center\”> ¦¦ </td><td>”);
}
else {
# this is the first entry in the category
}
print(’<table border=”0″><tr><td align=”center”><a href=”‘);
print($linkarray[$thisKeyNext]);
print(’”><img src=”<$MTBlogURL$>/<$MTEntryCategory dirify=”1″$>/’);
print($morearray[$thisKeyNext]);
print(’/thumbs/thumb_’);
print($excerptarray[$thisKeyNext]);
print(’.jpg” width=”150″ height=”30″ class=”thumb” align=”middle” alt=”"’);
print($titlearray[$thisKeyNext]);
print(’"” /></a><br />next »</td></tr></table>’);
}
}
print(”</td></tr></table>”);
}
?>
>>> NOTES:
- The first two sets of bold lines are where you need to add other tags you will be using (i.e. $more, $excerpt, etc.). If you are not using $excerpt for instance, delete all those related lines.
- The last two sets of bold lines are the previous/next sections. The parts that will be most important to you are the ones in italic. That’s where everything will be written out that is contained in those tags.
- Since I’m using this for a photo section, it might look a little confusing with all the extra image-related tags. If I tried to remove something, I’d probably mess up the code, so I won’t. Besides, it might be helpful to other photo section users. You can take any print(”"); lines out that you won’t need (i.e. print(’/thumbs/thumb_’);).
- I inserted a table spread out within the code, so if you don’t need that, delete all table, tr, and td tags. If you miss one, your layout will probably look messed up. Or you can keep it, it’s to align the next/previous/current tags right.
*******************************************
INDIVIDUAL ENTRY ARCHIVE - ACTUAL IMAGE TAG (just for reference)
*******************************************
<img src=”<$MTEntryExcerpt convert_breaks=”0″$>.jpg” alt=”*<$MTEntryTitle$>*” class=”image” border=”1″><br /><br />
<$MTEntryBody convert_breaks=”0″$>
That’s that. If something looks odd, double-check that you didn’t miss any < > tags. If something isn’t clear, I’m around, just ask. Good luck!
May 26th, 2003 at 1:17 pm
Jael, thanks again. I was afriad that I’ve have to do something like that. BTW, your site has a great design.
June 6th, 2003 at 3:52 pm
Anybody know of a way to do this in ASP rather than PHP? It looks similar, but some of my templates use ASP variables. I guess I could learn PHP, but I’d rather be lazy and have someone who understands teh script above tell me what the ASP equivalents to the PHP arguments are. I’ll rewrite the script if I know that correlation and post it.
Nice scripting ladies…
June 6th, 2003 at 5:44 pm
Nevermind my last comment… I learned PHP in about an hour… well, all that I needed to know of it… It’s almost identical to ASP in structure, so it was easy to turn my site into PHP…
http://www.jaiandbecky.com/bg/
And the script is great, thanks Scripties!
July 2nd, 2003 at 10:48 pm
I haven’t yet tried this out, but I want to know if it could work with entries that are assigned to multiple categories. If so, how? Would the Indiv Arch Page have to have the prev and next links for all categories that the entry is in? How might that work? Or won’t it?
August 13th, 2003 at 9:52 pm
Has anyone taken this prev/next within a category idea and made a plugin? I’d rather not bother with php on the site I want to try it on.
August 16th, 2003 at 12:58 pm
I have a question about using this on my photoblog. I’ve read through all the comments but haven’t been able to assess if I can modify this to work with my blog.
My photo blog incorporates two types of entries; GENERAL and PHOTOS. General entries are only text/blog entries and the MT code causes only those entries to show up in a certain spot.
PHOTOS are all added and placed in the PHOTOS category. I have then added additional categories in the blog and assigned the photos MULTIPLE categories. That’s how I get just the PLANTS or CREATURES to show up on a single archive page alone.
But by setting up my blog this way when I attempt to implement this script it only sees the MAIN “photos” category”.
Is there a way to make this work with my current blog setup?
Thank you in advance for any help. I’ll continue to “play” with it on my own but I haven’t come up with a simple way to integrate it into the “multiple” categories as of yet.
Url of photoblog: http://digitalasylum.net/vieus/
December 2nd, 2003 at 5:22 pm
thanks for the great code. only one problem, the “next” button actually goes to a the previous photo and vice-versa. how can i change the code to fix this. i dont want to change the order in the mt config because i need it to be ascending for the thumnails page.
cheers
tom
January 2nd, 2004 at 6:42 am
Hi Lynda and Jenn,
thx for the great script, which I got immediatly working. But then I changed my blog with the plugin “dirifyplus” and I got the following problem (codes underneath):
Error message in the “include” line:
Parse error: parse error, unexpected ‘[' in /srv/www/htdocs/www.xento.net/wir/unsere-vergangenheit/neuseeland/cape-reinga/noch-ein-xenia-bild.php on line 57
"Array"-Template
<?
$a = 0;
$this_category = "<$MTArchiveCategory dirifyplus="sld"$>";
?>
<MTEntries>
<?
if ("<$MTEntryCategory dirifyplus="sld"$>"==$this_category) {
$<$MTArchiveCategory dirifyplus="sld"$>idarraytemp[$a] = “<$MTEntryID encode_php=”qq”$>”;
$<$MTArchiveCategory dirifyplus=”sld”$>linkarraytemp[$a] = “<$MTEntryLink encode_php=”qq”$>”;
$a++;
}else{
// do nothing
}
?>
</MTEntries>
Individual-Template (php only, comments removed)
<?
$thisCat = “<$MTEntryCategory dirifyplus=”sld”$>”;
if (!$thisCat == “”) {
include(”/srv/www/htdocs/www.xento.net/wir/unsere-vergangenheit/neuseeland/arrays/<$MTEntryCategory dirifyplus=”sld”$>.php”);
for ($i =0; $i < count($<$MTEntryCategory dirifyplus=”sld”$>idarraytemp); $i++) {
$idarraytemp[$i] = $<$MTEntryCategory dirifyplus=”sld”$>idarraytemp[$i];
$linkarraytemp[$i] = $<$MTEntryCategory dirifyplus=”sld”$>linkarraytemp[$i];
}
if ($idarraytemp >= 1) {
$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(’”>see the previous post in this category</a>’);
$previouslinkshown = “true”;
}
if ($thisKeyNext >= count($linkarray)) {
// do nothing
} else {
if ($previouslinkshown == “true”) {
print(” || “);
}
print(’<a href=”‘);
print($linkarray[$thisKeyNext]);
print(’”>see the next post in this category</a>’);
}
print(”<br>”);
print(”This current category is: “);
print(”<$MTEntryCategory$>”);
print(”</p>”);
} else {
// do nothing
}
}
Do you have any idea, what I’m doing wrong? You can see the “live” result here: Neuseeland 1999
Thanks in advance,
Tobias
July 31st, 2004 at 7:06 pm
I am building my site as explained by Brad Choate, ‘Doing your whole site with MT’ and would like to know if this script will work with Brad’s setup?