Extending Movabletype

[list] [*] Prev/Next Links within Category

[*] Position of Individual Archive in Category

[*] List Total Number of Entries in Category

[/list]

i.e Have Entry #x of Total Entries in that category, and previous/next links within category. Usefull for photoblogs.


[b]Step 1[/b]

In the template section, click “Create new archive template” (near the middle of the page). Call this template something like Entry Numbers. In the template body place the following text exactly as it appears:

[code]

<$MTEntryID$>

[/code]

[b]Step 2[/b]

For the time being, there needs to be two archive templates. Later on only one will be required. Once again, in the template section, click “Create new archive template” (near the middle of the page). Call this Entry PermaLinks. In the template body place the following text exactly as it appears:

[code]

<$MTEntryPermalink$>

[/code]

[b]Step 3[/b]

For the two new templates we created above, we now have to tell MT that they are category archives, and give MT a path and filename for them. Go to Weblog Config, Archiving.

Click on “Add new”. Select “Category” as the Archive type, and in the template select the new template (Entry Numbers) we just created. Click Add. Now copy the following into the text field next to the new archive template:

[code]<$MTArchiveCategory dirify="1"$>/numbers[/code]

Click on “Add new”. Select “Category” as the Archive type, and in the template select the new template (Entry PermaLinks) we just created. Click Add. Now copy the following into the text field next to the new archive template:

[code]<$MTArchiveCategory dirify="1"$>/links[/code]

For this method to work, the cateogry and the individual archive pages have to be save in the form: http”//mysite.com/categoryname/filename. So in Weblog Config: Archiving, put the following:

For the Individual Archive template:

[code]<$MTEntryCategory dirify="1"$>/<$MTEntryTitle dirify="1"$><$MTEntryID$>.php[/code]

For the Category Archive template:

[code]<$MTArchiveCategory dirify="1"$>/index.html[/code]

You can see this archiving in use [url=http://offroadpakistan.com/pictures]over here[/url]. For more on archiving, see [url=”http://www.emptypages.org/more/tips/archive_file_templates.html”]archive file templates [tips][/url] and the MT manual.

[b]Step 4[/b]

This code goes at the top of the individual archive template exactly as it appears.

[code] )

{ $position=$i+1;

if ($i>0){$p=$links[$i-1];} else{$p=”0″;}

if ($i+1<$total_lines) {$n=$links[$i+1]; } else {$n="0";} } } //end for loop function _prev($p="0"){ if ($p=="0") {echo "---";} else {echo "« prev“; } }

function _next($n=”0″){

if ($n==”0”) { echo “—“;} else {echo “next »“; } }

?>

[/code]

[b]Display on page[/b]

Now the framework is in place. To display on the page, put the following code exactly as it appears whereever you want it to be diplayed.

Display number of the entry:

[code] [/code]

This just prints a number. i.e if there are 20 entries in that category and you’re viewing entry 4, this will print 4. I use it to display: Picture 4 of 20.

Prints a link to the next entry:

[code] [/code]

Prints a link to the previous entry:

[code][/code]

This is the code I am using to display the total number of entries in that category (on the individual page):

[code] MTCategoryCount[/code]

OR

[code] [/code]

I am using this script at the 4×4 Offroaders Club Karachi’s [url=http://www.offroadpakistan.com/pictures]picture gallery[/url]. Click on a picture to see it in effect.

Also see [url=http://www.scriptygoddess.com/archives/000902.php]Scriptygodess :: How to’s: Next/Prev Links Specific to Categories in MT – v.2[/url] I found it after I had already written most of this script.

Note: In the next version, only one archive template will be required instead of two.

Update: There is now a [url=http://philringnalda.com/blog/2004/02/previous_and_next_in_category.php]plugin available[/url] which gives previous and next in category tags. It’s missing one thing though, the ability to have numbers on entires – example entry x of 23, and also has a few other bugs. Hopefully MT 3.0 will include such funtionality builtin.

One thought on “Extending Movabletype”

Leave a Reply