Adding Content Under Your Post in a TwentyTen Child Theme

Over the weekend I installed Simple Twitter Connect (STC) and Simple Facebook Connect (SFC) here on VoodooPress.  They are my favourite plugins for total integration with each service.  And out of the box they work great.  You can have them just plop the ‘Like’ and ‘Tweet’ buttons under all your posts, and it works, and looks good.  But I’m picky.  I really only want my buttons manually placed exactly where I want them.  I’m using a twentyten child theme I made, and I wanted to insert the buttons only on single post views.  But I didn’t want to copy single.php from twentyten to use my own for just this.  I prefer to keep the original templates in use from the parent, and place any extra stuff through functions.php whenever possible.  I ran across several options, all of which worked in some fashion.  So let’s check out various ways to get content added under your post.  You can use the techniques here for pretty much any post, I’m just focusing on a twentyten child as that’s what I’m using.

The first thing I needed here was the code for displaying the buttons.  Otto provides plenty of guidance in the plugin backend for manually placing the Like and Tweet buttons.  So here is the code I was originally working with.  This was already all set up on my blog as we use the same plugins there.


	<?php if(function_exists('sfc_like_button')) : ?>
		<div class="fbConnect">
		<?php sfc_like_button(array('layout' => 'button_count')); ?>
		</div>
	<?php endif; ?>
	<?php if(function_exists('stc_tweetbutton')) : ?>
		<div class="twitConnect">
		<?php stc_tweetbutton(); ?>
		</div>
	<?php endif; ?>
	<div class="clear"></div>

So I knew I didn’t want to copy over any templates from the parent theme.  If I wanted to keep all templates intact and still be able to add this code to the templates, that left functions.php.  So my first thought was to get all my code inside a function which I could call later.  So here is the above code, all functioned out:


if ( ! function_exists( 'voodoo_social_buttons' ) ) :
//ADDS STC AND SFC BUTTONS
function voodoo_social_buttons() { ?>
	<?php if(function_exists('sfc_like_button')) : ?>
		<div class="fbConnect">
		<?php sfc_like_button(array('layout' => 'button_count')); ?>
		</div>
	<?php endif; ?>
	<?php if(function_exists('stc_tweetbutton')) : ?>
		<div class="twitConnect">
		<?php stc_tweetbutton(); ?>
		</div>
	<?php endif; ?>
	<div class="clear"></div>
<?php }
endif;

So now we have the code all ready to be used by simply calling out to voodoo_social_buttons.  That’s all well and good, but it doesn’t do anything for us.  The buttons still are not placed.  Now what?  Well, let’s look at a few options for actually including stuff under your content.  First up, is an old standby filter.  This works great for inserting stuff under your posts.  And you can adjust the conditional statement in there to match your needs, or get rid of it entirely.  But I didn’t like where it was positioning the text.  You can, of course, include some css in with your text to help styling and positioning.  So for some folks this is perfect, but not for me this time.


function voodoo_add_post_content($content) {
	if(!is_feed() && !is_home()) {
		$content .= '<p>This article is copyright &copy; '.date('Y').'&nbsp;'.bloginfo('name').'</p>';
	}
	return $content;
}
add_filter('the_content', 'voodoo_add_post_content');

The next thing I thought about is adding my buttons just above the comment form.  If you haven’t seen this article, check it out.  It’s a great article about using WordPress’ comment form from DevPress.  The hook that interested me here was the comment_form_before.  Seemed perfect.  So I tried it out.  It worked fine, but I still didn’t like the positioning.  Here’s the code in case you want something to show up there.


add_action( 'comment_form_before', 'voodoo_place_social' );

function voodoo_place_social() {
	echo '<div class="socialButtons">' . voodoo_social_buttons() . '</div>';
}

So I sat back and looked.  Adding the filter to the content as in the first example wasn’t quite right.  And neither was hooking on before the comment form.  One too high, one too low.  I wanted to have my buttons right above the meta that is displayed on single view in twentyten.  So I took a peek, and noticed that the meta was displayed using twentyten_posted_in, which was a function in the twentyten theme.  So I just grabbed that entire function and dropped in my function right at the top like so:


// COPY TWENTYTEN POSTED IN WITH OUR SOCIAL BUTTONS ADDED
function twentyten_posted_in() {
	voodoo_social_buttons();
	// Retrieves tag list of current post, separated by commas.
	$tag_list = get_the_tag_list( '', ', ' );
	if ( $tag_list ) {
		$posted_in = __( 'This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
	} elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
		$posted_in = __( 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
	} else {
		$posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
	}
	// Prints the string, replacing the placeholders.
	printf(
		$posted_in,
		get_the_category_list( ', ' ),
		$tag_list,
		get_permalink(),
		the_title_attribute( 'echo=0' )
	);
}

Real simple, just drop your function in right at the top. After making those edits, I tested my site, and everything was perfect. You can add a variety of things here if you like. In a future post I will be adding related posts functionality the very same way.

So now you have 3 different options for adding content under your post.  Which one you use depends on your needs.  But each of these works great, and allows you to add content to your posts in certain situations, safely in a child theme.  As I said earlier, these options are great for any theme, not just child themes.

2 Replies to “Adding Content Under Your Post in a TwentyTen Child Theme”

  1. Hi,

    I don’t seem to be getting this right, or am I?

    You added both these plugins to your site so that you could get the two buttons which are displayed in the “leave a reply box?”

    Is there not a plugin which detects you are a facebook user and displays your avatar/profile picture in the page, so when you go to answer a post it automatically sends it to facebook as well as posts it on your blog page?

    Would this not be:
    a) better value to the blogger for responses to posts?
    b) extremely viral?
    c) effective marketing?

    Surely, what I am saying is right, or has my imagination gone completely wold and something like this not already exist?

    Best
    Dora

    1. Actually I added these plugins so I could have a Like and Tweet button under the post content. So that users would be able to send my content off to either service. The login buttons in the reply box are a bonus.

Leave a Reply