<?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/"
	xmlns:media="http://search.yahoo.com/mrss"
>

<channel>
	<title>Deep Thoughts by Robert Felty &#187; sql</title>
	<atom:link href="http://blog.robfelty.com/category/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.robfelty.com</link>
	<description>thoughts on wordpress, latex, cooking et alia</description>
	<lastBuildDate>Tue, 22 Jun 2010 19:59:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Showing total number of replies in bbpress</title>
		<link>http://blog.robfelty.com/2010/04/09/showing-total-number-of-replies-in-bbpress/</link>
		<comments>http://blog.robfelty.com/2010/04/09/showing-total-number-of-replies-in-bbpress/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 21:36:59 +0000</pubDate>
		<dc:creator>robfelty</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[bbpress]]></category>

		<guid isPermaLink="false">http://blog.robfelty.com/?p=662</guid>
		<description><![CDATA[For awhile now I have been wanting to show the total number of topics started and replies in a bbpress forum on the profile page. Today I finally figured out how. I like bbpress quite a bit, as it integrates very nicely into wordpress. The main downside of bbpress right now is that the documentation [...]]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_663" class="wp-caption alignleft" style="width: 260px"><a href="http://blog.robfelty.com/2010/04/09/showing-total-number-of-replies-in-bbpress/totalreplies/" rel="attachment wp-att-663"><img src="http://blog.robfelty.com/wp-content/uploads/2010/04/totalReplies-250x189.png" alt="showing total number of replies on a bbpress profile page" title="totalReplies" width="250" height="189" class="size-medium wp-image-663" /></a><p class="wp-caption-text">showing total number of replies on a bbpress profile page</p></div> For awhile now I have been wanting to show the total number of topics started and replies in a bbpress forum on the profile page. Today I finally figured out how. I like bbpress quite a bit, as it integrates very nicely into wordpress. The main downside of bbpress right now is that the documentation is still basically nonexistent. Maybe someday I will help out with it. </p>
<div style='clear:both'></div>
<p>Anyways, to get the total number of replies, simply use the following little mysql query:</p>
<div class="codecolorer-container php dawn" style="overflow:auto;white-space:nowrap;width:100"><div class="php codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw2">&lt;?php</span><br />
<span class="kw3">global</span> <span class="re0">$bbdb</span><span class="sy0">;</span><br />
<span class="re0">$totalReplies</span> <span class="sy0">=</span> <span class="re0">$bbdb</span><span class="sy0">-&gt;</span><span class="me1">get_var</span><span class="br0">&#40;</span><span class="st0">&quot;SELECT COUNT(post_id) FROM &quot;</span> <span class="sy0">.</span><br />
<span class="re0">$bbdb</span><span class="sy0">-&gt;</span><span class="me1">prefix</span> <span class="sy0">.</span> <span class="st0">&quot;posts WHERE poster_id=<span class="es4">$user-&gt;ID</span>&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="sy1">?&gt;</span></div></div>
<p>To get the total number of topics started, use:</p>
<div class="codecolorer-container php dawn" style="overflow:auto;white-space:nowrap;width:100"><div class="php codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw2">&lt;?php</span><br />
<span class="kw3">global</span> <span class="re0">$bbdb</span><span class="sy0">;</span><br />
<span class="re0">$totalTopics</span> <span class="sy0">=</span> <span class="re0">$bbdb</span><span class="sy0">-&gt;</span><span class="me1">get_var</span><span class="br0">&#40;</span><span class="st0">&quot;SELECT COUNT(topic_id) FROM &quot;</span> <span class="sy0">.</span><br />
<span class="re0">$bbdb</span><span class="sy0">-&gt;</span><span class="me1">prefix</span> <span class="sy0">.</span> <span class="st0">&quot;topics WHERE topic_poster=<span class="es4">$user-&gt;ID</span>&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="sy1">?&gt;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.robfelty.com/2010/04/09/showing-total-number-of-replies-in-bbpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="http://blog.robfelty.com/wp-content/uploads/2010/04/totalReplies-250x189.png" />
		<media:content url="http://blog.robfelty.com/wp-content/uploads/2010/04/totalReplies-250x189.png" medium="image">
			<media:title type="html">totalReplies</media:title>
		</media:content>
	</item>
		<item>
		<title>WordPress 2.9 image changes</title>
		<link>http://blog.robfelty.com/2010/01/02/wordpress-2-9-image-changes/</link>
		<comments>http://blog.robfelty.com/2010/01/02/wordpress-2-9-image-changes/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 22:58:48 +0000</pubDate>
		<dc:creator>robfelty</dc:creator>
				<category><![CDATA[sql]]></category>
		<category><![CDATA[wiki/cms]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://blog.robfelty.com/?p=534</guid>
		<description><![CDATA[WordPress 2.9 has several new image enhancements. One of the biggest features is some basic image editing functionality. Another one is that you can now specify different alt text from the &#8220;caption&#8221; field. The &#8220;caption&#8221; field places a caption under the image. The &#8220;alt&#8221; text is used to describe the picture to non-seeing users (including [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress 2.9 has several new image enhancements. One of the biggest features is some basic image editing functionality. Another one is that you can now specify different alt text from the &#8220;caption&#8221; field. The &#8220;caption&#8221; field places a caption under the image. The &#8220;alt&#8221; text is used to describe the picture to non-seeing users (including search engines). This is a nice addition. However, I usually like my caption, alt text, and title text to be all the same, and I don&#8217;t like to have to enter it all manually or copy and paste. By default, wordpress will use an IPTC caption as its &#8220;description&#8221; field, which shows up in the title attribute of the image. This is nice, since I can add a caption in my image editing program of choice (Picasa) and then I don&#8217;t have to enter it again. Except for those pesky alt and caption fields, which are blank by default. </p>
<p>This is particularly important if I am uploading many pictures. So I wrote a little sql which will set the &#8220;caption&#8221; and &#8220;alt text&#8221; fields to be the same as the description. I already had this working for the &#8220;caption&#8221; field for quite some time, but getting it to work for the different alt text handling in 2.9 was a bit tricky, since I discovered that the alt text is not stored in wp_posts like the other fields. Instead it is stored in the wp_postmeta table, which is new in 2.9. Although it took me awhile to figure this out, the new table is a welcome addition. Now for each image you upload, wordpress stores meta information in this table, including the width and height, different sized versions of the file, the IPTC caption, some EXIF info and a few other goodies. This means that if you like to include EXIF info about your pictures, that doing so requires only a simple database lookup, instead of having to read the headers from the image, which should be considerably faster I would imagine. </p>
<p>Now for my little SQL which sets the &#8220;caption&#8221; and &#8220;alt text&#8221; to be the same as the description. I run this on my server after uploading pictures. It would be even better if I could figure out how to do this as a wordpress plugin.</p>
<div class="codecolorer-container sql dawn" style="overflow:auto;white-space:nowrap;width:100"><div class="sql codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="co1">-- First we set the image caption (post_excerpt) to be the same as the</span><br />
<span class="co1">-- description (post_content)</span><br />
<span class="kw1">UPDATE</span> wp_posts <span class="kw1">SET</span> post_excerpt<span class="sy0">=</span>post_content <span class="kw1">WHERE</span> post_type<span class="sy0">=</span><span class="st0">'attachment'</span> <span class="kw1">AND</span><br />
date<span class="br0">&#40;</span>post_date<span class="br0">&#41;</span><span class="sy0">=</span>curdate<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<br />
<span class="co1">-- Next we set the alternative text to be the same as the post_excerpt</span><br />
<span class="kw1">INSERT</span> <span class="kw1">INTO</span> wp_postmeta <span class="br0">&#40;</span>wp_postmeta<span class="sy0">.</span>post_id<span class="sy0">,</span> wp_postmeta<span class="sy0">.</span>meta_value<span class="br0">&#41;</span> <span class="kw1">SELECT</span><br />
<span class="kw1">DISTINCT</span> wp_posts<span class="sy0">.</span>ID<span class="sy0">,</span> wp_posts<span class="sy0">.</span>post_excerpt <span class="kw1">FROM</span> wp_posts<span class="sy0">,</span> wp_postmeta <span class="kw1">WHERE</span><br />
wp_posts<span class="sy0">.</span>ID<span class="sy0">=</span>wp_postmeta<span class="sy0">.</span>post_id <span class="kw1">AND</span> post_type<span class="sy0">=</span><span class="st0">'attachment'</span> <span class="kw1">AND</span><br />
date<span class="br0">&#40;</span>post_date<span class="br0">&#41;</span><span class="sy0">=</span>curdate<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<br />
<span class="co1">-- This line sets the correct meta_key for the previous line, which doesn't</span><br />
<span class="co1">-- seem possible otherwise</span><br />
<span class="kw1">UPDATE</span> wp_postmeta <span class="kw1">SET</span> meta_key<span class="sy0">=</span><span class="st0">'_wp_attachment_image_alt'</span> <span class="kw1">WHERE</span> meta_key <span class="kw1">IS</span><br />
<span class="kw1">NULL</span>;</div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.robfelty.com/2010/01/02/wordpress-2-9-image-changes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Releasing the Collapsing Archives WordPress Plugin</title>
		<link>http://blog.robfelty.com/2007/12/20/releasing-the-collapsing-archives-wordpress-plugin/</link>
		<comments>http://blog.robfelty.com/2007/12/20/releasing-the-collapsing-archives-wordpress-plugin/#comments</comments>
		<pubDate>Thu, 20 Dec 2007 05:14:09 +0000</pubDate>
		<dc:creator>robfelty</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[wiki/cms]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://blog.robfelty.com/2007/12/20/releasing-the-collapsing-archives-wordpress-plugin/</guid>
		<description><![CDATA[Finally getting around to releasing some more plugins. I started using the Fancy Archives plugin by Andrew Rader about the same time I started using his Fancy Categories plugin (maybe in the reverse order actually). I have been modifying it for some time now, and it seems appropriate to release it as a new plugin. [...]]]></description>
			<content:encoded><![CDATA[<p>Finally getting around to releasing some more plugins. I started using the Fancy Archives plugin by Andrew Rader about the same time I started using his Fancy Categories plugin (maybe in the reverse order actually). I have been modifying it for some time now, and it seems appropriate to release it as a new plugin. The functionality is best described by simply looking at my archives list on this blog. The default wordpress archives list is a simple unordered list. This plugin gives it some dynamic capabilities, similar to the default on Blogger. I have decided to keep increasing the version number from what Andrew was using, so I am calling this version 0.6. Here are the main highlights:</p>
<ul>
<li>Changed name from Fancy Archives to Collapsing Archives
<li>Changed author from Andrew Rader to Robert Felty</li>
<li>Added option to link to archives.php</li>
<li>Added option to list in chronological or reverse chronological order</li>
<li>Added triangles which mark the collapsing and expanding features<br />
      That is, clicking on the triangle collapses or expands, while clicking<br />
      on a month or year links to the archives for the said month or year</li>
<li>Changed behavior from starting all expanded and then collapsing on page<br />
      load to the opposite</li>
<li>Removed the rel=&#8217;hide&#8217; and rel=&#8217;show&#8217; tags, because they are not xhtml<br />
      1.0 compliant. Now uses the CSS classes instead</li>
</ul>
<p>You can download it from the <a href='http://wordpress.org/extend/plugins/collapsing-archives'>WordPress plugin repository</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.robfelty.com/2007/12/20/releasing-the-collapsing-archives-wordpress-plugin/feed/</wfw:commentRss>
		<slash:comments>44</slash:comments>
		</item>
		<item>
		<title>Releasing the Collapsing Categories WordPress Plugin</title>
		<link>http://blog.robfelty.com/2007/12/19/releasing-the-collapsing-categories-wordpress-plugin/</link>
		<comments>http://blog.robfelty.com/2007/12/19/releasing-the-collapsing-categories-wordpress-plugin/#comments</comments>
		<pubDate>Thu, 20 Dec 2007 03:51:05 +0000</pubDate>
		<dc:creator>robfelty</dc:creator>
				<category><![CDATA[(x)html]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[wiki/cms]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://blog.robfelty.com/2007/12/19/releasing-the-collapsing-categories-wordpress-plugin/</guid>
		<description><![CDATA[I started using the Fancy Categories plugin by Andrew Rader about 6 or 8 months ago. I have been slowly modifying it for some time now, and it seems appropriate to release it as a new plugin. (Note that I thought that Andrew Rader disappeared as well, but I now have found him at his [...]]]></description>
			<content:encoded><![CDATA[<p>I started using the Fancy Categories plugin by Andrew Rader about 6 or 8 months ago. I have been slowly modifying it for some time now, and it seems appropriate to release it as a new plugin. (Note that I thought that Andrew Rader disappeared as well, but I now have found him at his new home at <a href='http://voidsplat.org/code/wordpress/fancy-categories/'>void*</a>. The functionality is best described by simply looking at my categories list on this blog. The default wordpress categories list is a simple unordered list. This plugin gives it some dynamic capabilities, similar to the default on Blogger. I have decided to keep increasing the version number from what Andrew was using, so I am calling this version 0.2. Here are the main highlights:</p>
<ul>
<li> Changed name from Fancy Archives to Collapsing Archives</li>
<li> Changed author from Andrew Rader to Robert Felty</li>
<li> Added triangles which mark the collapsing and expanding features That is, clicking on the triangle collapses or expands, while clicking on a month or year links to the archives for the said category.  This uses html entities (dings) instead of images, for a variety of reasons</li>
<li> Lists the titles of posts, instead of just listing subcategories</li>
<li> Removed the rel=&#8217;hide&#8217; and rel=&#8217;show&#8217; tags, because they are not xhtml 1.0 compliant. Now uses the CSS classes instead</li>
<li> MOST IMPORTANTLY &#8212; it is compatible with both the pre 2.3 database which uses categories, and the 2.3+ database structure which uses the tag taxonomy</li>
</ul>
<p>You can download it from the <a href='http://wordpress.org/extend/plugins/collapsing-categories'>WordPress plugin repository</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.robfelty.com/2007/12/19/releasing-the-collapsing-categories-wordpress-plugin/feed/</wfw:commentRss>
		<slash:comments>84</slash:comments>
		</item>
		<item>
		<title>Chronologically ordered blog in wordpress</title>
		<link>http://blog.robfelty.com/2007/05/14/chronologically-ordered-blog-in-wordpress/</link>
		<comments>http://blog.robfelty.com/2007/05/14/chronologically-ordered-blog-in-wordpress/#comments</comments>
		<pubDate>Mon, 14 May 2007 15:34:49 +0000</pubDate>
		<dc:creator>robfelty</dc:creator>
				<category><![CDATA[(x)html]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[wiki/cms]]></category>

		<guid isPermaLink="false">http://blog.robfelty.com/2007/05/14/chronologically-ordered-blog-in-wordpress/</guid>
		<description><![CDATA[I recently started the FedDibblety house blog, documenting our home improvements to our new home in Indiana (which Clare&#8217;s parents built). I set up accounts for my wife Clare, her parents, Dave and Ellen, and my parents, Harold and Fran. Ellen, being a technology nut like myself, immediately jumped in writing posts about the house, [...]]]></description>
			<content:encoded><![CDATA[<p>I recently started <a href='http://fedibblety.com/house'>the FedDibblety house blog</a>, documenting our home improvements to our new home in Indiana (which Clare&#8217;s parents built). I set up accounts for my wife Clare, her parents, Dave and Ellen, and my parents, Harold and Fran. Ellen, being a technology nut like myself, immediately jumped in writing posts about the house, and also had some feature requests. One of those features was to have the blog read in chronological order. Most blogs read in reverse chronological order, but since this one was kind of diary-esque, it seemed more appropriate to have it in normal order. I am also dating posts corresponding to the improvements made, not the actual post date. I started searching around for forum posts and such about how to do this, and I came across two relevant ones. I came across one post on <a href='http://wordpress.org/support/topic/206'>wordpress.org</a> which had a very simple solution, of simply adding one line to the index.php file in the root directory, like so:</p>
<div class="codecolorer-container php dawn" style="overflow:auto;white-space:nowrap;width:100"><div class="php codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw2">&lt;?php</span><br />
<span class="coMULTI">/* Short and sweet */</span><br />
<span class="kw3">define</span><span class="br0">&#40;</span><span class="st_h">'WP_USE_THEMES'</span><span class="sy0">,</span> <span class="kw2">true</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="re0">$order</span> <span class="sy0">=</span> <span class="st_h">'ASC'</span><span class="sy0">;</span> <span class="co1">//adding this line</span><br />
<span class="kw1">require</span><span class="br0">&#40;</span><span class="st_h">'./wp-blog-header.php'</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="sy1">?&gt;</span></div></div>
<p>This did exactly as one would expect. However, this also caused some problems. For those avid blog readers, now they would have to scroll way down (or go the archives) to see <em>new</em> posts, which doesn&#8217;t really make sense. In addition, the RSS feed was also chronologically ordered, so that RSS users would find it very difficult to see if the blog had been updated recently. While searching I also found another post on <a href='http://www.janegalt.net/archives/004848.html'>janegalt.net</a>, in which the blogger asked the same question, and a reply by <a href='http://www.licquia.org/'>Jeff Licquia</a> suggested a very simple solution:</p>
<blockquote><p>
To set up archives to use a different template, go into the management page, then go to Options, then Permalinks.</p>
<p>If you can&#8217;t, or don&#8217;t understand, the RewriteRules stuff, look at the note about not being able to use mod_rewrite. Where it says:</p>
<p>/index.php/archives/%year%/%monthnum%/%day%/%postname%/</p>
<p>Change &#8220;index.php&#8221; to something else, like &#8220;archives.php&#8221;, and put that in for the virtual site structure. Copy index.php to archives.php in your document root, then add the special flag to archives.php. You should be all set at that point.</p>
<p>(I&#8217;m a newbie to WordPress, but not to Web servers or Web stuff in general, so the above makes sense to me but isn&#8217;t tested. I&#8217;ll try to help if you have problems.)
</p></blockquote>
<p>This idea worked very well. I made the change in the WordPress options page, then copied index.php to archives.php, using the $order=ASC flag, and removed that from index.php. Then I had to change the .htaccess file to direct queries to archives.php. I did not want to do this for feeds though, so I had to put in two rules, like so:</p>
<div class="codecolorer-container apache dawn" style="overflow:auto;white-space:nowrap;width:100"><div class="apache codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="co1">#.htaccess file for fedibblety/house blog</span><br />
&lt;<span class="kw3">IfModule</span> mod_rewrite.c&gt;<br />
<span class="kw1">RewriteEngine</span> <span class="kw2">On</span><br />
<span class="kw1">RewriteBase</span> /house/<br />
<span class="kw1">RewriteCond</span> %{REQUEST_FILENAME} !-f<br />
<span class="kw1">RewriteCond</span> %{REQUEST_FILENAME} !-d<br />
<span class="kw1">RewriteCond</span> %{REQUEST_FILENAME} !.*feed\/?$ [NC]<br />
<span class="kw1">RewriteRule</span> . /house/archives.php<br />
<span class="kw1">RewriteCond</span> %{REQUEST_FILENAME} .*feed\/?$ [NC]<br />
<span class="kw1">RewriteRule</span> . /house/index.php<br />
&lt;/<span class="kw3">IfModule</span>&gt;</div></div>
<p>Then there was one last thing. In that blog (and in this one), I am using the fancy-archives plugin (as I write this post that site seems to be down, so I am not providing a link), which I have tweaked a bit. To get the archives in the sidebar listed in chronological order, I just had to change the SQL queries in the fancy-archives-list.php file to ORDER BY post_date ASC.</p>
<p>That was it! </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.robfelty.com/2007/05/14/chronologically-ordered-blog-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
