<?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:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>

<channel>
	<title>CogDogBlog &#187; code</title>
	<atom:link href="http://cogdogblog.com/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://cogdogblog.com</link>
	<description>Alan Levine&#039;s space for barking about and playing with technology</description>
	<lastBuildDate>Mon, 13 Feb 2012 03:36:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
		<item>
		<title>From the CogDogLab: Pechaflickr</title>
		<link>http://cogdogblog.com/2011/05/26/pechaflickr/</link>
		<comments>http://cogdogblog.com/2011/05/26/pechaflickr/#comments</comments>
		<pubDate>Thu, 26 May 2011 17:54:24 +0000</pubDate>
		<dc:creator>Alan Levine aka CogDog</dc:creator>
				<category><![CDATA[Blog Pile]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[flickr]]></category>

		<guid isPermaLink="false">http://cogdogblog.com/?p=6870</guid>
		<description><![CDATA[Here is a new toy to play with- announcing Pechaflickr, the pecha kucha + battle decks + flickr mashup. Type in a tag, click &#8220;play&#8221;, and you will be served up 20 random flickr photos, displayed each for 20 seconds. The idea is to have people practice the art of improv to a set of never before seen images, and try to make sense of it. I owe the idea to Giulia Forsyth, who days before 2011 Northern Voice tweeted me asking if there was some way to make Five Card Flickr do something like this. My first, lame response was going to be: Yeah, do 5 Card flickr 4 times ;-) But I thought this might be fun to do. My first round was a build off of the same code that I wrote for 5 Card Flickr, because all of the image data for the tags read in [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a new toy to play with- announcing <a href="http://lab.cogdogblog.com/pechaflickr/">Pechaflickr</a>, the <a href="http://www.pecha-kucha.org/">pecha kucha</a> + <a href="http://www.google.com/search?q=battle+decks">battle decks</a> + <a href="http://flickr.com/">flickr</a> mashup.</p>
<p><a href="http://lab.cogdogblog.com/pechaflickr/"><img src="http://cogdogblog.com/wp-content/uploads/2011/05/pechaflickr.jpg" alt="" title="pechaflickr" width="500" height="404" class="alignnone size-full wp-image-6871" /></a></p>
<p>Type in a tag, click &#8220;play&#8221;, and you will be served up 20 random flickr photos, displayed each for 20 seconds. The idea is to have people practice the art of improv to a set of never before seen images, and try to make sense of it.</p>
<p>I owe the idea to <a href="http://gforsythe.ca">Giulia Forsyth</a>, who days before 2011 Northern Voice tweeted me asking if there was some way to make <a href="http://5card.cogdogblog.com/">Five Card Flickr</a> do something like this. My first, lame response was going to be:</p>
<blockquote><p>Yeah, do 5 Card flickr 4 times ;-)</p></blockquote>
<p>But I thought this might be fun to do. My first round was a build off of the same code that I wrote for 5 Card Flickr, because all of the image data for the tags read in are stored locally in my database (the site pulls in the flickr id for a photo needed to generate a size of an image via the API).</p>
<p>That was not hard, after tapping into a jquery library for slide shows, <a href="http://jquery.malsup.com/cycle/">jquery cycle</a>, which is amazing for what it provides to create a variety of web-based slideshows. But it seemed limiting to use only the tags defined for my other site.</p>
<p>So I pressed rewind, and just wrote something from scratch, using the same <a href="http://phpflickr.com/">phpflickr library</a> to work with the flickr API. In this version, I use the API to pull up the 200 most recent photos with the tag into an array, and then use <strong>array_rand()</strong> to grab 20 random from among those, which are then served up by the jquery cycle gig.</p>
<p>I found that the first image in the set loaded a bit slowly, so I made the first slide an intro/explanation/teaser image I pre-created (I have five of them, so you get a random one each time).</p>
<p><img src="http://cogdogblog.com/wp-content/uploads/2011/05/pf1.jpg" alt="" title="pf1" width="500" height="333" class="alignnone size-full wp-image-6872" /></p>
<p>The images are then displayed 20 seconds at a time, with a counter on the left- here is an example using tyhe tag &#8220;dog&#8221; (is there another tag worth doing?)</p>
<p><img src="http://cogdogblog.com/wp-content/uploads/2011/05/pf2.jpg" alt="" title="pf2" width="500" height="343" class="alignnone size-full wp-image-6873" /></p>
<p><img src="http://cogdogblog.com/wp-content/uploads/2011/05/pf3.jpg" alt="" title="pf3" width="500" height="343" class="alignnone size-full wp-image-6874" /></p>
<p>I did a demo of this at a Moosecamp session for Northern Voice, and people seemed to like it.</p>
<p>After I can do some tweaking of the layout and fish for feedback, I will post the code for it. Some things that people asked for included:</p>
<ul>
<li>An ability on the front to select the duration for slides to appear (it is fixed at 20 seconds, but this could be a menu option).</li>
<li>An ability to change the number of slides (maybe a mini pecha, say 10 slides?)</li>
<li>A clock on the screen (I am against the idea, it does not meet with the concept, but that is just me)</li>
<li>Perhaps a way fo presetting some &#8220;easy&#8221;, &#8216;medium&#8221;, &#8220;hard&#8221; settings to set the challenge level</li>
</ul>
<p>No promises I will do any of this, but I will at least share the code soon.</p>
<p>But this was fun to make!</p>
<p>Give it a play at <a href="http://lab.cogdogblog.com/pechaflickr/">http://lab.cogdogblog.com/pechaflickr/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://cogdogblog.com/2011/05/26/pechaflickr/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
		<item>
		<title>More Code Fun: Reading (or ‘to Read’) List</title>
		<link>http://cogdogblog.com/2010/10/22/more-code-fun-reading-or-to-read-list/</link>
		<comments>http://cogdogblog.com/2010/10/22/more-code-fun-reading-or-to-read-list/#comments</comments>
		<pubDate>Sat, 23 Oct 2010 03:59:16 +0000</pubDate>
		<dc:creator>Alan Levine aka CogDog</dc:creator>
				<category><![CDATA[Blog Pile]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://cogdogblog.com/?p=5821</guid>
		<description><![CDATA[While I&#8217;m on the code doc kick&#8230; this one is not mine, but something I applied on my site. A week or so ago I came across (from RSS feeds? nah, I think it was in twitter? maybe a squirrel stepped o my keyboard?) Steph Gray&#8217;s Reading: keeping on top of stuff I save, some code he rolled. The way he describes the need rang a resonant bell with me: Like a lot of people, I use services like Google Reader, Twitter, Delicious and Instapaper to help me find and store interesting links to articles, tools, apps or whatever. Personally, when I don’t have time to read it right now, I tend to star an item in Google Reader, ‘favourite’ it in Twitter, or mark it to ‘Read later’ in Instapaper – often five or ten things a day. I also save interesting stuff to Delicious, particularly where I think [...]]]></description>
			<content:encoded><![CDATA[<p>While I&#8217;m on the code doc kick&#8230; this one is not mine, but something I applied on my site.</p>
<p>A week or so ago I came across (from RSS feeds? nah, I think it was in twitter? maybe a squirrel stepped o my keyboard?) Steph Gray&#8217;s <a href="http://blog.helpfultechnology.com/2010/10/reading-keeping-on-top-of-stuff-i-save/">Reading: keeping on top of stuff I save</a>, some code he rolled. The way he describes the need rang a resonant bell with me:</p>
<blockquote><p>Like a lot of people, I use services like Google Reader, Twitter, Delicious and Instapaper to help me find and store interesting links to articles, tools, apps or whatever. Personally, when I don’t have time to read it right now, I tend to star an item in Google Reader, ‘favourite’ it in Twitter, or mark it to ‘Read later’ in Instapaper – often five or ten things a day. I also save interesting stuff to Delicious, particularly where I think it may have longer term usefulness.</p>
<p>But I hardly ever actually go back and read those things.</p>
<p>Mainly it’s because it’s a bit of a faff finding the links, and because the time I’d get to do it (on the train, hanging around waiting for a toddler to wake up, etc) I’ve generally only got an iPhone to hand.</p>
<p>Hence Reading. This is a little sliver of PHP and jQuery&#8230;</p></blockquote>
<p>Steph&#8217;s nifty script consists of a single PHP script plus the SimplePie RSS parser and a JQuery library to make the interface accordion work. My setup is at <a href="http://cogdogblog.com/reading">http://cogdogblog.com/reading</a>:</p>
<p><a href="http://cogdogblog.com/reading"><img src="http://cogdogblog.com/wp-content/uploads/2010/10/cdb-reading-web.jpg" alt="" title="cdb reading- web" width="500" height="261" class="alignnone size-full wp-image-5823" /></a></p>
<p>If you open any of the &#8220;accordion&#8221; items, you get a full version of the site:<br />
<a href="http://cogdogblog.com/reading"><img src="http://cogdogblog.com/wp-content/uploads/2010/10/cdb-reading-open.jpg" alt="" title="cdb reading open" width="500" height="348" class="alignnone size-full wp-image-5822" /></a></p>
<p> It&#8217;s something you cold implement without much code or PHP chops needed. In fact, all you need to edit is the line that lists the RSS feeds you want to use.</p>
<p>What it does is let you build your own list from all the RSS feeds for these sorts of things- your tags in delicious have a feed, your Google Reader shared (and starred) items have a feed, Instapaper has a feed- all you have to do is find them, and add them to the part of the code where you enter them in an array.</p>
<p>Delicious provides its RSS feed at the foot of most pages- you can do your entire stream, or create a special tag you want to use to designate items for this list. Instaper provides the feed somewhere in the account settings. You can get your Google Reader starred items via the Reader Settings &#8211; Folders and Tags (set the starred items to public, and you get a link for the RSS).  Your shared reader items are set up in the <a href="https://www.google.com/reader/view/?tab=my#friends-manager-page">Sharing Setup area</a>.  </p>
<p>Twitter does have a feed for your favorites, though it does not provide the link directly for you- I found <a href="http://www.twitterrati.com/2010/05/17/create-an-rss-feed-for-twitter-favorites/">the answer via twitterati</a>, it is as simple as:</p>
<p><pre>http://twitter.com/favorites/[insert_your_ID_here].rss</pre></p>
<p>so my feed is http://twitter.com/favorites/cogdog.rss</p>
<p>What is also neat, or maybe neater, is that Step&#8217;s code has a mobile friendly version at the same URL- in this one, you get the same list, but the accordion opens to just a link to the site:</p>
<p><img src="http://cogdogblog.com/wp-content/uploads/2010/10/cdb-reading-mobile.jpg" alt="" title="cdb-reading-mobile" width="267" height="400" class="aligncenter size-full wp-image-5824" /></p>
<p>I have been doing a bit more of sharing in Google reader, especially when I am on the mobile version, and this is sure a better way of organizing then emailing links to myself (the same for twitter). I&#8217;ve not used Instapaper in eons, I keep forgetting about it.</p>
<p>Thanks Steph for sharing the code- again, <a href="http://blog.helpfultechnology.com/2010/10/reading-keeping-on-top-of-stuff-i-save/">you can get your own code from Steph&#8217;s site</a>, and I see the plans for the next version are to make it so you can download all the items to a Google Spreadsheet.</p>
<p>What are you waiting for? Give it a try.</p>
]]></content:encoded>
			<wfw:commentRss>http://cogdogblog.com/2010/10/22/more-code-fun-reading-or-to-read-list/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
		<item>
		<title>PHP Local Time Code</title>
		<link>http://cogdogblog.com/2010/10/22/php-local-time-code/</link>
		<comments>http://cogdogblog.com/2010/10/22/php-local-time-code/#comments</comments>
		<pubDate>Sat, 23 Oct 2010 01:58:01 +0000</pubDate>
		<dc:creator>Alan Levine aka CogDog</dc:creator>
				<category><![CDATA[Blog Pile]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://cogdogblog.com/?p=5816</guid>
		<description><![CDATA[I spent about 15 minutes writing a small PHP function for one of my sites, and then another hour writing it up. What for? Well, let&#8217;s back up. If you are running online events where people might come from anywhere, there can always be challenges for getting the right time to people. For our NMC events, while our office is in Austin, we have staff in 3 other time zones, and people in our community from maybe another 14 or more zones on top of that. If I say something starts at 2:00pm Central Time, then it puts it on everyone else to figure out when that is (and I&#8217;ve seen event sites where they do not even provide the reference time zone). If were all proper and versatile, we&#8217;d use Greenwich Mean Time, since everyone knows their offset, right? (I am -7 what are you?) Most of the time [...]]]></description>
			<content:encoded><![CDATA[<p>I spent about 15 minutes writing a small PHP function for one of my sites, and then another hour writing it up. What for?</p>
<p>Well, let&#8217;s back up. If you are running online events where people might come from anywhere, there can always be challenges for getting the right time to people. For our NMC events, while our office is in Austin, we have staff in 3 other time zones, and people in our community from maybe another 14 or more zones on top of that.</p>
<p>If I say something starts at 2:00pm Central Time, then it puts it on everyone else to figure out when that is (and I&#8217;ve seen event sites where they do not even provide the reference time zone). If were all proper and versatile, we&#8217;d use Greenwich Mean Time, since everyone knows their offset, right? (I am -7 what are you?)</p>
<p>Most of the time , our event times are referenced to Pacific Time, since that is where our server is hosted, but even if we provide Pacific, Central, and Eastern Time, what about folks in Spain? New Zealand? Hong Kong? </p>
<p>This came to me a lot when our events picked up in Second Life back in 2006-2007.  They used Pacific Time too as a reference time (actually for a long time they called it SLT for Second Life Time, and people still say that). </p>
<p>I started early using the <a href="http://www.timeanddate.com/worldclock/fixedtime.html">World Time Clock fixed time</a>. It allows you to enter a date time, and reference time zone, and generates a link that produces a big chart that converts that to other times around the world.</p>
<p>it&#8217;s silly to not think of the world as your audience, and most of the world is on a different time zone, like those <a href="http://www.timeanddate.com/worldclock/city.html?n=5">weird half hour ones in South Australia</a>.</p>
<p>For example, if there was an event, like tonight my dinner, at 6:00 PM, I&#8217;d enter the date and time in the form, and scroll all the way down to the bottom to select my time zone (U.S.A. &#8211;  Arizona &#8211; Phoenix), and the form generates for me this URL</p>
<p><a href="http://www.timeanddate.com/worldclock/fixedtime.html?month=10&#038;day=23&#038;year=2010&#038;hour=18&#038;min=0&#038;sec=0&#038;p1=197">http://www.timeanddate.com/worldclock/fixedtime.html?month=10&#038;day=23&#038;year=2010&#038;hour=18&#038;min=0&#038;sec=0&#038;p1=197</a> </p>
<p>which I can use to generate a URL that lets anyone else in the world know when I am having dinner, in their local time zone:</p>
<p><a href="http://www.timeanddate.com/worldclock/fixedtime.html?month=10&amp;day=23&amp;year=2010&amp;hour=18&amp;min=0&amp;sec=0&amp;p1=197"><img src="http://cogdogblog.com/wp-content/uploads/2010/10/world-time-clock.jpg" alt="" title="world time clock" width="500" height="444" class="alignnone size-full wp-image-5817" /></a></p>
<p>And in our event web pages I might say:</p>
<blockquote><p>hey, tonight&#8217;s event is Alan&#8217;s Dinner! It is taking place October 22 at 6:00 PM PST (<a href="http://www.timeanddate.com/worldclock/fixedtime.html?month=10&#038;day=23&#038;year=2010&#038;hour=18&#038;min=0&#038;sec=0&#038;p1=197">check for local time</a>)</p></blockquote>
<p>I was pretty adamant about getting our folks to add this &#8220;check for local time&#8221; link. If you inspect the URL, you can actually make new ones just by adjusting the values in the URL string (The site does provide a URL shortener if you dont want to display a monster long URL).</p>
<p>But here is the thing that struck me today- for our MIDEA site, I am using the WP custom post types for our events, so I already have built into the date, a value for the start date/time (it is the unix time version of the date/time, number of seconds since 1970). Since I already have the data, I thought it would be easy to write a function that auto generates the World Time Clock Link.</p>
<p>It was easy.</p>
<pre class="brush: php">
function get_worldtimeclock ($ts, $tz=197) {
	// generates a URL for a world time clock link for a given timestamp $ts
	// default timezine (for this site) is 197 or Phoenix, hey thats my time zone

	$when = getdate($ts);

	return &#039;http://www.timeanddate.com/worldclock/fixedtime.html?month=&#039; . $when[&#039;mon&#039;]  . &#039;&amp;day=&#039; . $when[&#039;mday&#039;]  . &#039;&amp;year=&#039; . $when[&#039;year&#039;]  . &#039;&amp;hour=&#039; . $when[&#039;hours&#039;]  . &#039;&amp;min=&#039; . $when[&#039;minutes&#039;]  . &#039;&amp;sec=0&amp;p1=&#039; . $tz;
}
</pre>
<p>and you can see it in action in the top gray bars on pages like <a href="http://midea.nmc.org/event/horizonreportmuseumwebinar/">http://midea.nmc.org/event/horizonreportmuseumwebinar/</a>.</p>
<p>It&#8217;s really bone simple PHP, just like to write it up. I set up a code demo page so you can see it in action:</p>
<p><a href="http://cogdogblog.com/code/world-time-clock-link.php"><img src="http://cogdogblog.com/wp-content/uploads/2010/10/time-clock-demo.jpg" alt="" title="time clock demo" width="500" height="388" class="alignnone size-full wp-image-5818" /></a></p>
<p>Actually, it was just fun to dip my paws into the code. Even if it is bone head simple code.</p>
]]></content:encoded>
			<wfw:commentRss>http://cogdogblog.com/2010/10/22/php-local-time-code/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
		<item>
		<title>Coding My Own WordPress Authors List</title>
		<link>http://cogdogblog.com/2010/08/05/wordpress-authors-list/</link>
		<comments>http://cogdogblog.com/2010/08/05/wordpress-authors-list/#comments</comments>
		<pubDate>Fri, 06 Aug 2010 06:47:21 +0000</pubDate>
		<dc:creator>Alan Levine aka CogDog</dc:creator>
				<category><![CDATA[Blog Pile]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://cogdogblog.com/?p=5464</guid>
		<description><![CDATA[cc licensed flickr photo shared by bitzcelt Elwood: It&#8217;s 106 miles to get this sidebar coded, we&#8217;ve got a full tank of gas, half a pack of cigarettes, it&#8217;s dark and we&#8217;re wearing sunglasses. Jake: Hit it. I have no idea why I opened this way except for Jim Groom Inspiration. But to jive my code chops, there&#8217;s nothing more energizing than doing a little hack and chop coding in WordPress. Today I was again doing some sidebar fine tuning on the NMC MIDEA web site (previously covered in my almost done series on doing custom post types in WordPress 3.0). It was one of those &#8220;oh this might take 20 minute&#8221; deals that ended up going a bit longer. but like Jake and Elwood, when you gotta go to Chicago, you drop the sunglasses and hit it. And this is pretty simple, and most likely there is a plugin [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Too Cool / Blues for Sale" href="http://flickr.com/photos/bitzcelt/413275282/"><img src="http://farm1.static.flickr.com/126/413275282_8307909f17.jpg" /></a><br /><small><a title="Too Cool / Blues for Sale" href="http://flickr.com/photos/bitzcelt/413275282/">cc licensed flickr photo</a> shared by <a href="http://flickr.com/people/bitzcelt/">bitzcelt</a></small></p>
<p><strong>Elwood</strong>: It&#8217;s 106 miles to get this sidebar coded, we&#8217;ve got a full tank of gas, half a pack of cigarettes, it&#8217;s dark and we&#8217;re wearing sunglasses.<br />
<strong>Jake</strong>: Hit it.</p>
<p>I have no idea why I opened this way except for <a href="http://bavatuesdays.com/">Jim Groom Inspiration</a>.</p>
<p>But to jive my code chops, there&#8217;s nothing more energizing than doing a little hack and chop coding in WordPress.</p>
<p>Today I was again doing some sidebar fine tuning on the NMC <a href="http://midea.nmc.org/">MIDEA web site</a> (previously covered in my almost done <a href="http://cogdogblog.com/2010/07/23/roundup-wp3/">series on doing custom post types in WordPress 3.0</a>).</p>
<p>It was one of those &#8220;oh this might take 20 minute&#8221; deals that ended up going a bit longer. but like Jake and Elwood, when you gotta go to Chicago, you drop the sunglasses and hit it.</p>
<p>And this is pretty simple, and most likely there is a plugin that already does what I needed, but sometimes, it is just worth the effort to roll your own code. It&#8217;s the same joy of actually doing something in your car engine that actually does not result in flames or calling a tow truck.</p>
<p>What we have on this site is a number of accounts, me as admin, some staff as editors, and a few guest bloggers, with roles as authors. The category our gues authors blog under is called &#8220;<a href="http://midea.nmc.org/ideas">Ideas</a>&#8220;, and my idea was to add to the template sidebar, above the part where widgetized stuff happens, a blurb and a listing of our guest bloggers. I also liked the feature of not listing authors who have yet to post.</p>
<p>At first it seemed like the function <a href="http://codex.wordpress.org/Function_Reference/wp_list_authors">wp_list_authors</a> would do, but it has no way to list just authors of a certain role- it is meant for all authors (you can hide the administrator; I thought by making all our staff admins it would work, but that did not).</p>
<p>I scoured a few plugins, but most are widget oriented (its a long explanation, but because this only appears on category archives, doing a special set of widgets was overload) or or geared for listing author avatars.</p>
<p>Next I googled and found <a href="http://wpengineer.com/list-all-users-in-wordpress/">a custom function from WP Engineer</a> that at first looked good, but it was written for previous versions of WordPress- things have really changed from the early days of basing author capabilities on an integer user role number, though the info is still there in the database. I started editing their script to get it to work, going back and forth to phpMyAdmin to run test queries.</p>
<p>it ended up sort of working, but still was not what I sought. I wanted it (a) to not only list the authors, but link to their profiles; (b) list the number of posts the author has written like the wp_list_authors() function does; (c) skip authors that have not posted (again like  wp_list_authors() function does); and (d) list the authors in alphabetical order of their last name&#8230; which I did not find anywhere.</p>
<p>With some more elbow grease I more or less got it going, but really though the code was not quite as lean as it should be (this is the place where it may not pay to keep coding, but now Jake and Elwood were only 50 miles from the Windy City, and they could see the glow of light on the horizon).</p>
<p>There is actually quite a bit of fine grained tuning you can do for blog user accounts, down to the specific capabilities, and you can add/remove what accounts can do beyond the basic titles of &#8220;author&#8221; editor (<a href="http://codex.wordpress.org/Roles_and_Capabilities">see Roles and Capabilities)</a>. Most of this seems put to use for creators of plugins.</p>
<p>But with another round of Googling, I found <a href="http://sltaylor.co.uk/blog/get-wordpress-users-by-role/">the function I was looking for from Steve Taylor</a>- it would return a list of ids of users that had a given role, and it made my code a lot shorter.</p>
<p>Only 25 miles til Chi-Town, boys&#8230;.</p>
<p>I still ended up rolling some bits to do the parts I wanted&#8230; so here are the two functions I added to my <strong>functions.php</strong> template to generate a list of users with a given role as a &gt;ul&lt;&#8230;&gt;/ul&#038;lt list, in alphabetical order by last name (I made all the accounts, so I know they have these parts completed), skipping users with no posts&#8230;</p>
<p>It is pretty heavily commented, and ought to be semi-explanatory&#8230;</p>
<pre class="brush: php">
function getUsersByRole( $role ) {
	// find all users with given role
	// via http://sltaylor.co.uk/blog/get-wordpress-users-by-role/

	if ( class_exists( &#039;WP_User_Search&#039; ) ) {
		$wp_user_search = new WP_User_Search( &#039;&#039;, &#039;&#039;, $role );
		$userIDs = $wp_user_search-&gt;get_results();
	} else {
		global $wpdb;
		$userIDs = $wpdb-&gt;get_col(&#039;
			SELECT ID
			FROM &#039;.$wpdb-&gt;users.&#039; INNER JOIN &#039;.$wpdb-&gt;usermeta.&#039;
			ON &#039;.$wpdb-&gt;users.&#039;.ID = &#039;.$wpdb-&gt;usermeta.&#039;.user_id
			WHERE &#039;.$wpdb-&gt;usermeta.&#039;.meta_key = \&#039;&#039;.$wpdb-&gt;prefix.&#039;capabilities\&#039;
			AND &#039;.$wpdb-&gt;usermeta.&#039;.meta_value LIKE \&#039;%&quot;&#039;.$role.&#039;&quot;%\&#039;
		&#039;);
	}
	return $userIDs;
}

function midea_list_authors($user_role=&#039;author&#039;, $show_fullname = true) {
	// Generate a list of authors for a given role
	// default is to list authors and show full name

	global $wpdb;

	$blog_url = get_bloginfo(&#039;url&#039;); // store base URL of blog
	$holding_pen = array(); // this is cheap, a holder for author data

 	echo &#039;&lt;ul&gt;&#039;;

	// get array of all author ids for a role
	$authors = getUsersByRole( $user_role );

	foreach ( $authors as $item ) {

		// get number of posts by this author; custom query
		$post_count = $wpdb-&gt;get_results(&quot;SELECT COUNT( * ) as cnt
		FROM  $wpdb-&gt;posts
		WHERE  post_author =&quot; . $item . &quot;
		AND  post_type =  &#039;post&#039;
		AND  post_status =  &#039;publish&#039;&quot;);

		// only output authors with posts; ugly way to get to the result, but it works....

		if ($post_count[0]-&gt;cnt) {

			// load info on this user
			$author = get_userdata( $item);

			// store output in temp array; we use last names as an index in this array
			$holding_pen[$author-&gt;last_name] =  &#039;&lt;li&gt;&lt;a href=&quot;&#039; . $blog_url . &#039;/author/&#039;  . $author-&gt;user_login  . &#039;&quot;&gt; &#039; . $author-&gt;display_name . &#039; (&#039; . $post_count[0]-&gt;cnt . &#039;)&lt;/a&gt; &lt;/li&gt;&#039;;
		}

	}

	// now sort the array on the index to get alpha order
	ksort($holding_pen);

	// now we can spit the output out.
	foreach ($holding_pen as $key=&gt;$value) {
		echo $value;
	}
	echo &#039;&lt;/ul&gt;&#039;;
}
</pre>
<p>And this is simply called in my main sidebar.php template&#8230; I use a conditional to insert it where I want, so it only appears on the archives for the &#8220;ideas&#8221; category (I made the defaults of my function match my use case&#8230; sue me!)</p>
<pre class="brush: php">
&lt;?php if (is_category(&#039;ideas&#039;)) : ?&gt;
&lt;h3&gt;MIDEA Ideas&lt;/h3&gt;
&lt;p&gt;Our panel of guest bloggers, all of them experts in the museum and technology field, bring you food for thought. &lt;/p&gt;

&lt;?php midea_list_authors(); ?&gt; 

&lt;?php endif?&gt;
</pre>
<p>And with that, welcome to the big city&#8230; <a href="http://midea.nmc.org/ideas/">see it in action</a></p>
<p><a href="http://midea.nmc.org/ideas/"><img src="http://cogdogblog.com/wp-content/uploads/2010/08/midea-ideas.jpg" alt="" title="midea-ideas" width="500" height="315" class="alignnone size-full wp-image-5465" /></a></p>
<p>And the boys are now in town!</p>
<p><a title="Altar Of Blues" href="http://flickr.com/photos/51035610542@N01/160955737/"><img src="http://farm1.static.flickr.com/71/160955737_aec8393e03.jpg" /></a><br /><small><a title="Altar Of Blues" href="http://flickr.com/photos/51035610542@N01/160955737/">cc licensed flickr photo</a> shared by <a href="http://flickr.com/people/51035610542@N01/">cszar</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://cogdogblog.com/2010/08/05/wordpress-authors-list/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
		<item>
		<title>Feed2JS Source Moved to Google Code</title>
		<link>http://cogdogblog.com/2009/10/03/feed2js-google-code/</link>
		<comments>http://cogdogblog.com/2009/10/03/feed2js-google-code/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 17:25:08 +0000</pubDate>
		<dc:creator>Alan Levine aka CogDog</dc:creator>
				<category><![CDATA[Blog Pile]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Feed2JS]]></category>
		<category><![CDATA[rss]]></category>

		<guid isPermaLink="false">http://cogdogblog.com/?p=4269</guid>
		<description><![CDATA[I am at the same time honored and deeply scared that a lot of people use my Feed2JS tool created like in 2003 or 2004 for helping people embed RSS feeds in their site using cut and paste JavaScript. If my stats are right, in the 6 hours since the cache was cleaned out (daily), 45,000 some unique feeds have been run through here, which is about 60 feeds per minute. I hardly do anything to the code and I hope it does not blow up on anyone. There may have been some issues since the time I was trying to implement a new parser (which killed the server which for years has been kindly donated for free by the kind folks at Modevia Web Services)&#8230;. in restoring it I may have put a deprecated version of MagpieRSS; I just re-adjusted and the old FeedMachine seems to be working. For [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://cogdogblog.com/wp-content/uploads/2009/10/feed2js.jpg"><img src="http://cogdogblog.com/wp-content/uploads/2009/10/feed2js.jpg" alt="feed2js" title="feed2js" width="200" height="225" class="alignleft size-full wp-image-4271" /></a> I am at the same time honored and deeply scared that a lot of people use my <a href="http://feed2js.org/">Feed2JS tool</a> created like in 2003 or 2004 for helping people embed RSS feeds in their site using cut and paste JavaScript. <a href="http://feed2js.org"><img src="http://cogdogblog.com/wp-content/uploads/2009/10/feed2js_badge.gif" alt="feed2js_badge" title="feed2js_badge" width="80" height="15" class="alignnone size-full wp-image-4272" /></a></p>
<p>If my stats are right, in the 6 hours since the cache was cleaned out (daily), <a href="http://feed2js.org/index.php?s=examples">45,000 some unique feeds</a> have been run through here, which is about 60 feeds per minute.</p>
<p>I hardly do anything to the code and I hope it does not blow up on anyone. There may have been some issues since <a href="http://cogdogblog.com/2009/04/11/feed2js-one-step-back/">the time I was trying to implement a new parser</a> (which killed the server which for years has been kindly donated for free by the <a href="http://www.modevia.com/">kind folks at Modevia Web Services</a>)&#8230;. in restoring it I may have put a deprecated version of MagpieRSS; I just re-adjusted and the old FeedMachine seems to be working.</p>
<p>For the last few years I had the source code hosted at <a href="http://eduforge.org/">EduForge</a> but as there were some rumblings of changes there, and that despite <a href="http://cogdogblog.com/2009/10/02/waiting-for-wave/">my immense depression over being Wave Rejected</a>, I am a Google Fan Person&#8212; so I have moved the Feed2JS code to Google code at <a href="http://code.google.com/p/feed2js/">http://code.google.com/p/feed2js/</a>.</p>
<p><a href="http://code.google.com/p/feed2js/"><img src="http://cogdogblog.com/wp-content/uploads/2009/10/feed2js-google-code.jpg" alt="feed2js-google-code" title="feed2js-google-code" width="500" height="244" class="alignnone size-full wp-image-4270" /></a></p>
<p>I am still learning how to set things up there, and I don&#8217;t have source code established as check in / check out basis (like it matters, no one ever jumped at the chance to tinker in the code when offered). But since my contact info is not exactly front and center on Feed2JS site, I prefer if people use the <a href="http://code.google.com/p/feed2js/issues/list">Issues submission tool</a> at the new site to let me know of any problems (no guarantee I can do much, but I will try)</p>
]]></content:encoded>
			<wfw:commentRss>http://cogdogblog.com/2009/10/03/feed2js-google-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
		<item>
		<title>Updating Web Sites with Google Spreadsheets</title>
		<link>http://cogdogblog.com/2009/08/31/google-spreadsheets/</link>
		<comments>http://cogdogblog.com/2009/08/31/google-spreadsheets/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 04:54:43 +0000</pubDate>
		<dc:creator>Alan Levine</dc:creator>
				<category><![CDATA[Blog Pile]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://cogdogblog.com/?p=4118</guid>
		<description><![CDATA[I&#8217;ve done a handful of web projects this year where it made sense to store data in Google Spreadsheets, and then use a bit of PHP code to make them be dynamically displayed on a web site. In many cases, these are tables of data that are parsed and presented nicely in the web site, but for a few NMC projects, it made sense as a way for a staff person to update data on our web pages w/o having to touch the pages. As a first example, I am cleaning up an older WordPress site I use for logging my running/training; in the past, I kept a spreadsheet on my desktop for keeping a run log and then manually transferred the totals/averages/graphs to my web site by pasting into some text files (they are embedded with a PHP include). It worked, but it did have that tedious manual smell [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve done a handful of web projects this year where it made sense to store data in Google Spreadsheets, and then use a bit of PHP code to make them be dynamically displayed on a web site. In many cases, these are tables of data that are parsed and presented nicely in the web site, but for a few NMC projects, it made sense as a way for a staff person to update data on our web pages w/o having to touch the pages.</p>
<p>As a first example, I am cleaning up <a href="http://dommy.com/ihaterunning">an older WordPress site</a> I use for logging my running/training; in the past, I kept a spreadsheet on my desktop for keeping a run log and then manually transferred the totals/averages/graphs to my web site by pasting into some text files (they are embedded with a PHP include). It worked, but it did have that tedious manual smell for something that should be more automated.</p>
<p>It seemed to make sense to transfer the spreadsheet to a Google Doc. I&#8217;m not going to detail all the bits in there, but essentially, for every run, I enter a distance and time on the appropriate date line, and the sheet calculates total/averages per week and on a final summary page. </p>
<p><a href="http://spreadsheets.google.com/pub?key=tMIPDwydKpay-5Oq0_G769w&#038;single=true&#038;gid=1&#038;output=html"><img src="http://cogdogblog.com/wp-content/uploads/2009/08/spreadsheet-log.jpg" alt="spreadsheet-log" title="spreadsheet-log" width="500" height="273" class="alignnone size-full wp-image-4120" /></a></p>
<p>This is just the data; I have another sheet that is just the table for the weekly totals of miles and time spent running; from here I can simply use Google&#8217;s built-in Publish Chart which provides a URL to embed this graphic:</p>
<p><img src="http://spreadsheets.google.com/pub?key=tMIPDwydKpay-5Oq0_G769w&#038;oid=4&#038;output=image" width="100%"/></p>
<p>This is subtle but powerful&#8211; this is an image, but not an image- as the data changes, so will the graphic. So I know longer have to manually make a graphic and upload it to my web site; I can simply use the HTML</p>
<pre class="brush: html">

&lt;img src=&quot;http://spreadsheets.google.com/pub?key=tMIPDwydKpay-5Oq0_G769w&amp;oid=4&amp;output=image&quot; width=&quot;100%&quot;/&gt;
</pre>
<p>The other piece uses Google&#8217;s ability to publish a worksheet as CSV- this is data you can then parse on your web site. So I have a sheet that simply does averages/totals for my running log:</p>
<p><img src="http://cogdogblog.com/wp-content/uploads/2009/08/spreadsheet-totals.jpg" alt="spreadsheet totals" title="spreadsheet totals" width="500" height="205" class="alignnone size-full wp-image-4119" /></p>
<p>To access this data, I click the <strong>Share</strong> button and select <strong>Publish As Web Page</strong></p>
<p><img src="http://cogdogblog.com/wp-content/uploads/2009/08/publish-to-web.jpg" alt="publish-to-web" title="publish-to-web" width="535" height="496" class="alignnone size-full wp-image-4121" /></p>
<p>The options in the top make it so the published data is made current whenever I request it; in the bottom I select the option to have it published as CSV (comma separated value), and I select just the spreadsheet I need.</p>
<p>Thus, <a href="http://spreadsheets.google.com/pub?key=tMIPDwydKpay-5Oq0_G769w&#038;single=true&#038;gid=0&#038;output=html">this URL</a> always gives me the data on the spreadsheet in a form I can use in my code&#8230;. this bit takes some PHP savvy to manage, but I use the same logic almost everywhere.</p>
<p><img src="http://cogdogblog.com/wp-content/uploads/2009/08/current-totals.jpg" alt="current totals" title="current totals" width="253" height="146" class="alignright size-full wp-image-4122" /> I use this on the sidebar of my blog to display an up to date listing of my totals. In my WordPress sidebar, I use a statement to bring in the code from an external file named <strong>totals.php</strong> that sits inside my theme directory:</p>
<pre class="brush: html">
&lt;?php include (TEMPLATEPATH . &quot;/totals.php&quot;); ?&gt;
</pre>
<p>I could have simply inserted the code into my sidebar template, but going modular like this makes it easier to separate code from format&#8230; </p>
<p>The basic logic is using the php <strong>file</strong> command to read int a remote file, which puts the contents into an array; where each array item is one line of data. </p>
<pre class="brush: php">
// get the CSV data as an array from the remote URL
$lines = file(&#039;http://spreadsheets.google.com/pub?key=tMIPDwydKpay-5Oq0_G769w&amp;single=true&amp;gid=0&amp;output=csv&#039;);

// get rid of header row
$headers = array_shift($lines);

// Loop through data- therer is only one line hear
foreach ($lines as $line) {
	$ldata =  explode(&#039;,&#039;, trim($line)); // split row to its own array of elements

	if ($ldata[0] == &#039;&#039;) break; // an empty line means we are done, so exit the foreach loop

      // now we can just output the information as an HTML list, referencing the appropriate array items
       echo &#039;&lt;li&gt;Total Miles Biking  &lt;strong&gt;&#039; . $ldata[0] . &#039;&lt;/strong&gt;&lt;/li&gt;&lt;li&gt;Total Miles Running  &lt;strong&gt;&#039; . $ldata[1] . &#039;&lt;/strong&gt;&lt;/li&gt;&lt;li&gt;Total Hours Running  &lt;strong&gt;&#039; . $ldata[2] . &#039;&lt;/strong&gt;&lt;/li&gt;&lt;li&gt;Ave Pace Running  &lt;strong&gt;&#039; . $ldata[3] . &#039;&lt;/strong&gt;&lt;/li&gt;&#039;;
}
</pre>
<p>And what is cool is there does not seem to be much of an impact of hitting Google each time. It must be &#8216;a caching. Good stuff.</p>
<p>This is pretty simple example. I am running some more complex examples on the <a href="http://virtualworlds.nmc.org/">NMC Virtual Worlds site</a> where the reason to do this was to have a larger amount of tabular data be displayed in a more readable fashion on our web site&#8211; and to make it so someone other than me can be in charge of keeping the data up to date bu simply editing a Google doc (note that a spreadsheet used for this purpose must be public viewable, so don&#8217;t mix in any company secrets in there).</p>
<p>So for example, our <a href="http://virtualworlds.nmc.org/clients/">Clients listing</a> is coming from a google spreadsheet, and the parsing tests the existence of certain items to format the output&#8211; e.g. if the organization URL column has a value, we echo the name as a hyperlink; if we have the coordinates of their land in Second Life, we add a teleport link. The code that generates this page also sorts it on output.</p>
<p>This one technically is not hitting the spreadsheet every time&#8230;. I set this up so a unix cron (a timed script) calls every hour a PHP script which generates the formatted content as a text file on the web server, so the web page actually just reads it in via an include statement&#8230; this is a simple form of caching.</p>
<p>Another page has actually two chunks of data that are generated from different spreadsheets. Out <a href="http://virtualworlds.nmc.org/land/">current land availability page</a> lists plots of Second Life land available from NMC for rental.</p>
<p><img src="http://cogdogblog.com/wp-content/uploads/2009/08/land-prices.jpg" alt="land prices" title="land prices" width="500" height="385" class="alignnone size-full wp-image-4123" /></p>
<p>The main body content is a list of land with the output formatted around data in a spreadsheet. And the current land prices on the right side come form another sheet- this way we can make adjustments to the web page at any time simply by editing a spreadsheet, and never touch the web page- again it works like this:</p>
<ol>
<li>Every hour a cron script on the server calls a PHP script.</li>
<li>The  PHP script reads in CSV data, sucks it into an array (one line as an item), marches through items, and parses each item as an array representing the cells, and outputs the formatted as HTML to a small text file.</li>
<li>The WordPress page simply uses an include statement to display the content (I use the <a href="http://bluesome.net/post/2005/08/18/50/">Exec-PHP plugin</a> to be able to run statements in a page).</li>
</ol>
<p>I am thinking more and more how I can use this process&#8230;.</p>
<p> Of course, this is all baby stuff compared to the masterful data wrangling by the <a href="http://ouseful.info">Jedi Master Tony Hirst</a>&#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://cogdogblog.com/2009/08/31/google-spreadsheets/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
		<item>
		<title>WordPress Shazam! Your Category is Now a Page</title>
		<link>http://cogdogblog.com/2009/05/22/wordpress-shazam/</link>
		<comments>http://cogdogblog.com/2009/05/22/wordpress-shazam/#comments</comments>
		<pubDate>Fri, 22 May 2009 23:57:42 +0000</pubDate>
		<dc:creator>Alan Levine</dc:creator>
				<category><![CDATA[Blog Pile]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://cogdogblog.com/?p=3689</guid>
		<description><![CDATA[cc licensed flickr photo shared by ElDave The main navigation of most WordPress sites is driven by cycling through all of the content that are WordPress pages&#8211; which is nice, but sometimes you have content that you don;t want cluttering the navbar. Or maybe you want to insert something that is not a Page into the navbar. I&#8217;ve been amazed that so few people seem to know how to subvert it, and below is a little trick I use when I want to wedge some other kind of WordPress content into the navbar by Pages process. Mostly this is in your HEAD&#8230; I mean the header.php file of your templates that generates it as an Unordered List: &#60;div id=&#34;nav&#34;&#62; &#60;ul&#62; &#160;&#160;&#60;li class=&#34;&#60;?php if (is_home()) {echo &#039;page_item current_page_item&#039;; } ?&#62;&#34;&#62; &#160;&#160;&#160;&#160;&#60;a href=&#34;&#60;?php echo get_settings(&#039;home&#039;); ?&#62;/&#34;&#62;Home&#60;/a&#62;&#60;/li&#62; &#160;&#160;&#60;?php wp_list_pages(&#039;title_li&#039; ); ?&#62; &#60;/ul&#62; &#60;/div&#62; The first li item creates the Home link, and in [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Shazam!" href="http://flickr.com/photos/eldave/179559545/"><img src="http://farm1.static.flickr.com/72/179559545_f2acaca5aa.jpg" /></a><br /><small><a title="Shazam!" href="http://flickr.com/photos/eldave/179559545/">cc licensed flickr photo</a> shared by <a href="http://flickr.com/people/eldave/">ElDave</a></small></p>
<p>The main navigation of most WordPress sites is driven by cycling through all of the content that are WordPress pages&#8211; which is nice, but sometimes you have content that you don;t want cluttering the navbar. Or maybe you want to insert something that is not a Page into the navbar. I&#8217;ve been amazed that so few people seem to know how to subvert it, and below is a little trick I use when I want to wedge some other kind of WordPress content into the navbar by Pages process.</p>
<p>Mostly this is in your HEAD&#8230; I mean the <code>header.php</code> file of your templates that generates it as an Unordered List:</p>
<p><pre><pre>&lt;div id=&quot;nav&quot;&gt;
&lt;ul&gt;
&nbsp;&nbsp;&lt;li class=&quot;&lt;?php if (is_home()) {echo &#039;page_item current_page_item&#039;; } ?&gt;&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;a href=&quot;&lt;?php echo get_settings(&#039;home&#039;); ?&gt;/&quot;&gt;Home&lt;/a&gt;&lt;/li&gt;
&nbsp;&nbsp;&lt;?php wp_list_pages(&#039;title_li&#039; ); ?&gt;
&lt;/ul&gt;
&lt;/div&gt;</pre></pre></p>
<p>The first li item creates the Home link, and in thes case applies some CSS logic if the home page is in view. The rest of it happens in the PHP code statement that uses the WordPress fucntion to return a list of all Pages and putting each one in an <code>
<li></code> tag and set to link from the title.</p>
<p>To customize which Pages are used, you need to find the WordPress ID of the pages you want to include or exclude; the easy way is to go to the Edit Pages part of your dashboard, mouse over the page links, and look for the part of the URL that says <code>id=X</code> </p>
<p>If you don&#8217;t want all your pages, you can either exclude certain ones, say ID 5 and 11 by changing the line above to:<br />
<pre>&lt;?php wp_list_pages(&#039;exclude=5,11&amp;title_li&#039; ); ?&gt;</pre></p>
<p>Or, if in a current case, I have tons of pages but only want say 5 of them in my navigation, I can use:</p>
<p><pre>&lt;?php wp_list_pages(&#039;include=3,5,12,23,34&amp;title_li&#039; ); ?&gt;</pre></p>
<p>If you want to have more control over the order of links than alphabetical, add this little bit of code (broken in half for readability):</p>
<p><pre><pre>&lt;?php wp_list_pages(&#039;include=3,5,12,23,34
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp;title_li&amp;sort_column=menu_order&#039; ) ?&gt;</pre></pre></p>
<p>and for each page, you can modify the value of the Order field for your Page (under attributes) using integers to define the load order.. I love how it says below this box:</p>
<blockquote><p>Pages are usually ordered alphabetically, but you can put a number above to change the order pages appear in. (We know this is a little janky, it’ll be better in future releases.)</p></blockquote>
<p>It has been just as janky for like 5 years ;-)</p>
<p>What if you want one of your nav links to connect to something outside your blog? If you can live with it before or after the list of pages, you can just card code an extra <code>
<li></code> item</p>
<p><pre><pre>
&lt;div id=&quot;nav&quot;&gt;
&lt;ul&gt;
&nbsp;&nbsp;&lt;li class=&quot;&lt;?php if (is_home()) {echo &#039;page_item current_page_item&#039;; } ?&gt;&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;a href=&quot;&lt;?php echo get_settings(&#039;home&#039;); ?&gt;/&quot;&gt;Home&lt;/a&gt;&lt;/li&gt;
&nbsp;&nbsp;&lt;li&gt;&lt;a href=&quot;http://cogdogblog.com/&quot;&gt;Good Stuff&lt;/a&gt;&lt;/li&gt;
&nbsp;&nbsp;&lt;?php wp_list_pages(&#039;title_li&#039; ); ?&gt;
&nbsp;&nbsp;&lt;li&gt;&lt;a href=&quot;http://flickr.com/photos/cogdog&quot;&gt;Photos&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
</pre></pre></p>
<p>See, not too hard to  customize.</p>
<p>And now the magic tricks&#8211; I had a case today 9and elsewhere) where I wanted something like a WordPress Category or Tag Name to be part of my navbar flow, and needing it to be somewhere in the middle of my page orders (thus I could not use the extra <code>
<li></code> insertion).</p>
<p>I do this by a little misdirection. Let&#8217;s say I use a tag for my resource site called &#8220;Tips&#8221; to organize all my posts that are helpful tips- I thus have some sort of URL like <strong>http://www.mycoolstuff.org/tag/tips</strong> that I want to be part if my nav set of links.</p>
<p>First I create a fake placeholder WordPress page called My Cool Tips, which you can get to via the URL <strong>http://www.mycoolstuff.org/my-cool-tips</strong></p>
<p>I then go into by Apache server settings for this domain, and add a permanent redirection like:</p>
<p><pre>RedirectPermanent /tips http://www.mycoolstuff.org/my-cool-tips</pre></p>
<p>What this does is to tell my webs serve to take any request coming towards my site at http://www.mycoolstuff.org/my-cool-tips is immediately re-routed to http://www.mycoolstuff.org/tag/tips</p>
<p>but because WordPress thinks that this URL is a page, it sits it in my navbar like a Page, but any links to it are sent to the tag page archive.</p>
<p>Now, often, like on a hosted web server, you do not have access to the server apache configuration files. No problem! You can just slap it at the top of the <code>.htaccess</code> document inside your WordPress home directory.</p>
<p>I&#8217;ve done that here on CogDgBlog- I have a static page that sites outside of WordPress (it uses the WP include to access the nav bar, but it is not managed by WordPress; it is a stand alone PHP doc:</p>
<p><a href="http://cogdogblog.com/best.php">http://cogdogblog.com/best.php</a></p>
<p>But that URL is a bit&#8230;. &#8220;janky&#8221;, so in my .htaccess file, I added at the top:</p>
<p><code>RedirectPermanent /best http://cogdogblog.com/best.php</code></p>
<p>which sends any request to <a href="http://cogdogblog.com/best">http://cogdogblog.com/best</a> to the actual URL.</p>
<p>WordPress is great, but it is greater when you start tweaking and janking its insides out!</p>
]]></content:encoded>
			<wfw:commentRss>http://cogdogblog.com/2009/05/22/wordpress-shazam/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
		<item>
		<title>WP LastPosts: Cause I Keep Forgetting My Own URLs</title>
		<link>http://cogdogblog.com/2008/10/25/wp-lastposts/</link>
		<comments>http://cogdogblog.com/2008/10/25/wp-lastposts/#comments</comments>
		<pubDate>Sun, 26 Oct 2008 03:58:01 +0000</pubDate>
		<dc:creator>Alan Levine</dc:creator>
				<category><![CDATA[Blog Pile]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://cogdogblog.com/?p=2933</guid>
		<description><![CDATA[I just whipped up the puniest of WordPress hacks for the ultimate reasons, to serve myself. If I knew what I was doing, it would be a plugin, but I&#8217;ll leave that as an exercise for the reader. Here&#8217;s the thing. Whenever I write something, i like to reference by link a previous post. So I have to load my own site to find it, and man, I am tired of waiting. So my hack generates page that just in simple layout lists your latest 100 (or whatever number you wish) posts, so you can either copy the URL or edit it. It makes something like this: The code consists of 2 PHP files and a GIF image that go into your theme directory: http://cogdogblog.com/code/lastposts.zip headless.php is just a simplifed version of header.php with just some CSS in it last.php is a simple template that does all the work images/edit.gif [...]]]></description>
			<content:encoded><![CDATA[<p>I just whipped up the puniest of WordPress hacks for the ultimate reasons, to serve myself. If I knew what I was doing, it would be a plugin, but I&#8217;ll leave that as an exercise for the reader.</p>
<p>Here&#8217;s the thing. Whenever I write something, i like to reference by link a previous post. So I have to load my own site to find it, and man, I am tired of waiting. So my hack generates page that just in simple layout lists your latest 100 (or whatever number you wish) posts, so you can either copy the URL or edit it.</p>
<p>It makes something like <a href="http://cogdogblog.com/last/">this</a>:</p>
<p><a href="http://cogdogblog.com/last/"><img src="http://cogdogblog.com/wp-content/uploads/2008/10/lastposts.jpg" alt="" title="lastposts" width="500" height="284" class="alignnone size-full wp-image-2934" /></a></p>
<p>The code consists of 2 PHP files and a GIF image that go into your theme directory:<br />
<a href="http://cogdogblog.com/code/lastposts.zip">http://cogdogblog.com/code/lastposts.zip</a></p>
<ul>
<li><code>headless.php</code> is just a simplifed version of header.php with just some CSS in it
</li>
<li><code>last.php</code> is a simple template that does all the work</li>
<li><code>images/edit.gif</code> is just an icon for the output</li>
</ul>
<p>A walk through of the code of last.php follows for the curious&#8230; This first part merely provides what WP needs to list it as named template<br />
<pre><pre>&lt;?php
/*
Template Name: Last XX Posts
*/
?&gt;
</pre></pre></p>
<p>This is a little bit of useful trickery to make any page that uses this template use a different file for the header, instead of header.php- I use this often when I need to insert custom things in the HEAD of an output page:<br />
<pre><pre>
&lt;?php include (TEMPLATEPATH . &#039;/headless.php&#039;); ?&gt;
</pre></pre></p>
<p>Just the HTML set up for lists&#8230;<br />
<pre><pre>
&lt;div id=&quot;content&quot;&gt;
&lt;h1&gt;Last Posts!&lt;/h1&gt;
&lt;ol&gt;
</pre></pre></p>
<p>Now we start the work; we first run a custom query to get the last 100 posts (change the number if you want more or less). This iterates your own version of the WordPress Loop. We set up a while loop so we can walk through each one, and  we insert what is yanked from the database for a post, all of the information about/in a blog post.<br />
<pre><pre>
&lt;?php $my_query = new WP_Query(&#039;showposts=100&#039;);?&gt;
&lt;?php while ($my_query-&gt;have_posts()) : 
$my_query-&gt;the_post();?&gt;
</pre></pre></p>
<p>And here we echo what is needed to display info for one post, link to it, its title, date and time of posting, and a link to edit it (only if you are logged in with edit privs):<br />
<pre><pre>
&lt;li&gt;&lt;a href=&quot;&lt;?php the_permalink(); ?&gt;&quot; rel=&quot;bookmark&quot; 
title=&quot;Permanent Link to 
&lt;?php the_title(); ?&gt;&quot;&quot;&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;
&lt;small&gt;&lt;?php the_time(&#039;M j, Y&#039;) ?&gt; 
&lt;?php the_time(&#039;h:ia&#039;)&nbsp;&nbsp;?&gt; 
&lt;?php edit_post_link(&#039; Edit&#039;, 
&#039;&lt;img src=&quot;&#039; . get_bloginfo(&#039;template_directory&#039;)&nbsp;&nbsp;. 
&#039;/images/edit.gif&quot; 
alt=&quot;&quot; align=&quot;absmiddle&quot; /&gt; &#039;, &#039;&#039;); ?&gt;
&lt;/small&gt; &lt;/li&gt;
</pre></pre></p>
<p>And the rest just closes things up, nice and neat:<br />
<pre><pre>
&lt;?php endwhile; ?&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre></pre></p>
<p>Now to make it active, all you need to do is to create a new WordPress Page. You can put whatever you want in the title or body, cause it is never used on the output. I edit the URL path to be something like:</p>
<p>http://www.mycoolblog.com/last/</p>
<p>Now the thing to make it work is to go down to to Page Template, and select the name of this template (I called it <strong>Last XX Posts</strong>), and then Publish.</p>
]]></content:encoded>
			<wfw:commentRss>http://cogdogblog.com/2008/10/25/wp-lastposts/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
		<item>
		<title>Now Available: Source Code for Five Card Flickr</title>
		<link>http://cogdogblog.com/2008/10/22/source-code-five-card-flickr/</link>
		<comments>http://cogdogblog.com/2008/10/22/source-code-five-card-flickr/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 07:13:30 +0000</pubDate>
		<dc:creator>Alan Levine aka CogDog</dc:creator>
				<category><![CDATA[Blog Pile]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[storytelling]]></category>

		<guid isPermaLink="false">http://cogdogblog.com/?p=2895</guid>
		<description><![CDATA[I had some code fun in September creating the Five Card Stories site, which provides a simple activity in visual storytelling by making a visitor select from five rounds of randomly chosen images to string together as a story told only in pictures &#8212; now the source code is available from Google Code (I would have liked to call it alpha version 0.0000001). I designed it somewhat general, as I had two different ways I thought of getting images- one from pulling ones from a given tag in flickr and the other were taken from ones submitted at the Learning 2.008 Conference in a ning forum. The source code provides what you need to run the flickr version. On my site, there are now 516 photos people have tagged to share and as I write this, there are 290 stories that people have created and saved on the site&#8211; alot [...]]]></description>
			<content:encoded><![CDATA[<p>I had some code fun in September creating <a href="http://web.nmc.org/5cardstory">the Five Card Stories site</a>, which provides a simple activity in visual storytelling by making a visitor select from five rounds of randomly chosen images to string together as a story told only in pictures &#8212; now the <a href="http://code.google.com/p/fivecardflickr/">source code is available from Google Code</a> (I would have liked to call it alpha version 0.0000001).</p>
<p><a href="http://web.nmc.org/5cardstory"><img src="http://cogdogblog.com/wp-content/uploads/2008/10/5card-stories.jpg" alt="" title="5card-stories" width="500" height="317" class="alignnone size-full wp-image-2896" /></a></p>
<p>I designed it somewhat general, as I had two different ways I thought of getting images- <a href="http://web.nmc.org/5cardstory/flickr.php">one from pulling ones from a given tag in flickr</a> and the other were taken from <a href="http://web.nmc.org/5cardstory/learn2cn.php">ones submitted at the Learning 2.008 Conference in a ning forum</a>.</p>
<p>The source code provides what you need to run the flickr version. On my site, there are now <a href="http://flickr.com/photos/tags/5cardflickr">516 photos people have tagged to share</a> and as I write this, <a href="http://web.nmc.org/5cardstory/show.php?type=flickr">there are 290 stories</a> that people have created and saved on the site&#8211; alot of them I think came from <a href="http://www.nmc.org/2008-pachyderm-conference">an NMC conference</a> where <a href="http://www.hippasus.com/">Ruben Puentadora</a> shared it.</p>
<p>This was very fitting, since it was Ruben&#8217;s workshops on comics and storytelling that lit an idea the way use ran an activity based on <a href="http://www.7415comics.com/nancy">Five Card Nancy</a>.</p>
<p>A tricky part was the finding a way to get info from flickr on images of a specified tag. Either the API does not provide it, or I just don&#8217;t know enough about APIs (the latter most likely), but I could not figure out that route to get the info on photos of a specified tag. A twitter post got me a big boost from <a href="http://technagogy.learningfield.org/">John Krutsch</a>, who wrote some PHP that grabbed the info basically by saving as giant text variable the results of a flickr search query on the tag, and then parsing that into an array for the data needed (URL for image, name of photographer, and link to original flickr photo page).</p>
<p>John&#8217;s code worked as advertised, but at a run-time cost- the time to do the query and extract was at least 20 seconds, causing the web page that was handing out the cards to appear to be a sleeping dealer. My end around was to create a caching approach&#8211; I modified the code so when it searched, it output the array data to a text file, and on the next search, if the modified timestamp on the cache file was less than 70 minutes, it used the cache instead of taking the time to run a new query.</p>
<p>This still meant around once an hour, or at least next time a human visitor went to the sit, there would be a delay to get fresh images if the cache was &#8220;stale&#8221;. So my approach was to run an hourly cron script to do the search and update the cache file (the web server running the query does not care if it has to wait 30 seconds for data). Therefore a user of the site would always be fetcing the cached data, which at most is an hour old.</p>
<p>The code is moderately commented, but follows my own PHP pretzel logic. I am sure someone could code it much more elegantly (and I&#8217;ll roll in elegant mods), but I just posted the whole web site, code, and database set up at <a href="http://code.google.com/p/fivecardflickr/">http://code.google.com/p/fivecardflickr/</a>, released for free under GPL.</p>
<p>I have no idea if it makes sense, so I am hoping there are some eager beta testers (people with their own web servers and can manage basic PHP/MySQL stuff) who can try out the setup and see if they can get it running on another site, maybe with a different tag set then I used. I am not going to be surprised if something is wonky.</p>
<p>There&#8217;s nothing like the smell of code in the morning&#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://cogdogblog.com/2008/10/22/source-code-five-card-flickr/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
		<item>
		<title>How to Put Anything in Your MediaWiki Pages</title>
		<link>http://cogdogblog.com/2008/09/10/anything-in-your-mediawiki-pages/</link>
		<comments>http://cogdogblog.com/2008/09/10/anything-in-your-mediawiki-pages/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 00:10:15 +0000</pubDate>
		<dc:creator>Alan Levine aka CogDog</dc:creator>
				<category><![CDATA[Blog Pile]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[mediawiki]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://cogdogblog.com/?p=2753</guid>
		<description><![CDATA[Well, &#8220;anything&#8221; is loosely termed. I run about 6 different MediaWiki sites for the NMC, and I have to remind myself alot that the software is a huge black box (it works super) and I am pretty sure the things I have done tap maybe 8% of what it is capable of doing. One of the limits is the kind of content you can put in the editing pane. Sure you can add additional tags you want to allow, but even a security lazy bum like me is not interesting in allowing any person to add &#60;script&#62; tags in there. Danger, Danger, MediaWiki Robinson! So in prepping some new things for the wiki that we have reset for the 2009 NMC Horizon Project&#8211; we don&#8217;t delete the old stuff or hide them in edits; each year I migrate content to its own namespace, e.g. http://horizon.nmc.org/wiki/Horizon2007:Main_Page and http://horizon.nmc.org/wiki/Horizon2008:Main_Page. I&#8217;d like to [...]]]></description>
			<content:encoded><![CDATA[<p>Well, &#8220;anything&#8221; is loosely termed. I run about 6 different MediaWiki sites for the NMC, and I have to remind myself alot that the software is a huge black box (it works super) and I am pretty sure the things I have done tap maybe 8% of what it is capable of doing.</p>
<p>One of the limits is the kind of content you can put in the editing pane. Sure you can add additional tags you want to allow, but even a security lazy bum like me is not interesting in allowing any person to add &lt;script&gt; tags in there. <em>Danger, Danger, MediaWiki Robinson!</em></p>
<p>So in prepping some new things for <a href="http://horizon.nmc.org/wiki">the wiki that we have reset for the 2009 NMC Horizon Project</a>&#8211; we don&#8217;t delete the old stuff or hide them in edits; each year I migrate content to its own namespace, e.g. <a href="http://horizon.nmc.org/wiki/Horizon2007:Main_Page">http://horizon.nmc.org/wiki/Horizon2007:Main_Page</a> and <a href="http://horizon.nmc.org/wiki/Horizon2008:Main_Page">http://horizon.nmc.org/wiki/Horizon2008:Main_Page</a>. I&#8217;d like to know if I can have different Sidebars for these, but that&#8217;s another tinkering.</p>
<p>I was thinking a nice feature would be to add the Google Custom Search Engine I toyed with last year- a <a href="http://www.google.com/coop/cse/">CSE</a> is an incredible free tool where you can make your own search site, that rather than searching all 12 trillion Google pages, confines the search to a set of web sites that you pick. That is an amazing tool! Where is yours?</p>
<p>It was easy peasy to <a href="http://www.nmc.org/tools/horizon-cse.php">put it on the NMC web site</a>, as the page I made is completely custom PHP- it&#8217;s not even drupal, just mocked the style of the main site, and to add a drupal block with the form that pushes searches there as a block on the right sidebar at<a href=" http://horizon.nmc.org/"> http://horizon.nmc.org/</a>:</p>
<p><a href="http://www.nmc.org/tools/horizon-cse.php?cx=014131512217047653857%3Af3amcei6jt0&#038;cof=FORID%3A11&#038;q=cloud+computing&#038;sa=Search#957"><img src="http://cogdogblog.com/wp-content/uploads/2008/09/nmc-google-cse.jpg" alt="" title="nmc-google-cse" width="500" height="314" class="alignnone size-full wp-image-2754" /></a></p>
<p>But getting that functionality inside MediaWiki? Hmmmm. There is embed code provided with the GoogleCSE, but it is merely (well not so merely) a Javascript tag linked to a remote source file, and you cannot just slap JavaScript into your wiki text.</p>
<p>Then a light bulb went off- I bet it could be done by writing a custom MediaWiki Extension- <a href="http://cogdogblog.com/2006/07/14/rendering-rss-inside-media-wiki/">I had done some mods of an RSS embedding extension</a> almost 2 years ago (and still use it extensively!). You just need to know the syntax and have it spit out web content.</p>
<p><span id="more-2753"></span></p>
<p>Of course I <a href="http://www.google.com/search?q=how+to+write+mediawiki+extension">consulted an oracle</a> and at first fell into the mire that is MediaWiki &#8220;documentation&#8221; &#8211; this was really helpful:</p>
<blockquote><p>&#8230; When {{#funcname &#8230;}} is implemented as a parser function, it passes its template parameters to a PHP function instead of the usual template article. This function returns a string of wiki text that replaces the parameterized template. Parser functions are used to handle wiki text generation that involves logic that is too complex or confusing to write using normal template writing techniques&#8230;.</p></blockquote>
<p>But dipping back into the well, I found <a href="http://junkchest.blogspot.com/2005/03/wiki-adding-extensions-to-mediawiki.html">an easy example to understand at Glenn&#8217;s Junk Chest</a>.</p>
<p>So to start the explanation, first here is the working version: <a href="http://horizon.nmc.org/wiki/Horizon_Google_CSE">http://horizon.nmc.org/wiki/Horizon_Google_CSE</a>.</p>
<p>What you need besides your own Google CSE, is the code it provides where you can get embed stuff. I even got fancy and made mine so you can pass it a few tags.</p>
<p>Basically, I defined my own markup tags:<br />
<pre><pre>
&lt;gcse&gt;url|width|height|title&lt;/gsce&gt;
</pre></pre><br />
and pass it parameters so I could possible use the extension with a different CSE or do some mini customization. I could have done it really easy by no parameters and just spit out the code, but I was optimistic.</p>
<p>I could walk you through the code, but am hopeful I documented just about all the steps. <a href='http://cogdogblog.com/wp-content/uploads/2008/09/googlecsephp.txt'>Download the php code</a> It is posted as googleCSE.php.txt- simply remove the .txt entension and upload to your MediaWiki extensions directory. </p>
<p>The all you need to do is to add a line at the bottom area of your LocalSettings.php file:</p>
<p><pre>include(&quot;extensions/googleCSE.php&quot;);</pre></p>
<p>and toss some &lt;gsce&gt;&#8230;&lt;/gsce&gt;&#8230; tags into your wikitext.</p>
<p>This is a crude off the cuff demo, but it is sending off a few ricochets of ideas (so much I skipped the project I intended to do this afternoon) &#8212; this essentially means you could write extensions to put any kind of content into your wiki pages, and not necessarily let anyone put any code in the editor&#8230;</p>
<p>what do you want in your wiki?</p>
]]></content:encoded>
			<wfw:commentRss>http://cogdogblog.com/2008/09/10/anything-in-your-mediawiki-pages/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
	</item>
	</channel>
</rss>

