Forums

Plugin: Twitpic Expander (5 posts)

  1. bh
    Member
    Posted 3 months ago #

    Hey Guys,

    I just threw together my first plugin. I am using Twitter Tools to pull in a Twitter feed into Wordpress. It was perfect for my needs except for one thing - I wanted Twitpic URL's to display as an image instead of the link URL. I mostly borrowed code from different places, but it works. I am posting it here just in case it helps someone. If anyone wants to improve the code I would be super grateful! (I am not a programmer, so please excuse any obvious mistakes)

    Cheers

    <?php
    /*
    Plugin Name: Twitpic Expander
    Plugin URI: http://jacksonlaycock.com/
    Description: Scans posts for twitpic URL's and automatically expands them and shows an image.
    Version: 1.0
    Author: Jackson Laycock
    Author URI: http://jacksonlaycock.com/
    */
    ?>
    <?php
    // borrowed code from http://code.google.com/p/dabr/source/browse/trunk/common/twitter.php?spec=svn116&r=116
    
    function showtwitpic($text){
    	$foo = $text;
    	$tmp = strip_tags($text);
    	// find a mention of twitpic
    	if (preg_match_all('#twitpic.com/([\d\w]+)#', $tmp, $matches, PREG_PATTERN_ORDER) > 0) {
    		foreach ($matches[1] as $match) {
    	     $text = "<a href='http://twitpic.com/{$match}'><img src='http://twitpic.com/show/large/{$match}' class='aligncenter' /></a>";
    	  	}
    		$text = $foo . $text;
    	}	
    
    	return 	$text;
    }		
    
    add_filter('the_content', 'showtwitpic', 21);
    add_filter('the_excerpt', 'showtwitpic', 21);
    ?>
  2. alexkingorg
    Member
    Posted 3 months ago #

    Pretty cool, you should make this a plugin for Twitter Tools so it works in the sidebar too.

  3. bh
    Member
    Posted 3 months ago #

    Thanks Alex. I would love to, but I might have to pass the torch on this one.

    Thanks again for such a great WP/Twitter Plugin!

  4. vuthy
    Member
    Posted 2 months ago #

    Thanks, this is just what I'm looking for though for some reason, if a post has more than one twitpic link, only the last one gets its picture displayed. I'll try to see if I can figure this out.

    Thanks for the code!

  5. bh
    Member
    Posted 1 month ago #

    Hey Vuthy,
    Did you figure out the code and make any changes?

Reply

You must log in to post.

About this Topic