SideBlog changes: remove titles, link post content

As you already know, I post all my non-reply tweets from Twitter on my personal blog with Twitter Tools. I do not display the posts with the Twitter Tools widget, but with SideBlog. With SideBlog you can place all posts from a particular category in the sidebar. I have chosen to show only my “Tweets from Twitter” category. The original output of SideBlog places a title, post content and a permalinked “#” at the end of the post. This wasn’t minimalistic enough, and on top of that with Twitter Tools the first 40 characters of your content is your title, so you are repeating yourself. I don’t care for the pound sign, “#”, either. So I made the following changes to the plug-in.

Edit One
This edit comments out all the SideBlog plug-in’s output except for the permalink and the content. You will find this code within SideBlog 5.1 at about line 170 within the function, sideblog($asidecategory=”).

// smjdesign BEGIN edit
$replacements[] = $sideblog_content->post_title;
// $replacements[] = wpautop($sideblog_content->post_content);
// $replacements[] = "<a href=\"" . $permalink . "\">#</a>";
$replacements[] = "<a href=\"" . $permalink . "\">"
.format_if_content_contains_link($sideblog_content->post_content);
// $replacements[] = "<a href=\"" . $permalink . "\" title=\""
.$sideblog_content->post_title . "\">"
.$sideblog_content->post_title . "</a>";
// $replacements[] = $sideblog_content->post_date;
// $replacements[] = "<a href=\"" . $permalink . "\">"
.$sideblog_content->post_date . "</a>";
// $replacements[] = $excerpt;
// $replacements[] = $excerpt2;
// smjdesign END edit

Edit Two:
Place the function, format_if_content_contains_link(), within sideblog.php. I have placed around line 200 after function, sideblog(). This function tests to see if the post content contains a link. There are better (non Regular Expression) ways to do this with PHP5. This function is needed to make content that contain links valid HTML (or XHTML). If not used, links tags will encapsulate other links tags.

// smjdesign BEGIN edit
function format_if_content_contains_link($content) {
	if( substr($content, strlen($content)-4 , 4) == "</a>" ) {
		$content_arr = split("<a href",$content);
		$content = preg_replace( "/<a href/", "</a><a href", $content, 1);
	}
	else {
		$content .= "</a>";
	}
	return ($content);
}
// smjdesign END edit

You can view the output of these changes in the sidebar at my personal site, Rachel and Stephen.

How to keep SideBlog posts within your post query

I noticed that quite a few people are discovering this page by wanting to NOT exclude “SideBlog categories” from the general post query (i.e.- from index.php). To do that, you will want to remove/comment out the filter:

add_filter('pre_get_posts','sideblog_post_filter');

from the sideblog.php plugin file. I like to include my "SideBlog category" within the general listing, since these are asides or mini-posts.

If you have found this post valuable, please share it with others: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Facebook
  • del.icio.us
  • Google
  • StumbleUpon
  • TwitThis

A note about the author

Photograph of Stephen JamesMedia designer with experience in interactive, print and video. I have a marketing and advertising agency background and currently work full-time at a full-service agency. Visit my contact page, even if you would just like to say hello. To stay in touch, follow me on Twitter or connect on a variety of other social networks. Thanks for stopping by!

Leave a Reply


Books Now Reading

My Sites