Although most of my blogging is done here, on Wonko’s World, I also author the West Midlands NO! Campaign blog and sometimes post on the Campaign for an English Parliament blog.
It’s common for bloggers who write on collaborative blogs to cross-post the same article on both their own blog and the collaborative blog they write on but what do you do about the comments? You might not necessarily want to have two seperate sets of comments on the same post. You can turn off the comments and put a link in the bottom of the post to the other post but they rarely get clicked.
Today I had a brainwave – add a metadata item with the url of the other post and change the comments link when the post is displayed. So, I tried it and it works and this is how to do it …
First up is the main index page of the blog. Open the index.php file and find comments_popup_link – this is the function that displays the comments link. The line should look like this:
<?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?>
Change it to this:
<?php
$xpostcommentsurl=get_post_meta($post->ID, "xpost", $single=true);
if(strlen($xpostcommentsurl)>0)
{
echo '<a href="'.$xpostcommentsurl.'" target="_blank">Comments</a> (off-site)';
}
else
{
comments_popup_link('No Comments', '1 Comment', '% Comments');
}
?>Next we have to change the single post file – it should be called single.php. Open it and look for comments_template. The line should look like this:
<?php comments_template(); ?>
Change it to this:
<?php
$xpostcommentsurl=get_post_meta($post->ID, "xpost", $single=true);
if(strlen($xpostcommentsurl)>0)
{
echo 'This entry has been cross-posted from another site.';
echo 'Click <a href="'.$xpostcommentsurl.'" target="_blank">here</a> to open the comments page for this post.';
}
else
{
comments_template();
}
?>
One you’ve made these changes, everything is ready. When you write your post, scroll down the page to Custom Fields and add an entry named "xpost". Give it a value of the url of the cross-post you want the comments to appear on and save. Simple as that!
Leave a Reply