<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>My Corner &#187; widget</title>
	<atom:link href="http://blog.spencerkellis.net/tag/widget/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.spencerkellis.net</link>
	<description>An experiment in writing of life as I live it</description>
	<lastBuildDate>Sun, 27 Jun 2010 18:24:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>RSSPhoto: A WordPress Widget</title>
		<link>http://blog.spencerkellis.net/2009/08/rssphoto-a-wordpress-widget/</link>
		<comments>http://blog.spencerkellis.net/2009/08/rssphoto-a-wordpress-widget/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 02:22:45 +0000</pubDate>
		<dc:creator>Spencer</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[RSSPhoto]]></category>
		<category><![CDATA[widget]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://blog.spencerkellis.net/?p=277</guid>
		<description><![CDATA[I&#8217;ve made a WordPress widget called RSSPhoto that pulls images from photoblog RSS or Atom feeds and displays a thumbnail in the sidebar (I&#8217;m using it in my sidebar).  I mentioned the beginnings of this project a couple posts back.  That one was pulling images straight out of my database though.  This version is more [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve made a WordPress widget called RSSPhoto that pulls images from photoblog RSS or Atom feeds and displays a thumbnail in the sidebar (I&#8217;m using it in my sidebar).  I mentioned the beginnings of this project a couple posts back.  That one was pulling images straight out of my database though.  This version is more generic and uses the <a href="http://simplepie.org/">SimplePie</a> PHP library for parsing feeds.</p>
<p>Even though I say it pulls from photoblog feeds, really it can pull from any feed&#8211;it will just pull one of the images out of the content of a feed item.  I&#8217;ve used it to pull Flickr RSS feeds and a couple other random ones.  I also installed it easily on <a href="http://www.thesassylime.com">Emily&#8217;s blog</a>.</p>
<p>Check it out on my new Projects page (<a href="http://blog.spencerkellis.net/projects/rssphoto/">direct link</a>).  If you have a WordPress blog, try it out and let me know how your experience was.  I&#8217;d definitely appreciate any feedback.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.spencerkellis.net/2009/08/rssphoto-a-wordpress-widget/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Plugins and Widgets and WordPress&#8211;Oh my!</title>
		<link>http://blog.spencerkellis.net/2009/07/plugins-and-widgets-and-wordpress-oh-my/</link>
		<comments>http://blog.spencerkellis.net/2009/07/plugins-and-widgets-and-wordpress-oh-my/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 22:21:41 +0000</pubDate>
		<dc:creator>Spencer</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[identity crisis]]></category>
		<category><![CDATA[just one line of code]]></category>
		<category><![CDATA[Photography]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://blog.spencerkellis.net/?p=228</guid>
		<description><![CDATA[From my last post you know I&#8217;m trying to figure out the best configuration of my domain and subdomains.  I&#8217;m leaning toward the blog as my principal domain content with the photography blog as a linked subdomain. To sleep well at night with this change, I need a good way to interface my photography with [...]]]></description>
			<content:encoded><![CDATA[<p>From my last post you know I&#8217;m trying to figure out the best configuration of my domain and subdomains.  I&#8217;m leaning toward the blog as my principal domain content with the photography blog as a linked subdomain.</p>
<p><img class="alignleft size-full wp-image-254" title="sidebar" src="http://blog.spencerkellis.net/wp-content/uploads/2009/07/sidebar.jpg" alt="sidebar" width="100" height="275" /></p>
<p>To sleep well at night with this change, I need a good way to interface my photography with the blog.  After testing a few options, I decided to try developing a WordPress Widget to display the most recent photo.  It was surprisingly easy!  I thought I might document a bit about the design of a WordPress widget.  I know my audience (consisting mostly of family) has <em>really </em>been hoping for a technical article with some code to sink their teeth into.  Right?</p>
<p>To really understand widgets, you should play around with them first in your own admin section, under Appearance-&gt;Widgets.  You can drag and drop from available widgets to the sidebar or footer to define the contents of those areas of your blog.  You&#8217;ll notice when you drag a widget, a form appears with some fields to define.</p>
<p>On to creating a widget.  First, make a directory to hold all the plugin files in the <code>wp-content/plugins</code> directory.  Mine, for example, is <code>wp-content/plugins/skphoto/</code>.</p>
<p>Second, you need to define a class that extends WP_Widget, and includes a constructor function, widget function, update function, and form function.  This same file should also register the widget.  Here&#8217;s an outline of what that looks like:</p>
<pre name="code" class="php">class WidgetName extends WP_Widget
{
  /* constructor */
  function WidgetName() {}

  /* display the widget */
  function widget($args, $instance) {}

  /* save widget settings */
  function update($new_instance, $old_instance) {}

  /* edit form for the widget */
  function form($instance) {}
}

function WidgetNameInit()
{
  register_widget('WidgetName');
}
add_action('widgets_init', 'WidgetNameInit');</pre>
<p>See Jesse Altman&#8217;s <a href="http://jessealtman.com/2009/06/08/tutorial-wordpress-28-widget-api/">tutorial post</a> for details on these functions.</p>
<p>I do want to give a bit more information about the widget function.  If you want to access your MySQL database from within the widget function, you&#8217;ll need to add <code>global $wpdb;</code> to the top of your function.  Then, you can use standard WordPress <a href="http://codex.wordpress.org/Function_Reference/wpdb_Class">database functions</a> to pull data out.</p>
<p>Here&#8217;s the basics of my widget function for reference:</p>
<pre name="code" class="php">  function widget($args, $instance){
    global $wpdb;
    extract($args);
    $title = apply_filters('widget_title', empty($instance['title']) ? ' ' : $instance['title']);
    $feed_url = empty($instance['feed_url']) ? 'http://photography.spencerkellis.net/atom.php' : $instance['feed_url'];

    # Before the widget
    echo $before_widget;

    # The title
    if ( $title )
    echo $before_title . $title . $after_title;

    $sql = "SELECT `path` FROM `photos` ORDER BY `date` DESC LIMIT 1";
    $path = $wpdb-&gt;get_var($sql);
    echo "<img src=".$path." alt="" />";

    # After the widget
    echo $after_widget;
  }</pre>
<p>Finally, activate your new plugin in the WordPress Plugins section.  Then go back to the Widgets where the new widget will be available to drag and drop.</p>
<p>So there it is.  Easy-peezy, right?  Just a few lines of code, as I always like to say.  Here are a few resources if you want to explore on your own:</p>
<ul>
<li><a href="http://jessealtman.com/2009/06/08/tutorial-wordpress-28-widget-api/">Jesse Altman &#8211; Widget Tutorial</a></li>
<li><a href="http://wpengineer.com/wordpress-built-a-widget/">WP Engineer &#8211; Build a Widget</a></li>
<li><a href="http://codex.wordpress.org/Writing_a_Plugin">WordPress Docs &#8211; Writing a Plugin</a></li>
<li><a href="http://codex.wordpress.org/Function_Reference/wpdb_Class">WordPress Docs &#8211; Function Reference / wpdb Class</a></li>
<li><a href="http://codex.wordpress.org/Developer_Documentation">WordPress Docs &#8211; Developer Documentation</a></li>
</ul>
<p>So I&#8217;ll be looking for your thoughts.  What do you think about this solution for a home page?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.spencerkellis.net/2009/07/plugins-and-widgets-and-wordpress-oh-my/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

