Thesis Hook Example 2: Adding Social Bookmarking Icons
This hook will show you how to add some social bookmarking or social media buttons to the bottom of only your single post pages (the actual page your full, individual blog post lives on) like my site does.
Step 1: Upload the graphics you want to use to link to the social sites (if applicable) to the custom images folder (thesis > custom > images > put your images here)
Step 2: Open your custom_functions.php file (thesis > custom > custom_functions.php) in your favorite editor
Step 3: Underneath the example code already in the file, place the following code (this code assumes your blog is in the root and is to place Stumbleupon, Digg, Delicious and a link to your RSS at the bottom of each individual post on your blog):
/* Custom Social Media After Post Hook */
function add_social_media () {
if (is_single()) {
?>
<p><a href="http://www.stumbleupon.com/submit?url=<?php the_permalink() ?>"><img src="THE_URL_OF_YOUR_STUMBLE_GRAPHIC"></a><a href="http://digg.com/submit?phase=2&URL=<?php the_permalink() ?>"><img src="THE_URL_OF_YOUR_DIGG_GRAPHIC"></a><a href="http://del.icio.us/post?url=<?php the_permalink() ?>&title=<?php the_title(); ?>"><img src="THE_URL_OF_YOUR_DELICIOUS_GRAPHIC"></a><a href="http://www.linktoyourfeedhere.com"><img src="THE_URL_OF_YOUR_STUMBLE_GRAPHIC"></a></p>
<?php
}
}
add_action('thesis_hook_after_post', 'add_social_media');
Same as before, the /* Stuff Inside Here */ is a label for the code below so you know what it is at a single glance. This is not part of the actual “code”. The word “function” tells Thesis you want it to do something. The add_social_media is what I decided to name that function.
The if (is_single()) is a conditional tag that basically tells Thesis to only use that function if the page is the single post page. If I changed it to be is_category() it would only run this function on category pages. You can find a full list of conditional tags here. If you wanted to change this to show the social bookmarking buttons on every page of the site, you’d remove the (is_single()) and the following { and later } like so:
/* Custom Social Media After Post Hook */
function add_social_media () {
?>
<p><a href="http://www.stumbleupon.com/submit?url=<?php the_permalink() ?>"><img src="THE_URL_OF_YOUR_STUMBLE_GRAPHIC"></a><a href="http://digg.com/submit?phase=2&URL=<?php the_permalink() ?>"><img src="THE_URL_OF_YOUR_DIGG_GRAPHIC"></a><a href="http://del.icio.us/post?url=<?php the_permalink() ?>&title=<?php the_title(); ?>"><img src="THE_URL_OF_YOUR_DELICIOUS_GRAPHIC"></a><a href="http://www.linktoyourfeedhere.com"><img src="THE_URL_OF_YOUR_STUMBLE_GRAPHIC"></a></p>
<?php
}
add_action('thesis_hook_after_post', 'add_social_media');
The rest of the code is the traditional HTML code you’d use to add those bookmarking buttons to your theme normally.
The add_action(’thesis_hook_after_post’, ‘add_social_media’); line tells Thesis that you want it to add a function after the post content and the function you want to add is the one we created – the add_social_media function.
No comments:
Post a Comment