tips and tricks for movable type

comment author web link plugin
July 07, 2002

Another plugin which adds a new tag to MT - posted by philringnalda in this support forum thread.

The new tag, MTCommentAuthorWebLink, gives you a linked URL if your commenter left one, or an unlinked "www" if they didn't.

Save as CommentAuthorWebLink.pl in your plugins directory:

use MT::Template::Context;
use MT::Util qw( remove_html );
MT::Template::Context->add_tag(CommentAuthorWebLink => sub {
my $tag = $_[0]->stash('tag');
my $c = $_[0]->stash($tag =~ /Preview/ ? 'comment_preview' : 'comment')
or return $_[0]->_no_comment_error('MT' . $tag);
my $url = defined $c->url ? $c->url : '';
remove_html($url);
$url ? "<a href=\"" . $url . "\">www</a>" : 'www';
});

Then insert <MTCommentAuthorWebLink> in your Comments Listing Template or Individual Archive Template where you want it to appear. Note that the tag should replace your entire link:

<$MTCommentAuthorWebLink$>

not

<a href="<$MTCommentAuthorWebLink$>">www</a>

Related links:

MT Manual on Plugins

Comments

Hi all I just added a little hack in the code to let you put some an other text than "www" as link.

Here is what it looks like now :

use MT::Template::Context;
use MT::Util qw( remove_html );
MT::Template::Context->add_tag(CommentAuthorWebLink => sub {
  my ($ct, $args) = @_;
  my $tag = $_[0]->stash('tag');
  my $c = $_[0]->stash($tag =~ /Preview/ ? 'comment_preview' : 'comment')
  or return $_[0]->_no_comment_error('MT' . $tag);
  my $url = defined $c->url ? $c->url : '';
  remove_html($url);
  $urltext="www";
  $urltext=$args->{'atext'} if defined $args->,{'atext'};
  $url ? "<a href=\"" . $url . "\">" . $urltext . "</a>" : '';
}); 

To specify a text othen than "www", add a "atext" attribute, like this :

<$MTCommentAuthorWebLink atext="web link" $>

by n`rs_ | 04.13.03 02:40 AM

how do i have it so that the MTCommentAuthorLink always links to the emaila address? i've implemented the "(www)" link to the comment author's website, but the author name also points to the website, making the "(www)" redundant. i tried adding show_email="1" show_url="0" to the tag (i assume setting show_email to "1" means setting it to "yes"), but it still doesn't work for me.

by peter | 05.10.03 08:14 PM

If you always want to link to the email address, then use MTCommentEmail - you'll have to construct the link yourself though.

<a href="mailto:<MTCommentEmail spam_protect="1">"><MTCommentAuthor></a>

Does that help?

by girlie | 05.10.03 09:07 PM

cool! worked like a charm! thanks for the quick response too!

by peter | 05.10.03 10:29 PM

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

TrackBack: 0
(URL: http://www.thegirliematters.com/sf/mt-track.cgi/51)