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.
Further Reading on Blogging
- Pruning blog posts from syndication feeds
- How to create a Twitter book reading list
- Blog conference in Indiana, mid-August
Further Reading on PHP
- Hiding an email address from spambots and spiders
- Gallery2 titles and keywords search engine optimization script
- Features and characteristics of a great 404 error page





