Help - Search - Members - Calendar
Full Version: entry x of y
Movable Type Community Forum > Additional Resources > Tips and Tricks
Bostich
I'd like to do a "seemingly" simple thing, have a little "x of y" item on each individual archive page.

Is there an easy way to do this?

Right now I'm thinking I need to ditch the built in MT archiving structure completely and do it all in php/MySQL ? (does someone have an example of that?)

Assume all messages are in a single category, but there are multiple categories so the numbers for each entry won't be sequential.

thanks,
john.,
girlie
Do you have only one blog or multiple blogs?

I'm wondering if this would work:

CODE
<MTEntryID> of <MTBlogEntryCount>


I don't know how "true" that would be with MTEntryID though, since the IDs are added sequentially regardless of entry date and across all blogs.
kadyellebee
I've done entire index pages with MySQL but not all the archives.  It seemed like it would be a bit harder to deal with dynamically generated pages for every archive.

I think overall, girlie's suggestion is the best.

You'd want your newest entry to show like entry 305 of 305?  and then each would be lower?  I have an idea of how I'd do it on the index page - you could do something like this:
CODE
<? $count=<$MTBlogEntryCount$>;
$total=<$MTBlogEntryCount$>; ?>
<MTEntries>
<? echo $count of $total?>
MTTags here
<? $count=$count-1; ?>
</MTEntries>


I think that would make it less for each entry on the page, because it would make it less than one for each entry, and then when it started to generate the next entry, it wouldn't go back to the top of the page, just the top of the inside of the MTEntries tag.

I didn't test this out, its kinda just in the theoretical state in my mind.  I'll think some more on it.  I think there should be a MySQL way to pull it out, but I'm not quite sure how.  I know that mysql_num_rows will give you the count of all of the rows in a certain SELECT statement, but I haven't ever tried to get it to tell me which row number that I'm on in a foreach statement.  I'm sure there's a way, though! smile.gif

Kristine
Bostich
Multiple Blogs (4) .. Thanks for the suggestions:

Yeah, I know there must be a way with SQL.. I'll try these MT based solutions out and let ya know.

I don't want to show the MTEntryID, because for example the first post in this new blog is MTEntryID=456, but really it needs to be 1.

john.,
kadyellebee
I wonder if you could set up some sort of secondary table in the mysql database that would automatically generate a row number for each post on that blog.  Maybe have it also have the entry_id in it so that then your query would be easy to construct on each individual page.  Otherwise, I'd think it would be a lot of processing just to get the row number on each page.

I'll keep thinking, but that was my brainstorm on rereading this morning smile.gif

Kristine
Bostich
I was thinking I could maybe make an include file (.inc or .js) that was an MT archive index listing which would build itself into a javascript or PHP array and work through that, where MTEntry ID == the MTEntryID in the array, then:

(pull out the number of that entry from the array) of (total number of elements in array)

Seems remotely plausible, and it would just update that array whenever I add an entry.

john.,
kadyellebee
Oh, yeah, that seems like it would work - Post back when you get it working - I'd love to hear how it all works out! smile.gif

Kristine
Bostich
The following works really well:

I found some code for dynamic image galleries over at Dynamic Drive, which contains a small page numbering function that works cross-browser.

FIRST I take the part I needed and modified it thusly:

CODE
/*
MT Archive Page Numbering by John Fairley (john@bostich.com) based on:

Interactive Image slideshow with text description
By Christian Carlessi Salvadó (cocolinks@c.net.gt). Keep this notice intact.
Visit http://www.dynamicdrive.com for script
*/

g_iimg = 0;
g_imax = 0;
g_PageTable = new Array();

<MTArchiveList>g_PageTable[g_imax++] = new Array ("<MTEntries><$MTEntryID$></MTEntries>");</MTArchiveList>

function getobject(obj){
if (document.getElementById)
return document.getElementById(obj)
else if (document.all)
return document.all[obj]
}

function setPageNumber(myPage){

var inputPage = myPage;

for (var i = 0; i < g_PageTable.length; i++) {
    if (inputPage == g_PageTable[i][0]){
    g_iimg = i;
    }
}

getobject("_Ath_Img_X").innerHTML = g_iimg + 1;
getobject("_Ath_Img_N").innerHTML = g_imax;
}


Make it a new Index Template, with a .js extension.

SECOND Include it like any other .js file in your archive template, and add the following onLoad event to the template:

CODE
<body "setPageNumber(<$MTEntryID$>);">


FINALLY Add the following SPANs to your archive tempalte:

CODE
<SPAN id="_Ath_Img_X"></SPAN>
<SPAN id="_Ath_Img_N"></SPAN>


------------------------------------------------
All this just compares the MTEntryID's of the page and Array, and spits out the numbers.

Seems to work fine, and of course it's auto-updating everytime you publish a new page.



john.,
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.