March 25, 2003
MTPingEntry plugin for MT
I'd asked the MovableType support forum for a way to make use of Entry data within comments and ping containers. This to allow running a container loop over trackbacks and comments independent of categories or entries. Ben Trott posted up a code snippet on how to do it. Here's how you can use that code in your own site.
Your MT site has the ability to use plug-ins. If you're not using them already you'll need to create a directory.
First find where your system keeps it's mt.cgi script. You'll need to create a directory here named 'plugins'. If you're connecting to your site via FTP then 'cd' to the mt.cgi directory and 'mkdir plugins'.
Now that you know the directory exists you can put plugin scripts into it. You'll need to create a text file. You'll create this locally on your computer and then use FTP to put it up on your MT site. I created a file named pingentry.pl and put this text inside it:
##
#
# pingentry.pl
#
# code snippet from Ben Trott on the MT support board
# http://www.movabletype.org/support/
#
# wrapped up nice and neat like this by
# Bill Kearney
# http://www.ideaspace.net/users/wkearney
##
use strict;
use MT::Template::Context;
use MT::Trackback;
MT::Template::Context->add_container_tag(PingEntry => sub {
my($ctx, $args, $cond) = @_;
my $p = $ctx->stash('ping')
or return $ctx->_no_ping_error('MTPingEntry');
require MT::Trackback;
my $tb = MT:Trackback->load($p->tb_id);
my $entry_id = $tb->entry_id || return '';
require MT::Entry;
my $entry = MT::Entry->load($entry_id)
or return '';
local $ctx->{__stash}{entry} = $entry;
local $ctx->{current_timestamp} = $entry->created_on;
$ctx->stash('builder')->build($ctx, $ctx->stash('tokens'), $cond);
});
Save the file and then upload it via FTP to your MT site 'plugins' directory. Once that's done your MT site will automagically recognize it. Check your web server error_log just in case.
The above plugin lets you use Entry tags inside an MTPings container. I've made use of is like so:
The point of my using this container is to allow me to iterate over the pings themselves independent of entries.<MTPings lastn="15" sort_order="descend"> <h3 class="title"><a href="<$MTPingURL$>"><$MTPingTitle$></a></h3> <MTPingEntry><i>Re: <a href="<$MTEntryLink$>"><$MTEntryTitle$></a></i><br/></MTPingEntry> <$MTPingExcerpt$> <div class="posted">Pinged: <$MTPingDate language="en" format="%a, %d %b %Y %H:%M:%S"$> from: <$MTPingBlogName$></div> </MTPings>




