This is The World According to Buchs - Keepin’ it moving since 2003!

MT != PHP

So this whole website thing is a work in progress. As I have the time, I try to add features or tweak things. The latest update I’m trying to make is the addition of sortable archive list pages. I’d like to have my category list pages be sorted by a user-defined variable. Put simply, a table that you can sort by clicking a column header - title, date, number of comments, etc.

The problem

MovableType generates static HTML code. There’s no interaction with the database as the page is written.

Solutions?

My first attempt was to use a plugin that allowed me to pass a SQL query to the database - MTSql. I quickly realized that, although I was able to define a sort order for my queries, I was still limited to a single, static page. I needed to be able to pass a post or get variable to the page, which would then modify the query being ran, and return the updated recordset.

Next, and this is where I’m at now, is to use MT to generate the page shell, but use PHP within the page to query and display the results on my own. This approach has got 2 problems:

# There’s no way (that I can find) to access the MT values within PHP. Specifically, I need to get the MTCategoryID into PHP. I’m unable to place a MT tag within a PHP block - it’s being rendered as {{MTCategoryID}} when the page is written, instead of “18″. So, as a workaround, I’m passing the ID in the URL string. That’s a pain in the ass, which requires every reference to a category archive page to be updated in my templates.
# Even though I’ve hacked a way to get the result I want, I still need to manually format all the output. Not a big deal… with the exception of the link itself. My links are formatted like “/archives/year/month/day/title_of_article/”. So, I’ve got to write a function to do that - because I can’t find a way to access that MT method from PHP.

Updated!

I guess it pays to be persistent. I did some digging around… when the Dyanmic Publishing engine translates a page, it saves a cached version to the “/templaces_c/” directory. I opened up one of those, and pulled out the MT-Php Smarty function calls I needed! Specifically: smarty_function_MTCategoryID(array(), $this); I’ll try and write some documentation on what exactly I did, and post the templates I created.

Very exciting!

This entry was posted on September 16, 2004 at 5:43 pm, filed under web and tagged , . Bookmark the permalink. Follow any comments here with the RSS feed for this post. Trackbacks are closed, but you can post a comment.

Comments

4 Comments

  1. Finally, I’ve been waiting so long for you to write about MT, PHP and smarty functions. You’re the best, Bryan!

    Posted September 17, 2004 at 9:51 am by Chuck .

  2. I’m not the phony, you’re the phony.

    Posted September 17, 2004 at 10:36 am by Bryan Buchs .

  3. WOW, thanks for making me feel like a completely incompent computer person!

    Posted September 17, 2004 at 4:51 pm by Up North Princess .

  4. I don’t know if you had a chance to read over it, but we’ve published two tutorials on our PHP support in MT that might explain this a little better:

    http://www.sixapart.com/pronet/2004/09/php_dynamic_pub.html

    http://www.sixapart.com/pronet/2004/11/php_dynamic_pub_1.html

    Posted December 10, 2004 at 8:47 pm by Anil Dash .

Respond

Leave a comment. Your email is never published nor shared. Required fields are marked *

  • Recent commentsNone Found