scriptygoddess

17 Apr, 2002

Category next/previous – Call for help…

Posted by: Jennifer In: Projects

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.

15 Responses to "Category next/previous – Call for help…"

1 | Lynda

April 17th, 2002 at 8:40 am

Avatar

I have an idea for something that *might* work, but it's 100% completely different than what you're trying here.

I'll see if I can get anywhere with it. heh.

2 | Lynda

April 17th, 2002 at 9:40 am

Avatar

Scrap my idea. :) Jenn, what isn't working with this? Is it getting the previous links? Because it *seems* to get the next links just fine (??)

I haven't played around with this as much as you have, so a little more detail as to what you think is going wrong would narrow the problem down.

I created something like this for my blog and I thought the array list looked weird. It certainly didn't list all my entries, is it supposed to? It seems to me if it doesn't, that would cause a problem.

I'll keep fiddling with it. More detail when you get a chance would be great.

3 | Jennifer

April 17th, 2002 at 9:48 am

Avatar

The script (as it is) is running right now. (no array's for projects – so check out a different post)

Each category seems to point to ONE entry with that link. As if there's only one entry in the array – or something…

I think when I try to transfer the array's into the generically named variables – it's not working… at least I think so.

I'm going to run a test on that categoryArray.php file to see what in fact is in those arrays…

4 | Lynda

April 17th, 2002 at 10:02 am

Avatar

I took this:

if ($thisKeyPrevious

and turned it into this:

if ($thisKeyPrevious > 0) {

and I at least got the previous link to show up. But it didn't point to anything. thisKeyPrevious should be greater than 0, no? GT and LT signs always confused me.

5 | Jennifer

April 17th, 2002 at 10:08 am

Avatar

HOLD THE PHONE!!! I think it's working…
instead of using that each($arrayname) thing… I just used a for loop to transfer the contents of the array…

Looks like it's working… yes?

(as for the greater than less than – I'm doing it a little sloppy – if it's LESS THAN Zero, I want it to print nothing… otherwise it should print the stuff… probably more efficiently would be to say if it's greater than or equal to zero – print the stuff)… let's see if that works…

6 | Jennifer

April 17th, 2002 at 10:23 am

Avatar

well…not entirely… we're getting closer… the bookmarks category is a little weird…
here's my test array page:
here

7 | Lynda

April 17th, 2002 at 10:32 am

Avatar

I only setup two categories to test this in my blog, Very Short Blips and Restricted. Both *seem* to be working:

here.

8 | Lynda

April 17th, 2002 at 10:40 am

Avatar

Why is the bookmarks category "a little weird" ?

When using the reverse array thing, I'm getting errors on any pages not setup with arrays. I even tried moving that !$abort line up and it didn't help.

Otherwise, of course, I get everything backwards. Maybe instead of reversing the array you can just switch around what is defined as "next" and "previous" ?

Probably not being any help at all. :)

9 | Lynda

April 17th, 2002 at 10:55 am

Avatar

Hmmm. Okay. I reversed the definition of Previous and Next and took out an error that was causing all my glitches (I had

if (!$abort=="true"); {

for some reason) and everything SEEMS to be fine.

Might be missing something.

10 | Jennifer

April 17th, 2002 at 10:58 am

Avatar

I think it's the multiple array issue…

I have a few posts that are MT hacks AND bookmarks… seems to be screwing things up…

check out that test page… you'll notice that some IDs are in ALL arrays! (??)

11 | Lynda

April 17th, 2002 at 11:19 am

Avatar

Perhaps when you use an MTCategories container, it spits out everything. If an entry has two categories, it's listed twice. That might be the problem.

Is there any other way to do it?

12 | Lynda

April 17th, 2002 at 11:27 am

Avatar

Would using an MTArchiveList container work? That way it would most assuredly only list the main category, as I use this for the "years past" script and include categories in that.

I just tried it and didn't see any noticable difference.

13 | Jennifer

April 17th, 2002 at 11:33 am

Avatar

OH LYNDA!!! I think that did it!!!! WOOOOHOOO!!!!

14 | Lynda

April 17th, 2002 at 11:35 am

Avatar

For the array reverse thing, I moved

if (!$abort =="true") {

ABOVE:

$idarray = array_reverse($idarraytemp);
$linkarray = array_reverse($linkarraytemp);

And that seems to work hunky-dory.

:-)

15 | Jennifer

April 17th, 2002 at 11:44 am

Avatar

…and so it does! This is awesome! I'll write up a tutorial on all this… (for those that are trying to play along! LOL!!)

The scriptygoddesses ROCK!!!!!

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements