Using a Keyword Plugin with Google Blog Bar

As much as I love the functionality of the Google Blog Bar in my blog, there is a limitation. Since my code to add the Blog Bar uses the post’s category for the keyword search, if the category is something like “Miscellaneous Musings/Moments“, there will be no results because the Blog Bar searches through the post’s content, and ignores the category.

I decided to find a WordPress plugin that would enable me to apply tags to my posts. Tags are better than categories when the number of posts don’t warrant having a category for the posts. Also, I don’t have to display the tags so there won’t be clutter.

I decided upon Jerome’s Keywords Plugin because it is possible to use the categories that I have already assigned to the posts. I didn’t want to have to go back and enter keywords for all my posts.

There will still be posts that don’t have blog bar results, but this new functionality allows me to have more flexibility with what results should show up.

If you want to use the Blog Bar in the same way that I am:

  1. Install Jerome’s Keywords Plugin
  2. Follow instructions in my blog post, Added Google Blog Bar to Individual Posts
  3. Replace the blogbar.inc.php code in the previous step with the following:
<?php
/* Only edit the variables here */
$key = 'YOUR-API-KEY';
$site = 'http://yoursite.com/blog/';
/* end of editable portion */
function the_category_plain($separator = '', $parents='') {
	echo '"' . strip_tags(get_the_category_list($separator, $parents)) .'"';
}
?>
<div>
<h2>Google Blog Bar</h2>
<p>The blog bar presents posts from my blog with related keywords. If none are found, Google posts are displayed.</p>
<!-- ++Begin Blog Bar Wizard Generated Code++ -->
  <!--
  // Created with a Google AJAX Search Wizard
  // http://code.google.com/apis/ajaxsearch/wizards.html
  -->

  <!--
  // The Following div element will end up holding the actual blogbar.
  // You can place this anywhere on your page.
  -->
  <div id="blogBar-bar">
    <span style="color:#676767;font-size:11px;margin:10px;padding:4px;">Loading...</span>
  </div>

  <!-- Ajax Search Api and Stylesheet
  // Note: If you are already using the AJAX Search API, then do not include it
  //       or its stylesheet again
  //
  // The Key Embedded in the following script tag is designed to work with
  // the following site:
  // http://yoursite.com/blog/
  -->
  <script src="http://www.google.com/uds/api?file=uds.js&v=1.0&source=uds-blbw&key=<?php echo $key ?>"
    type="text/javascript"></script>
  <style type="text/css">
    @import url("http://www.google.com/uds/css/gsearch.css");
  </style>

  <!-- Blog Bar Code and Stylesheet -->
  <script src="http://www.google.com/uds/solutions/blogbar/gsblogbar.js?mode=new"
    type="text/javascript"></script>
  <style type="text/css">
    @import url("http://www.google.com/uds/solutions/blogbar/gsblogbar.css");
#blogBar-bar a img {
	border: none;
}  </style>

<?php
/* use in the loop
ttt: modified version of the_post_keytags() from Jerome's keyword plugin
*/
function post_keytags($include_cats=false, $localsearch=true, $linktitle=false) {
	$taglist = get_the_post_keytags($include_cats, $localsearch, $linktitle);

	if (empty($taglist))
		return "none";
	else
		return ucwords(strip_tags($taglist));
}
$keywords = post_keytags('include_cats');
$keywords_list = eregi_replace ( ', ', "', '", $keywords);
?>
  <script type="text/javascript">
    function LoadBlogBar() {
      var blogBar;
      var options = {
	    siteRestriction : "<?php echo $site ?>",
        largeResultSet : true,
        title : "Related Posts",
		cycleTime : GSblogBar.CYCLE_TIME_LONG,
		currentResult : document.getElementById("currentResult"),
        horizontal : true,
        orderBy : GSearch.ORDER_BY_RELEVANCE,
        autoExecuteList : {
          executeList : [<?php echo "'" . $keywords_list . "'" ?>]
        }
      }

      blogBar = new GSblogBar(document.getElementById("blogBar-bar"), options);
    }
    // arrange for this function to be called during body.onload
    // event processing
    GSearch.setOnLoadCallback(LoadBlogBar);
  </script>
  <div id="currentResult">Loading</div>
<!-- ++End Blog Bar Wizard Generated Code++ -->
</div>

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>