Archive for February, 2010

Manually adding Social Media links to a WordPress Theme

Friday, February 19th, 2010

Here’s a set of links to add your posts to Digg, Twitter, StumbleUpon, Del.icio.us, Facebook, MySpace, Google Bookmarks, Technorati, AddThis, and Reddit– I always end up needing these for themes I’m building, so I thought I’d pass them along!


<!-- Digg -->
<a href="http://digg.com/submit?url=<?php the_permalink(); ?>&title=<?php the_title(); ?>" rel="nofollow" title="Submit to Digg" target="_blank"><img src="<?php bloginfo('template_directory'); ?>/images/social/digg.gif" alt="Digg" title="Digg" /></a>
<!-- Twitter -->
<a title="Tweet About It!" href="http://twitter.com/home?status=<?php the_title(); ?> <?php the_permalink(); ?>" target="_blank"><img src="<?php bloginfo('template_directory'); ?>/images/social/twitter.gif" alt="Twitter" title="Twitter" /></a>
<!-- StumbleUpon -->
<a href="http://www.stumbleupon.com/submit?url=<?php the_permalink(); ?>&title=<?php the_title(); ?>" rel="nofollow" title="Stumble It!" target="_blank"><img src="<?php bloginfo('template_directory'); ?>/images/social/stumbleupon.gif" alt="StumbleUpon" title="StumbleUpon" /></a>
<!-- Delicious -->
<a href="http://delicious.com/save?url=<?php urlencode(the_permalink()); ?>&amp;title=<?php urlencode(the_title()); ?>" onclick="window.open('http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=<?php urlencode(the_permalink()); ?>&amp;title=<?php urlencode(the_title()); ?>', 'delicious', 'toolbar=no,width=550,height=550'); return false;" title="Bookmark this post on del.icio.us"><img src="<?php bloginfo('template_directory'); ?>/images/social/delicious.gif" alt="Delicious" title="Delicious" /></a>
<!-- Facebook -->
<a href="http://www.facebook.com/share.php?u=<?php the_permalink(); ?>" rel="nofollow" title="Share on Facebook" target="_blank"><img src="<?php bloginfo('template_directory'); ?>/images/social/facebook.gif" alt="Facebook" title="Facebook" /></a>
<!-- MySpace -->
<a href="javascript:GetThis('<?php the_title(); ?>','<?php the_excerpt(); ?>', '<?php the_permalink(); ?>')"><img src="<?php bloginfo('template_directory'); ?>/images/social/myspace.gif" alt="MySpace" title="MySpace" /></a>
<!-- Google Bookmarks -->
<a href="http://www.google.com/bookmarks/mark?op=edit&bkmk=<?php the_permalink(); ?>" rel="nofollow" title="Bookmark on Google" target="_blank"><img src="<?php bloginfo('template_directory'); ?>/images/social/google.gif" alt="Google Bookmarks" title="Google Bookmarks" /></a>
<!-- Technorati -->
<a href="http://technorati.com/faves?add=<?php the_permalink(); ?>" target="_blank"><img src="<?php bloginfo('template_directory'); ?>/images/social/technorati.gif" alt="Technorati" title="Technorati" /></a>
<!-- AddThis -->
<a class="addthis_button" href="http://www.addthis.com/bookmark.php?v=250&amp;username=xa-4b6908a945df8eb0"><img src="<?php bloginfo('template_directory'); ?>/images/social/addthis.gif" alt="Bookmark and Share" style="border:0"/></a><script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=xa-4b6908a945df8eb0"></script>
<!-- Reddit -->
<a href="http://reddit.com/submit?url=<?php the_permalink(); ?>" rel="nofollow" title="Submit to Reddit" target="_blank"><img src="<?php bloginfo('template_directory'); ?>/images/social/reddit.gif" alt="Reddit" title="Reddit" /></a>

In a WordPress theme, only show an element on the first page

Thursday, February 18th, 2010

I just had a colleague shoot me a quick question– he had a flash animated header that he wanted to only show up on the home page, so he wanted to know how he could keep it in the header, but only have it show up on that home page. Without further ado, here’s the code:

<?php if (is_home()) : ?>
<!-- Content to only show on the home page -->
<?php endif; ?>

Easily Add Twitter Status to any page with PHP

Tuesday, February 16th, 2010

Quick post– I found a lot of answers to this problem but none that really worked for me…

This will output your latest twitter status, converting any URLs or email addresses to clickable links:

function get_status($twitterid) {
$xml = @simplexml_load_file('http://twitter.com/statuses/user_timeline/'.$twitterid.'.xml?count=1');
if($xml->status) {
foreach($xml->status as $status){
$text = $status->text;
$text = html_entity_decode($text);
$text = " ".$text;
$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'<a href="\\1" target=_blank>\\1</a>', $text);
$text = eregi_replace('(((f|ht){1}tps://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'<a href="\\1" target=_blank>\\1</a>', $text);
$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'\\1<a href="http://\\2" target=_blank>\\2</a>', $text);
$text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})',
'<a href="mailto:\\1" target=_blank>\\1</a>', $text);
$text .= "<h4>Posted from $status->source</h4>";
}} else {
return 'Trouble in Twittersville, API not loading, sorry!';
}
return $text;
}

Then, to call it, just use this function:


get_status('YOUR_TWITTER_ID');

with your numerical Twitter ID in the obvious spot. You can find your Twitter ID by looking at the URL for your Twitter RSS feed, which will be:

http://twitter.com/statuses/user_timeline/YOUR_TWITTER_ID.rss

Powered by Olark