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

<channel>
	<title>bioneural.net &#187; php</title>
	<atom:link href="http://www.bioneural.net/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bioneural.net</link>
	<description>bioneural.net is for stuff worth sharing: commentary by Bruce McKenzie. Major topics covered are gadgets, informatics, Internet, Mac, mobile, musings, New Zealand, photography, Project Koru, quicklinks, rant, rave, travel and Windows</description>
	<pubDate>Thu, 08 May 2008 19:36:56 +0000</pubDate>
	
	<language>en</language>
	<image>
		<title>bioneural.net</title>
		<url>http://www.bioneural.net/images/kiwi-yellow-64px.png</url>
		<link>http://www.bioneural.net</link>
		<width>64</width>
		<height>64</height>
		<description>bioneural.net</description>
	</image>
		<item>
		<title>Customizing WordPress feed content</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F04%2F13%2Fcustomizing-wordpress-feed-content%2F&amp;seed_title=Customizing+WordPress+feed+content</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F04%2F13%2Fcustomizing-wordpress-feed-content%2F&amp;seed_title=Customizing+WordPress+feed+content#comments</comments>
		<pubDate>Sun, 13 Apr 2008 20:38:12 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[howto]]></category>

		<category><![CDATA[microformats]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[rss]]></category>

		<category><![CDATA[tips]]></category>

		<category><![CDATA[webdev]]></category>

		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/?p=920</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>When I last <a href="http://www.bioneural.net/2006/07/20/customizing-feeds-in-wordpress-2x/">looked</a> at customizing feeds in WordPress, it was all to do with being able to offer a summary and full text feed simultaneously&mdash;making use of WordPress' flexible feed URL syntax and a .htaccess file. In this post I look at modifying the actual contents of the feed using a <a href="http://codex.wordpress.org/Theme_Development#Functions_File" rel="external">functions.php</a> file (which may already exist as part of your current theme).<br />
<span id="more-920"></span></p>
<p>Just as WordPress provides a number of hooks for adding or removing actions in your theme header (see <a href="http://www.bioneural.net/2008/01/12/spring-clean-your-wordpress-head/">here</a>), so to do the core files that generate your feeds. Editing the core files is however discouraged (it makes upgrading a pain), and although you can build your own replacement feed templates an easy alternative is adding a few lines to your theme's functions.php file.</p>
<p class="alert">As a perpetual PHP beginner I feel obliged to warn you that use of the following code is at your own risk.</p>
<p>If there are any PHP/ WordPress experts reading this who can improve on my code please make yourself known ;-)</p>
<h4>Removing WP version info</h4>
<p>Somewhere, a while back, I read a tip about not including the WordPress version you are running in your template header&mdash;potentially allowing hackers to identify you as a target if you haven't kept up-to-date. It's easy to remove if present. For example, in the <a href="http://getk2.com/" rel="external">K2</a> theme just delete the following line from header.php:</p>
<pre><code>&lt;meta name="generator" content="WordPress &lt;?php bloginfo('version'); ?&gt;" /&gt;</code></pre>
<p>I recently released that version information was still being sent out in my feed. The feed XML contained a line like this:</p>
<pre><code>&lt;generator&gt;http://wordpress.org/?v=2.x&lt;/generator&gt;</code></pre>
<p>Thanks to Peter Westwood's helpful <a href="http://blog.ftwr.co.uk/archives/2007/10/06/improving-the-wordpress-generator/" rel="external">post</a> I used my theme's functions.php file to remove this with the following code:</p>
<pre><code>//Remove WP version info
function hide_wp_vers() { return ''; }
add_filter('the_generator','hide_wp_vers');</code></pre>
<p>So wherever <code>the_generator</code> function is called (such as in the feed templates in /wp-includes) it gets replaced with... nothing. Job done.</p>
<h4>Adding a feed image</h4>
<p>A feed image (e.g. your site logo or avatar) is an <a href="http://www.rssboard.org/rss-specification#ltimagegtSubelementOfLtchannelgt" rel="external">optional</a> part of the RSS 2.0 spec and shows up in some feed readers along with the feed description. There are plenty of tutorials (search Google) that tell you how to add a feed image by editing core template files, and there are plugins that will add one for you. I had previously edited my core RSS 2.0 template, and lost the changes during upgrades more than once. To avoid this in future here's what's now in my functions.php file:</p>
<pre><code>//Add a feed image
function feed_image() { echo "&lt;image&gt;\n\t\t&lt;title&gt;bioneural.net&lt;/title&gt;\n\t\t&lt;url&gt;http://www.bioneural.net/images/kiwi-yellow-64px.png&lt;/url&gt;\n\t\t&lt;link&gt;http://www.bioneural.net&lt;/link&gt;\n\t\t&lt;width&gt;64&lt;/width&gt;\n\t\t&lt;height&gt;64&lt;/height&gt;\n\t\t&lt;description&gt;bioneural.net&lt;/description&gt;\n\t&lt;/image&gt;\n"; }
add_action('rss2_head', 'feed_image');</code></pre>
<p>Having created my <code>feed_image</code> function I use <code>add_action</code> (<a href="http://codex.wordpress.org/Function_Reference/add_action" rel="external">Codex</a>) to insert my function via the <code>rss2_head</code> hook (<a href="http://codex.wordpress.org/Plugin_API/Action_Reference#Feed_Actions" rel="external">Codex</a>).</p>
<p>Note that <code>\n</code> means new line, <code>\t</code> means tab, and <code>\r</code> (not shown) carriage return: these are just for the sake of formatting. They have no function other than making the feed XML&mdash;which you will likely never see&mdash;look more organized:</p>
<pre><code>&lt;image&gt;
	&lt;title&gt;bioneural.net&lt;/title&gt;
	&lt;url&gt;http://www.bioneural.net/images/kiwi-yellow-64px.png&lt;/url&gt;
	&lt;link&gt;http://www.bioneural.net&lt;/link&gt;
	&lt;width&gt;64&lt;/width&gt;
	&lt;height&gt;64&lt;/height&gt;
	&lt;description&gt;bioneural.net&lt;/description&gt;
&lt;/image&gt;</code>
</pre>
<p>Here's how the above renders when viewed in <a href="http://www.bloglines.com" rel="external">Bloglines</a>:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/04/bloglines.jpg" width="295" height="89" alt="bloglines.jpg" /></p>
<p class="info"><em>Tip</em>: If you want to add a feed image but don't want to do it via a plugin or functions.php, you can use <em>Feed Image Burner</em> from <a href="http://www.feedburner.com" rel="external">FeedBurner</a>.</p>
<h4>Adding a content license</h4>
<p>I've noticed a rise in my content appearing on <a href="http://en.wikipedia.org/wiki/Spam_blog" rel="external">splogs</a>, usually in the form "[Some random name] wrote an interesting post today: here is an excerpt". This violates the <a href="http://creativecommons.org/" rel="external">Creative Commons</a> licensing of my content, which <a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="external">requires</a> correct attribution. In a similar vein I've noticed some of my images turning up on "all rights reserved" sites with no attribution. While some folk are no doubt just ignorant, the sploggers are simply morons who don't give a damn. I can't do much about the latter (although I'm giving <a href="http://redalt.com/Resources/Plugins/AntiLeech" rel="external">AntiLeech</a> a spin) but it did get me wondering what I can do to improve the visibility of my licensing terms for the benefit of those "unaware".</p>
<p>The Creative Commons Wiki <a href="http://wiki.creativecommons.org/Syndication" rel="external">links</a> to an RSS 2.0 module for annotating feeds. While this may be machine-parsable I've yet to come across a feed reader that actually picks up on it. As well as incorporating this extension I wanted to add a human-readable annotation to each feed item. This one took a bit of figuring out:</p>
<pre><code>//Add CC license to namespace, item, inline img link within description
function add_license_ns() { echo "\n\t" . 'xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"' . "\n"; }
add_action('rss2_ns', 'add_license_ns');
function add_license_item() { echo "\t" . '&lt;creativeCommons:license&gt;http://creativecommons.org/licenses/by-nc-sa/2.5/&lt;/creativeCommons:license&gt;' . "\n"; }
add_action('rss2_item', 'add_license_item');
function add_license_img($join) {
	$join = _e('&lt;p&gt;&lt;a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"&gt;&lt;img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /&gt;&lt;/a&gt; From &lt;a href="http://www.bioneural.net/about/terms/"&gt;bioneural.net&lt;/a&gt;:&lt;/p&gt;') . the_content();
	return $join;
}
add_filter('the_excerpt_rss','add_license_img');</code></pre>
<p>The first function writes the required namespace declaration; <code>add_action</code> then adds this via the <code>rss2_ns</code> hook (<a href="http://codex.wordpress.org/Plugin_API/Action_Reference#Feed_Actions" rel="external">Codex</a>). The next function/ action pair writes the module to each feed item using rss2_item (<a href="http://codex.wordpress.org/Plugin_API/Action_Reference#Feed_Actions" rel="external">Codex</a>). The third part is the human-readable bit: writing the image, text, and links and concatenating these with <code>the_content()</code> (<a href="http://codex.wordpress.org/Template_Tags/the_content" rel="external">Codex</a>) to replace <code>the_excerpt_rss()</code> (<a href="http://codex.wordpress.org/Template_Tags/the_excerpt_rss" rel="external">Codex</a>). Note also the use of the <a href="http://microformats.org/wiki/rel-license" rel="external">rel-license</a> microformat.</p>
<p class="info">For this to work you must set your <em>Reading Settings</em> in WordPress to <em>Summary</em>, even though we will be displaying the full text (replacing <code>the_excerpt_rss()</code> with <code>the_content()</code>).</p>
<p>The XML will look like this (edited for clarity):</p>
<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;rss version="2.0"
	...
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
&gt;

&lt;channel&gt;
	...
		&lt;item&gt;
		&lt;title&gt;Web developer widgets&lt;/title&gt;
		...
		&lt;description&gt;&lt;![CDATA[&lt;p&gt;&lt;a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"&gt;&lt;img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /&gt;&lt;/a&gt; From &lt;a href="http://www.bioneural.net/about/terms/"&gt;bioneural.net&lt;/a&gt;:&lt;/p&gt;&lt;p&gt;Mac-based web developers...&lt;/p&gt;]]&gt;&lt;/description&gt;
		...
		&lt;creativeCommons:license&gt;http://creativecommons.org/licenses/by-nc-sa/2.5/&lt;/creativeCommons:license&gt;
		&lt;/item&gt;</code></pre>
<p>Rendered in a feed reader humans will see this:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/04/reader.jpg" width="295" height="143" alt="reader.jpg" /></p>
<p>The Creative Commons icon is hopefully recognisable and links to the correct license; the link to bioneural.net links to <a href="http://www.bioneural.net/about/terms/">additional</a> terms of use.</p>
<p class="info"><em>Tip</em>: If you prefer not to have full text feeds containing HTML tags, you could use <code>the_content_rss('', '', '', 250)</code> (<a href="http://codex.wordpress.org/Template_Tags/the_content_rss" rel="external">Codex</a>) in place of <code>the_content()</code> to produce a 250 word text-only teaser.</p>
<h4>Expanding the feed description</h4>
<p>The text of the feed description is ordinarily the same text that appears as the tagline for your blog (set in <em>General Settings</em>). You might want to keep it short in your blog header, but perhaps send a more informative version out with your feed. </p>
<p>In K2 at least the description is only used in the head:</p>
<pre><code>&lt;meta name="description" content="&lt;?php bloginfo('description'); ?&gt;" /&gt;</code></pre>
<p>and header:</p>
<pre><code>&lt;p class="description"&gt;&lt;?php bloginfo('description'); ?&gt;&lt;/p&gt;</code></pre>
<p>One solution is therefore to replace the PHP call with short fixed text descriptions (e.g. "stuff worth sharing") in your theme template (header.php) and make the description/ tagline in WP <em>General Settings</em> longer, so it gets into your feed e.g.:</p>
<pre><code>&lt;description&gt;bioneural.net is for stuff worth sharing: commentary by Bruce McKenzie. Major topics covered are gadgets, informatics, Internet, Mac, mobile, musings, New Zealand, photography, Project Koru, quicklinks, rant, rave, travel and Windows&lt;/description&gt;</code></pre>
<p>I was unable to successfully utilize <code>rss2_head</code> (<a href="http://codex.wordpress.org/Plugin_API/Action_Reference#Feed_Actions" rel="external">Codex</a>) in a way that avoided duplicate descriptions.</p>
<p class="info"><em>Tip</em>: Another way to add a more detailed description to your feed only is to use <em>Title/Description Burner</em> from <a href="http://www.feedburner.com" rel="external">FeedBurner</a>.</p>
<h4>Adding a category image</h4>
<p>I previously used the now neglected <a href="http://coffee2code.com/archives/2004/06/27/plugin-category-images/" rel="external">Category Image(s)</a> plugin to send out a category icon with each feed item, replicating their use on my blog to readily identify Mac-related posts, etc. All I needed to do was replace the default item description with this:</p>
<pre><code>&lt;description&gt;&lt;![CDATA[&lt;?php c2c_the_category_image(); ?&gt;&lt;br /&gt;&lt;br /&gt;&lt;?php the_excerpt_rss() ?&gt;]]&gt;&lt;/description&gt;</code></pre>
<p>Sadly such a trick doesn't work with the <a href="http://wordpress.org/extend/plugins/category-icons/" rel="external">Category Icons</a> plugin I am now using, but I've been in touch with the plugin author and submitted this as a feature request.</p>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F04%2F13%2Fcustomizing-wordpress-feed-content%2F&amp;seed_title=Customizing+WordPress+feed+content/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>Web developer widgets</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F04%2F11%2Fweb-developer-widgets%2F&amp;seed_title=Web+developer+widgets</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F04%2F11%2Fweb-developer-widgets%2F&amp;seed_title=Web+developer+widgets#comments</comments>
		<pubDate>Fri, 11 Apr 2008 21:42:29 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Quicklinks]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[Mac]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/?p=917</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>Mac-based web developers may yet find a use for Dashboard. <a href="http://www.apple.com/downloads/dashboard/reference/seess.html" rel="external">SeeSS</a> is a CSS property reference detailing inheritance, CSS compliance, Safari support, possible and default values, examples, plus an informative description [<a href="http://www.bioneural.net/wp-content/uploads/2008/04/seess.jpg" rel="ibox">screenshot</a>]. <a href="http://www.apple.com/downloads/dashboard/developer/phpfunctionreference.html" rel="external">PHP Function Reference</a> provides offline access to the PHP manual, a cheat sheet, and an interactive date formatter [<a href="http://www.bioneural.net/wp-content/uploads/2008/04/phpfr.jpg" rel="ibox">screenshot</a>].</p>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F04%2F11%2Fweb-developer-widgets%2F&amp;seed_title=Web+developer+widgets/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>bioneural.net site preference panel revisited</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F01%2F22%2Fbioneuralnet-site-preference-panel-revisited%2F&amp;seed_title=bioneural.net+site+preference+panel+revisited</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F01%2F22%2Fbioneuralnet-site-preference-panel-revisited%2F&amp;seed_title=bioneural.net+site+preference+panel+revisited#comments</comments>
		<pubDate>Tue, 22 Jan 2008 20:06:51 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[howto]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[jquery]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[webdev]]></category>

		<category><![CDATA[wordpress]]></category>

		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2008/01/22/bioneuralnet-site-preference-panel-revisited/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>The <a href="http://www.bioneural.net/2006/05/11/adding-a-site-preferences-panel/">first</a> version of my site preference panel for <a href="http://wordpress.org/" rel="external">WordPress</a> needed lots of JavaScript for the toggle (<a href="http://www.bioneural.net/2008/01/06/from-protoaculous-to-jquery/">Proto.aculo.us</a>), more JavaScript to switch styles, and still more JavaScript to change text size. Version 2 still uses JavaScript for the toggle effect&mdash;but no additional load&mdash;since jQuery is already utilised by <a href="http://getk2.com/" rel="external">K2</a>. The rest is accomplished using server-side PHP, and the revised 3-column panel layout makes use of more recent CSS know-how. I've tried to modularize the preferences panel as much as possible, but some simple template editing is still required (at 4 points). It is optimised for K2 (tested using RC3 and RC4) and although I haven't tested it with other themes (that's your job!) I don't see why it couldn't be used (*Some tweaking may be required. Batteries not included.)<br />
<span id="more-785"></span></p>
<h4>Get the files</h4>
<p>Let's get it done, then come back to the how and why if you're interested. Download the files to create your own preference panel as siteprefs.zip, available <a href="http://www.bioneural.net/extra/">here</a>. Expand the archive and upload the folder "siteprefs" into your K2 main directory:</p>
<p>/wp-content/themes/k2/siteprefs/</p>
<p>At this point you may also want to download and activate the <a href="http://wordpress.org/extend/plugins/theme-switcher/" rel="external">Theme Switcher</a> plugin if you plan on allowing your audience to change the WordPress theme they see on a per-user basis (storing their preference in a cookie). Support for the plugin is built into the preference panel (see features, below).</p>
<p>It's yours to play with and customise; all I ask is that you retain the little "i" icon with it's link back to these instructions. Feedback and suggestions for improvement are welcome. If you do modify it in a novel way (or use it in a theme other than K2), please leave a comment so I and others can check it out.</p>
<p>Right then, let's hack some templates!</p>
<h4>Step 1: Look for cookies</h4>
<p>Add the following code into PHP block at the top of K2's header.php (e.g. before the closing "?&gt;"):</p>
<pre><code>// Check cookie for stored site prefs
$layout = (isset($_COOKIE['layout']) &amp;&amp; ($_COOKIE['layout'] == "alternate")) ? "alternate" : "style";</code></pre>
<p>Here, "style" is the name of your main stylesheet (style.css in K2) and "alternate" is the name of a stylesheet we'll create at Step 5. If you're not using K2 pop this between PHP start and end tags at the top of your header template and set "style" to the name of your primary CSS file.</p>
<h4>Step 2: Know your style</h4>
<p>We need to replace the relative link to your stylesheet with one into which we can insert the value of the variable <code>$layout</code>. While we're here, we might as well link to the styling for the preference panel. In the head element of header.php replace this line (or your theme's equivalent):</p>
<pre><code>&lt;link rel="stylesheet" type="text/css" media="screen" href="&lt;?php bloginfo('stylesheet_url'); ?&gt;" /&gt;</code></pre>
<p>with:</p>
<pre><code>&lt;link rel="stylesheet" type="text/css" media="screen" href="&lt;?php bloginfo('template_url'); ?&gt;/&lt;?php echo $layout; ?&gt;.css" /&gt;
&lt;link rel="stylesheet" type="text/css" media="screen" href="&lt;?php bloginfo('template_url'); ?&gt;/siteprefs/siteprefs.css" /&gt;</code></pre>
<p class="info">Your K2 custom stylesheet will still be loaded too, if you're using one.</p>
<h4>Step 3: Flick the switch</h4>
<p>Create a toggle to switch visibility of the preference panel on or off (it will be hidden on page load). The actual "switch" might be a text or an image link, inserted into an appropriate place (e.g your header or sidebar). If you prefer to add the toggle in the form of a tab in your K2 menu, look for <code>ul class="menu"</code> in header.php and replace this code:</p>
<pre><code>	&lt;?php wp_register('&lt;li class="admintab"&gt;','&lt;/li&gt;'); ?&gt;
&lt;/ul&gt;</code></pre>
<p>with the following code:</p>
<pre><code>	&lt;?php wp_register('&lt;li class="admintab"&gt;','&lt;/li&gt;'); ?&gt;
	&lt;li&gt;&lt;a id="siteprefs-toggle" href="#" title="Click to show/hide site preferences (requires JavaScript)"&gt;Prefs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;script type="text/javascript"&gt;
	jQuery(document).ready(function() {

	// hide #siteprefs as soon as the DOM is ready
	jQuery('#siteprefs').hide();

	// toggle #siteprefs on clicking the #prefs-toogle link
	jQuery('a#siteprefs-toggle').click(function() {
	jQuery('#siteprefs').slideToggle(400);
	return false;
	});

});
&lt;/script&gt;</code></pre>
<p>If you'd rather use the supplied image (sitepref2.gif), place the following code after <code>p class="description"</code> (which is within <code>div id="header"</code>) and before <code>ul class="menu"</code> in K2's header.php. </p>
<pre><code>&lt;a id="siteprefs-toggle" href="#" title="Click to show/hide site preferences (requires JavaScript)"&gt;&lt;img src="&lt;?php bloginfo('template_directory'); ?&gt;/siteprefs/img/sitepref2.gif" width="52" height="28" alt="siteprefs" /&gt;&lt;/a&gt;
&lt;script type="text/javascript"&gt;
	jQuery(document).ready(function() {

	// hide #siteprefs as soon as the DOM is ready
	jQuery('#siteprefs').hide();

	// toggle #siteprefs on clicking the #prefs-toogle link
	jQuery('a#siteprefs-toggle').click(function() {
	jQuery('#siteprefs').slideToggle(400);
	return false;
	});

});
&lt;/script&gt;</code></pre>
<p>The CSS to position the #siteprefs-toggle image within K2's header image area is included in the download (it will be ignored if you create a menu tab instead). If this position doesn't suit your theme of course you can overwrite this in siteprefs.css. </p>
<p class="info">The toggle's "slide" effect depends on jQuery, which comes with K2 by default. If you're not using K2, you'll need to include the jQuery library in your head, find an alternative JavaScript (<a href="http://www.bioneural.net/2006/05/11/adding-a-site-preferences-panel/">here</a> is how v1 did it using Proto.aculo.us), or you may wish to dispense with the toggle altogether and ventilate your preferences permanently.</p>
<h4>Step 4: Feel included</h4>
<p>The file siteprefs.php includes the XHTML and PHP to build your preference panel. As well as providing the Theme Switcher control, it works with layout.php to toggle your main and alternate stylesheets (and store your choice in a cookie), and advises your audience on link behaviour. You can change the content of these three columns as you see fit just by editing siteprefs.php.</p>
<p>To get siteprefs.php into your theme we have to include it e.g. immediately below the closing tag of the div #header in header.php, so it appears to slide out from the K2 menu:</p>
<pre><code>&lt;?php include (TEMPLATEPATH . '/siteprefs/siteprefs.php'); ?&gt;</code></pre>
<p>If you prefer you could put it at the top of your page, in the sidebar, or in the footer. Or anywhere. For sidebar placement, for example, you would likely edit siteprefs.php and siteprefs.css to respectively create and style a single vertical column.</p>
<p>At this point, if you refresh your site you should see the bioneural.net preference panel installed. If all went well and you're using a default K2 installation, you should be something like this:</p>
<p><span class="zoom">Click thumbnail to enlarge image</span><br /><a href="http://www.bioneural.net/images/enlarge/siteprefs-large.jpg" rel="ibox" title="Site preferences installed into default K2 theme (using image toggle)"><img src="http://www.bioneural.net/wp-content/uploads/2008/01/siteprefs-thumb.jpg" width="200" height="81" alt="siteprefs-thumb.jpg" /></a><br /><span class="caption">Site preferences installed into default K2 theme (using image toggle)</span></p>
<h4>Step 5: Go alternative</h4>
<p>Finally we create an alternate stylesheet, named alternate.css (the name is specified in Step 1 and in layout.php).</p>
<p>What you put in here is up to you. You will likely want to import existing styling from your main stylesheet, and then write a handful of rules which, owing to the CSS "cascade", will overwrite some of those you just imported. </p>
<p>Here's a barebones example that increases font size and turns the default K2 fixed-width theme into a fluid/ liquid layout:</p>
<pre><code>@import 'style.css';

body { font-size: 90%; } /* approx 30% larger than K2 default */
#page { width: 100% !important; border: 0; padding: 0; }
#primary { width: 100%; margin-left: -30px; padding-left: 30px; background-color: #fff;}
.content { background-color: #fff; } /* Match bg colour to #primary */
#sidebar-main.secondary { padding-left: 30px; border-right: 10px solid #f2f2f2; padding-bottom: 20px; } /* Border colour matches bg colour of .secondary */
.secondary { width: 100% !important; margin-left: -30px; background: #f2f2f2; }
#footer { background-color: #ccc; }</code></pre>
<p>Upload alternate.css into the same directory as your main stylesheet (e.g. styles.css i.e. /wp-content/themes/k2/). This is <strong>important</strong> as the switch relies on your main and alternate stylesheets being in the same directory.</p>
<p class="info">If you're having trouble overwriting rules for your alternate stylesheet, try !important e.g. <code>width: 100% !important;</code> but bear in mind IE6 will ignore it.</p>
<h4>Build notes, features and credits</h4>
<p>You don't <em>have</em> to read on&mdash;unless you're interested in how, why, and who helped make it work the way it does ;-)</p>
<h4>The toggle effect</h4>
<p>The toggle uses the <a href="http://jquery.com/" rel="external">jQuery</a> JavaScript library and the code for this was covered in a <a href="http://www.bioneural.net/2008/01/06/from-protoaculous-to-jquery/">previous</a> article.</p>
<p>What if the user doesn't have JavaScript, or has it but disabled it? Version 1 hid the preference panel on page load using CSS, and showing it required JavaScript to change the styling to "display". Version 2 uses JavaScript to initially hide the panel, so if there is no JavaScript the panel will be revealed at the outset. Furthermore, because none of the controls in the panel utilize any JavaScript, no functionality is impaired. The only (minor) outcome is that the panel can't be hidden, but at least the "accessibility" preferences are, err, accessible.</p>
<h4>A flexible 3-column framework</h4>
<p>The XHTML mark-up and CSS for this is adapted from an <a href="http://www.alistapart.com/d/multicolumnlayouts/3ColLiquid.html" rel="external">example</a> multi-column layout given in an ALA <a href="http://www.alistapart.com/articles/multicolumnlayouts" rel="external">article</a> by <a href="http://alttag.org/" rel="external">Alan Pearce</a>. Alan cleverly builds on previous work that makes use of borders to simulate equal-height columns. Initially my mark-up used borders too, but after 2 days of trying to get it to work in IE6 and 7 with in-column padding I realised I didn't need them. </p>
<p>The fixed-width two-column K2 theme I use defaults to a width of 780px. To create our basic layout we create 3 divs (one for each column), and wrap these in a container div. The container sets up the 3 columns using floats and negative margins and then uses padding to effectively pull the outer columns back inside the container! We then create a header div and a footer div, and style the width of the outer columns (including padding) to 260px i.e. one third of our page width:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/01/3-columns.jpg" width="451" height="203" alt="3-columns" /></p>
<p>We can then apply a horizontally-repeating background image to the header and footer divs, match the background colours, and clear floats for the footer to position correctly. Here's what our panel now looks like topographically:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/01/topographical.jpg" width="450" height="108" alt="topographical" /></p>
<p>But the preference panel resizes, too. If your alternate stylesheet is "fluid" i.e. page content fits to the width of the browser window, the three columns will automatically space themselves out equally to fill the window:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/01/fluid.jpg" width="450" height="64" alt="fluid" /></p>
<p class="info">Note that the left and right column width doesn't actually change, but the width of the middle column is no longer an implied 260px since we have set #siteprefs-center to occupy 100% width.</p>
<p>At this point everything is looking good&mdash;in Firefox, Safari, and IE7. You guessed it: Internet Exploder 6 is singing protest songs. We need to patch our CSS to make it work with IE6:</p>
<p class="bug">The IE escaping floats <a href="http://www.positioniseverything.net/explorer/escape-floats.html" rel="external">bug</a> causes the contents of #siteprefs-header not to display. We just add <code>width: 100%;</code> to fix this.</p>
<p class="bug">The IE doubled float-margin <a href="http://www.positioniseverything.net/explorer/doubled-margin.html" rel="external">bug</a> causes #siteprefs-right to float outside of #siteprefs-wrapper! To fix this we add <code>display: inline;</code> to #siteprefs-right.</p>
<h4>Switching whole themes</h4>
<p>The <a href="http://wordpress.org/extend/plugins/theme-switcher/" rel="external">Theme Switcher</a> plugin for WordPress is by <a href="http://boren.nu/" rel="external">Ryan Boren</a>. It sets a cookie so that the user's browser remembers their choice of theme for subsequent visits.</p>
<p>The bioneural.net preference panel uses conditional PHP to show the theme switcher dropdown menu or, if the TS plugin is not present or is present but not activated, they will see a "not enabled" message:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2008/01/styling-states.jpg" width="374" height="122" alt="styling-states.jpg" /></p>
<p>There are a few other things you might consider if you allow theme switching on your site; see Ben's <a href="http://www.instigatorblog.com/10-things-you-must-do-when-changing-wordpress-themes/2007/01/15/" rel="external">list</a>. To press the point, the preference panel includes a warning when the switcher is displayed that using it "may reduce functionality". At the very least you need to allow users to easily switch back to the previous theme&mdash;otherwise they'll have to wait a year until the cookie expires (not really; they could just delete the cookie!). In the sidebar of each theme you have installed, just paste the following:</p>
<pre><code>&lt;?php if (function_exists('wp_theme_switcher')) { ?&gt;
	&lt;?php wp_theme_switcher('dropdown'); ?&gt;
&lt;?php } ?&gt;</code></pre>
<p>If you don't like the list styling, this CSS (as used in siteprefs.css) will remove it:</p>
<pre><code>#themeswitcher { list-style: none; padding-left: 0; }</code></pre>
<h4>Switching stylesheets</h4>
<p>Previously I had used JavaScript to effect both a change in layout (fixed or fluid-width) and in text size (smaller, default, larger). Both of these are really accessibility issues&mdash;adapting to the size of your screen or the acuity of your vision. Add to this the observation that enlarging text size very soon causes problems within the confines of a fixed-width layout and it becomes clear why I decided to merge these features in version 2 i.e. biiger text, bigger container.</p>
<p>Stylesheet switching with memory is ideal, for example, if you want your iPhone/ tablet&mdash;or screen resolution-challenged work PC&mdash;to always use an alternative "accessible" layout. Cookies could likewise ensure that a different default style makes full use of your stunning 23" Apple Display.</p>
<p>Having decided against reusing the <a href="http://www.alistapart.com/stories/alternate/" rel="external">original</a> ALA styleswitcher JavaScript, and considered using jQuery (as <a href="http://kelvinluck.com/article/switch-stylesheets-with-jquery" rel="external">here</a>&mdash;also JavaScript, but better), I looked at a few PHP options and settled on Roger Johansson's <a href="http://www.456bereastreet.com/archive/200608/build_your_own_php_style_sheet_switcher/" rel="external">method</a>.</p>
<h4>Identifying off-site links</h4>
<p>By default (Option 1) any link you tag with rel="external" will display the "off-site" icon (dimmed for visited links) using the included CSS. I prefer this option for identifying off-site links because it gives your audience the choice as to how links behave (the alternative is forcing them to open new windows using JavaScript or the depreciated target="_bank"). If you haven't religiously tagged your off-site links with rel="external" (or can't be bothered), you have two alternative options:</p>
<ol>
<li>Open siteprefs.css and uncomment Option 2 (making sure the CSS for Options 1 and 3 is commented); this will apply the icon to all links other than to your own domain (<a href="http://lachy.id.au/log/2005/04/handy-css" rel="external">credit</a>). See the instructions in the file.</li>
<li>A WordPress <a href="http://sw-guide.de/wordpress/plugins/link-indication/" rel="external">plugin</a> is available that will do it for you (Option 3). Once the Link Indication plugin is activated just uncomment the CSS for Option 3 in siteprefs.css (ensuring the CSS for Options 1 and 2 is commented-out).</li>
</ol>
<p class="info">Option 1 works in Firefox, IE7, and Safari (but not IE6). Option 2 works in Firefox and Safari (but not IE7 or IE6). Option 3 works in Firefox, IE7, IE6, and Safari (but does not differentiate between visited/ unvisited links).</p>
<h4>Change log</h4>
<table class="tabulate">
<tr>
<th>Version</th>
<th>Notes</th>
</tr>
<tr>
<td>1.0</td>
<td class="odd"><em>11.05.06</em>. Initial 1.x release.</td>
</tr>
<tr>
<td>2.0</td>
<td class="odd"><em>22.01.08</em>. Initial 2.x release.</td>
</tr>
<tr>
<td>2.1</td>
<td class="odd"><em>28.01.08</em>. Corrected CSS for off-site links. Added alternative methods of identifying off-site links using <a href="http://www.w3.org/TR/2001/CR-css3-selectors-20011113/#pseudo-classes" rel="external">pseudo-class</a> (Option 2) or class (Option 3).</td>
</tr>
</table>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F01%2F22%2Fbioneuralnet-site-preference-panel-revisited%2F&amp;seed_title=bioneural.net+site+preference+panel+revisited/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>Stop WordPress character replacements</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F01%2F18%2Fput-a-stop-to-wordpress-character-replacements%2F&amp;seed_title=Stop+WordPress+character+replacements</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F01%2F18%2Fput-a-stop-to-wordpress-character-replacements%2F&amp;seed_title=Stop+WordPress+character+replacements#comments</comments>
		<pubDate>Fri, 18 Jan 2008 17:08:06 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Quicklinks]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2008/01/18/put-a-stop-to-wordpress-character-replacements/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>Is WordPress altering your punctuation behind your back e.g. converting typewriter quotes (") to smart quotes (&ldquo; &amp; &rdquo;)? It's down to the on-by-default <a href="http://codex.wordpress.org/Function_Reference/wptexturize" rel="external">wptexturize</a> function. You can <a href="http://wordpress.org/support/topic/125038" rel="external">disable</a> this by adding the following to your theme's functions.php file: remove_filter('the_content', 'wptexturize'); (for posts) and remove_filter('comment_text', 'wptexturize'); (for comments). Or, use a <a href="http://www.coffee2code.com/archives/2004/06/27/plugin-wpuntexturize/" rel="external">plugin</a>.</p>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F01%2F18%2Fput-a-stop-to-wordpress-character-replacements%2F&amp;seed_title=Stop+WordPress+character+replacements/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>Spring clean your WordPress head</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F01%2F12%2Fspring-clean-your-wordpress-head%2F&amp;seed_title=Spring+clean+your+WordPress+head</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F01%2F12%2Fspring-clean-your-wordpress-head%2F&amp;seed_title=Spring+clean+your+WordPress+head#comments</comments>
		<pubDate>Sat, 12 Jan 2008 08:00:42 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[howto]]></category>

		<category><![CDATA[metadata]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[tips]]></category>

		<category><![CDATA[webdev]]></category>

		<category><![CDATA[wordpress]]></category>

		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2008/01/12/spring-clean-your-wordpress-head/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>If you had viewed the source of my WordPress-generated pages a while ago you'd have noticed that my head elements were a real mess. Now they've been spring cleaned, arranged neatly into related groupings and the needless clutter disposed of. Plugins that use the <a href="http://codex.wordpress.org/Hook_Reference/wp_head" rel="external">wp_head</a> hook distribute junk all over the show, offending any sense of order. Luckily your WordPress theme is the key to taking control of your head, through a combination of edits to functions.php and header.php.<br />
<span id="more-771"></span></p>
<h4>Removing actions using a functions file</h4>
<p>Your theme may already include a file called <a href="http://codex.wordpress.org/Theme_Development#Functions_File" rel="external">functions.php</a>. If it doesn't you can create one using the functions file found in the default theme directory (which is a bit busy), or copy-and-paste mine (with the K2 bits stripped out for clarity):</p>
<pre><code>&lt;?php 

// De-clutter wp-head

// Really Simple Discovery
remove_action('wp_head', 'rsd_link');
// Windows Live Writer
remove_action('wp_head', 'wlwmanifest_link');
// Quoter plugin
remove_action('wp_head', 'quoter_head');
// wp-forecast plugin
remove_action('wp_head', 'wp_forecast_css');
// K2 custom header
remove_action('wp_head', array('K2Header', 'output_header_css'));

?&gt;</code></pre>
<p>The real advantage here is avoiding the need to hack any plugins or core WordPress files (an upgrader's nightmare). Let's go through the removal actions in sequence.</p>
<p><a href="http://en.wikipedia.org/wiki/Really_Simple_Discovery" rel="external">Really Simple Discovery</a> helps client software discover things about your blog. If you don't use a client and manage your posts directly in WordPress, you don't need to offer such help. The PHP script:</p>
<pre><code>remove_action('wp_head', 'rsd_link');</code></pre>
<p>will remove a line from your head that looks something like this:</p>
<pre><code>&lt;link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://www.bioneural.net/xmlrpc.php?rsd" /&gt;</code></pre>
<p><a href="http://get.live.com/writer/overview" rel="external">Windows Live Writer</a> is one such desktop blogging client, but supporting it needs yet another line in your head. The script:</p>
<pre><code>remove_action('wp_head', 'wlwmanifest_link');</code></pre>
<p>will remove a line from your head that looks something like this:</p>
<pre><code>&lt;link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://www.bioneural.net/wp-includes/wlwmanifest.xml" /&gt;</code></pre>
<p>The <a href="http://www.damagedgoods.it/wp-plugins/quoter/" rel="external">Quoter</a> plugin defaults to inserting comments, JavaScript, and CSS into your head:</p>
<pre><code>&lt;!-- Added by Quoter plugin v1.1 --&gt;
&lt;script type="text/javascript" src="http://www.bioneural.net/wp-content/plugins/quoter/quoter.php?js=1"&gt;&lt;/script&gt;
&lt;style type="text/css" media="screen"&gt;
.commentlist blockquote cite { /* Fix for Kubrik theme */
	display: inline;
}
&lt;/style&gt;</code></pre>
<p>You don't need that inline CSS if you're not using Kubrik, and can remove it with this script in functions.php:</p>
<pre><code>remove_action('wp_head', 'quoter_head');</code></pre>
<p>You can then restore functionality with a much tidier JavaScript call in an appropriate place (moving any custom CSS to your CSS file):</p>
<pre><code>&lt;script type="text/javascript" src="http://www.bioneural.net/wp-content/plugins/quoter/quoter.php?js=1"&gt;&lt;/script&gt;</code></pre>
<p>The <a href="http://www.tuxlog.de/wordpress/2007/neue-version-von-wp-forecast-v10-beta/" rel="external">wp-forecast</a> plugin insists on inline CSS too. The script:</p>
<pre><code>remove_action('wp_head', 'wp_forecast_css');</code></pre>
<p>will remove a line from your head that looks something like this (again, any CSS goes in your CSS file):</p>
<pre><code>&lt;link rel="stylesheet" href="http://www.bioneural.net/wp-content/plugins/wp-forecast/wp-forecast.css" type="text/css" media="screen" /&gt;</code></pre>
<p>The K2 theme inserts some particularly messy inline CSS:</p>
<pre><code>		&lt;style type="text/css"&gt;
										#header h1 a, #header .description {
				color: #ffffff;
			}
							&lt;/style&gt;</code></pre>
<p>We can ditch this if not using custom K2 headers as follows:</p>
<pre><code>remove_action('wp_head', array('K2Header', 'output_header_css'));</code></pre>
<p class="info">Finding the right function that adds the action can involve a bit of trial-and-error. Searching plugin (or theme) code for a partial match to an unwanted string appearing in your head is a reasonable first option.</p>
<h4>The plugin alternative</h4>
<p>The Codex <a href="http://codex.wordpress.org/Theme_Development#Functions_File" rel="external">describes</a> the functions file as being "like a plugin". This turns out to be quite literal; you could take the above functions and roll your own plugin (as suggested <a href="http://wordpress.org/support/topic/140794" rel="external">here</a>). Create a file (head-cleaner.php say) containing the actions you want removing (your list may differ from mine), upload it to /wp-content/plugins/ and activate it in the usual way:</p>
<pre><code>&lt;?php

/*
Plugin Name: Head cleaner
Description: Removes unwanted clutter from the head.
*/

// Really Simple Discovery
remove_action('wp_head', 'rsd_link');
// Windows Live Writer
remove_action('wp_head', 'wlwmanifest_link');
// Quoter plugin
remove_action('wp_head', 'quoter_head');
// wp-forecast plugin
remove_action('wp_head', 'wp_forecast_css');
// K2 custom header
remove_action('wp_head', array('K2Header', 'output_header_css'));

?&gt;</code></pre>
<h4>Other head-cleaning tips</h4>
<p>Have a poke around in your theme's header.php file, and see if you can organise it a bit better.</p>
<p>I also found I could remove the following, found in the header.php of many themes, with no adverse effects:</p>
<pre><code>&lt;?php wp_get_archives('type=monthly&amp;format=link'); ?&gt;</code></pre>
<p>This script produced a whole bunch of lines in the head having the following form:</p>
<pre><code>&lt;link rel='archives' title='January 2008' href='http://www.bioneural.net/2008/01/' /&gt;</code></pre>
<p>Removing the lengthy relative links list for archives doesn't seem <a href="http://wordpress.org/support/topic/120828" rel="external">important</a> except in <a href="http://wordpress.org/support/topic/115211" rel="external">theory</a>:</p>
<blockquote><p>
The rel="archives" does not have any specific use that I am aware of. It is used to define other pages that are archives of the site in question. In other words, it's defining pages where the content on this page will be seen in the future.
</p></blockquote>
<p>Finally, some plugins may insert code that, while not necessarily disorderly, may not be just the way you like it. For example, <a href="http://www.herewithme.fr/wordpress-plugins/simple-tags" rel="external">Simple Tags</a> can automatically insert keyword metadata into the head of each and every page. You might feel, however, that it's not sensible to associate metadata with a dynamic index page that temporarily contains tagged posts on a variety of topics. You could therefore make metadata insertion conditional, using Simple Tags manually as follows:</p>
<pre><code>&lt;?php if ( function_exists('st_meta_keywords') and is_single() ) { ?&gt;
	&lt;?php st_meta_keywords(); ?&gt;
&lt;?php } ?&gt;</code></pre>
<p>Alternatively, if you shun dependence on plugins you may want to use built-in WordPress functions, as detailed <a href="http://wordpress.org/support/topic/141783">here</a>:</p>
<pre><code>&lt;?php /* Get the meta keywords */ global $post;
if( is_single() || is_page() ) :
	$tags = get_the_tags($post-&gt;ID);
	if($tags) :
		foreach($tags as $tag) :
			$sep = (empty($keywords)) ? '' : ', ';
			$keywords .= $sep . $tag-&gt;name;
		endforeach;
?&gt;
&lt;meta name="keywords" content="&lt;?php echo $keywords; ?&gt;" /&gt;
&lt;?php
	endif;
endif;
?&gt;</code></pre>
<p>It looks like a lot more code, but remember it will still produce just the one line meta element.</p>
<p>That's enough. Too much of this sort of thing <span style="text-decoration: line-through;">cleanly</span> clearly does my head in.</p>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2008%2F01%2F12%2Fspring-clean-your-wordpress-head%2F&amp;seed_title=Spring+clean+your+WordPress+head/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>A Xmas spent upgrading bioneural.net</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2007%2F12%2F27%2Fa-xmas-spent-upgrading-bioneuralnet%2F&amp;seed_title=A+Xmas+spent+upgrading+bioneural.net</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2007%2F12%2F27%2Fa-xmas-spent-upgrading-bioneuralnet%2F&amp;seed_title=A+Xmas+spent+upgrading+bioneural.net#comments</comments>
		<pubDate>Thu, 27 Dec 2007 17:08:26 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[gallery]]></category>

		<category><![CDATA[mysql]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[webdev]]></category>

		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2007/12/27/a-xmas-spent-upgrading-bioneuralnet/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>It's amazing how much detritus accumulates in your server directories and MySQL tables over the years. Add to the mix a propensity to hack core files to the point where you dare not upgrade your packages, and you have yourself a fine mess. I hope it wasn't too obvious, but bioneural.net had developed <a href="http://www.bioneural.net/2004/03/20/filth-poverty-and-free-choice/">Diogenes syndrome</a>. It was time for a clear-out and makeover. If you're thinking that sounds like work, it is. What follows is not riveting reading, but if you're contemplating doing the same, perusing what this involved for me might help you judge how many days to set aside&mdash;and maybe bug-fix your own migration.<br />
<span id="more-753"></span></p>
<h4>Why upgrade?</h4>
<p><img src="http://www.bioneural.net/wp-content/uploads/2007/12/header-note.png" width="114" height="99" alt="header note" /></p>
<p>There were multiple reasons why I felt a major overhaul was called for:</p>
<ul>
<li>My host <a href="http://www.mediatemple.net/go/order/?refdom=bioneural.net" rel="external">(mt)</a> told me I needed to upgrade from my (ss) product to the (gs) product that had superseded it, and that if I took no action I would "loose the benefit of choosing [my] own migration timeline";</li>
<li>The (ss) product was stuck at MySQL 3.23.58 and PHP 4.4.1, whereas the (gs) upgrade offered MySQL 4.1.11 and PHP 4.4.7 or 5.2.2;</li>
<li>Such upgrades would bring security fixes, as would upgrading <a href="http://codex.gallery2.org/Gallery2:Upgrading_to_2.2.x" rel="external">Gallery</a> from 2.1.2 to 2.2.4;</li>
<li>WordPress 2.3.1 (current as of this writing) requires MySQL 4.0 or greater, so I was stuck on WordPress 2.0.11;</li>
<li>I wanted to configure ecto 3 to work with WordPress's new integral tagging system (ecto 2 did work with <a href="http://www.neato.co.nz/ultimate-tag-warrior/" rel="external">UTW</a> and some <a href="http://www.robinlu.com/blog/archives/57" rel="external">hacks</a> to xmlrpc.php);</li>
<li>I made a number of hacks to core WordPress files (xmlrpc.php, wp_rss2.php, etc.) which makes updating a pain&mdash;something I'll try to avoid in future;</li>
<li>My WordPress theme was a heavily-hacked edition of <a href="http://getk2.com/" rel="external">K2</a> Beta Two r163 and I've been unable to benefit from the many releases since;</li>
<li>More to the point, my customised theme was plain incompatible with WordPress 2.3.1;</li>
<li>I'd also hacked a number of WordPress plugins and thus using old versions, so time to start over and once again resist hacking in the interests of smoother updating.</li>
</ul>
<h4>Preparation</h4>
<p>In case of disaster I wanted to ensure I had full backups. I therefore:</p>
<ol>
<li>Made screen captures of all my current WordPress options and settings;</li>
<li>Downloaded the entire contents of my server to a backup directory on my local drive (which took a very long time, largely I think due to Gallery);</li>
<li>Used a backup <a href="http://www.ilfilosofo.com/blog/wp-db-backup" rel="external">plugin</a> to download core WordPress tables, core tables plus UTW tag tables, and all tables;</li>
<li>Created a backup of my <a href="http://haveamint.com/" rel="external">Mint</a> settings and data;</li>
<li>Used <a href="http://www.phpmyadmin.net/" rel="external">phpMyAdmin</a> to <a href="http://codex.gallery2.org/Gallery2:How_do_I_Make_Backups_of_My_Database" rel="external">backup</a> my Gallery albums etc. (not the images, but I downloaded those as above);</li>
</ol>
<h4>From (ss) to (gs)</h4>
<p>The (mt) migration tool completed in around 12 hours or so, and seemed to go (ok).</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2007/12/gs-migration.jpg" width="450" height="286" alt="gs migration" /></p>
<p>After adjusting my FTP login I uploaded an info.php file which confirmed I was now using MySQL 4.1.11 and PHP <del datetime="2007-12-29T22:41:09+00:00">4.4.7</del> 5.2.2 (after switching the default version in the control panel):</p>
<pre><code>&lt;?php phpinfo(); ?&gt;</code></pre>
<p>Although bioneural.net was there, tekoru.net wasn't. Prior to the upgrade tekoru.net was a sub-domain that pointed to ../category/project-koru/. To fix this I first had to re-create the alternate domain in the (mt) Account Center. Unfortunately visiting tekoru.net then showed </p>
<blockquote><p>
Forbidden</p>
<p>You don't have permission to access / on this server.
</p></blockquote>
<p>The reason? The new domain directory /domains/tekoru.net/html/ was empty. This could be fixed by adding an index.html file (with appropriate content) or, alternatively, using .htaccess to redirect visitors elsewhere. Thus I simply had to move the pre-existing redirect rule from my .htaccess file in /domains/bioneural.net/html/  to a new file in /domains/tekoru.net/html/ to restore normality:</p>
<pre><code>## Redirect tekoru.net to www.bioneural.net/category/project-koru/
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?tekoru\.net$ [NC]
RewriteRule ^(.*)$ http://www.bioneural.net/category/project-koru/$1 [R=301,L]</code></pre>
<h4>Upgrading WordPress</h4>
<p>I had reason to be concerned this wouldn't go well, since I had tried and failed to import an export of my WP database into the new WordPress running in a <a href="http://www.mamp.info/" rel="external">MAMP</a> environment (ending up with a blank page when trying to update the database). The live upgrade from 2.0.11 to 2.3.1, however, went almost flawlessly:</p>
<ol>
<li>Deactivate all installed plugins;</li>
<li>Overwrite all WP files except for wp-content (which requires more care);</li>
<li>Run /wp-admin/upgrade.php;</li>
<li>Apply a fix to wp_settings.php to resolve a database error related to <a href="http://dev.wp-plugins.org/wiki/WP-Cache" rel="external">WP-Cache</a>;</li>
<li>Install and activate <a href="http://cavemonkey50.com/code/full-feed/" rel="external">Full Text Feeds</a> to compensate for a daft decision on the part of the WP development team;</li>
<li>Download up-to-date versions of some of my WordPress plugins, activating them one-by-one to test for compatibility;</li>
<li>Removed comments.php from the default theme (I've found that doing so, in conjunction with other methods, significantly reduces spam);</li>
<li>Import UTW tags (Manage &gt; Import &gt; Ultimate Tag Warrior) into the new native tagging structure (they now populate the new wp_terms, wp_term_relationships, and wp_term_taxonomy <a href="http://codex.wordpress.org/Database_Description" rel="external">tables</a>).</li>
</ol>
<h4>Cleaning out old WP tables</h4>
<p>Using phpMyAdmin I dropped various disused or redundant WP tables. Most had been created by deleted plugins e.g. wp_tags as used by UTW, making my table list over twice as long as the default (shown):</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2007/12/wp-default-tables.jpg" width="450" height="136" alt="wp-default-tables.jpg" /></p>
<h4>Mint</h4>
<p>The transition from (ss) to (gs) had no adverse effect on <a href="http://www.haveamint.com/" rel="external">Mint</a>; as with WordPress to migration tool automatically changed the database name. However, I wanted to move the Mint tables into their own database.</p>
<ol>
<li>Drop backup and old Mint tables from the WordPress database in phpMyAdmin;</li>
<li>Export current Mint tables (prefixed with mint_) to file;</li>
<li>Create new database for Mint;</li>
<li>Import the file containing Mint tables;</li>
<li>Update /mint/config/dp.php with the name of the new database;</li>
<li>Tell mint about the change with /mint/?moved;</li>
<li>Delete the Mint tables from the WordPress database.</li>
</ol>
<h4>Gallery</h4>
<p>The transition from (ss) to (gs) broke my Gallery 2.1.2 installation. Before I could upgrade to the current 2.2.4 version I had to get the old one working again, in order to run the Gallery Upgrader.</p>
<p>I edited gallery2/config.php to change the name of the database and also the location of the data directory. Gallery came online again, but the Upgrader often returned me to step one, and I could not get past the system checks at step two. I was seeing the following error:</p>
<blockquote><p>
Error: Some files and or directories in your storage directory are not writeable by the webserver user. Run chown -R webserverUser /domains/bioneural.net/html/gallery2/g2data/ OR run chmod -R 777 /domains/bioneural.net/html/gallery2/g2data/.
</p></blockquote>
<p>I tried chmod 777 to g2data via SSH in Terminal:</p>
<pre><code>chmod -R 777 /home/32398/domains/bioneural.net/html/gallery2/g2data</code></pre>
<p>But still no joy. Attempting cache maintenance (/gallery2/lib/support/index.php?cache) gave a shed-load of errors similar to this (contracted):</p>
<blockquote><p>
Warning: mkdir(/domains) [function.mkdir]: Read-only file system in .../gallery2/modules/core/classes/GalleryPlatform.class on line 624</p>
<p>Warning: rename(.../gallery2/g2data/cache/module/archiveupload/0/0/0.inc) [function.rename]: No such file or directory in .../gallery2/modules/core/classes/GalleryPlatform.class on line 487
</p></blockquote>
<p>Scanning the Gallery Forums wasn't much help, although as suggested <a href="http://gallery.menalto.com/node/24616" rel="external">here</a>, I tried a test.php with the line:</p>
<pre><code>&lt;?php if (is_writable('/domains/bioneural.net/html/gallery2/g2data')) { print "yay"; } else { print "boo"; } ?&gt;</code></pre>
<p>I got "boo". It was (mt) Tech Support who came to the rescue. For (ss) Gallery's config.php read:</p>
<pre><code>$gallery-&gt;setConfig('data.gallery.base', '/var/www/html/gallery2/g2data/');</code></pre>
<p>For (gs) I had changed this to:</p>
<pre><code>$gallery-&gt;setConfig('data.gallery.base', '/domains/bioneural.net/html/gallery2/g2data/');</code></pre>
<p>But, as (mt) pointed out, it should be:</p>
<pre><code>$gallery-&gt;setConfig('data.gallery.base', '/home/32398/domains/bioneural.net/html/gallery2/g2data/');</code></pre>
<p>Gallery was back up! Thus I was able to get a "yay" out of test.php:</p>
<pre><code>&lt;?php if (is_writable('/home/32398/domains/bioneural.net/html/gallery2/g2data')) { print "yay"; } else { print "boo"; } ?&gt;</code></pre>
<p>With the old version working, I then upgraded by uploading the new files. Once again transferring the multitudinous Gallery files by FTP is a lengthy process. Once again the Upgrader kept returning me to the beginning step of the upgrade process for no apparent reason. It was very frustrating, but eventually I managed to click through to the last step and complete the process:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2007/12/upgrader.jpg" width="450" height="373" alt="upgrader.jpg" /></p>
<h4>ecto</h4>
<p>Configuring ecto 3 to <a href="http://www.labrujulaverde.com/2007/10/16/configurar-ecto-3-para-usar-los-tags-de-wordpress-23/" rel="external">work</a> with the new WP integral tagging system is not difficult. Just set it up as below:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2007/12/ecto.jpg" width="436" height="425" alt="ecto.jpg" /></p>
<p>Unfortunately it doesn't seem to play perfect; I'm noticing some odd "tags" are being downloaded&mdash;not tags at all but image file names, for example. Hmm...</p>
<h4>Regaining the bioneural.net look-and-feel</h4>
<p>I just love BBEdit's <em>Compare two front documents option</em> (in the Search menu). By opening the corresponding files from both the latest version of K2 and from my theme and running this crosscheck I could see where my edits and other codes changes occurred. The majority of discrepancies were in 4 files:</p>
<ul>
<li>header.php</li>
<li>sidebar.php</li>
<li>theloop.php</li>
<li>style.css</li>
</ul>
<p>I haven't finished rebuilding my customisation of K2 as I write this. Actually I began developing my own theme from scratch but have put this on hold, figuring that my site would be down for less time if I simply re-hacked K2 to incorporate my modifications.</p>
<h4>Miscellaneous issues</h4>
<ul>
<li>Restored various scripts e.g. <a href="http://www.ibegin.com/blog/p_ibox.html" rel="external">iBox</a>;</li>
<li>Restored SimplePie, updated <a href="http://simplepie.org/wiki/reference/simplepie/start" rel="external">syntax</a> on my <a href="http://www.bioneural.net/links/">Links</a> page (with help from (mt) here too, since I created the cache directory in the wrong place);</li>
<li>Edited Quoter plugin (as <a href="http://www.damagedgoods.it/wp-plugins/quoter/#comment-30399" rel="external">here</a>) to stop pre-quotation of earlier comments in the comment-textarea;</li>
<li>Disabled <a href="http://www.tuxlog.de/" rel="external">wp-forecast</a> as cause of errors in K2's Ajax-powered live search, live commenting, and rolling archives;</li>
<li>Edited Gallery slideshow template (as instructed <a href="http://gallery.menalto.com/node/35992" rel="external">here</a>) to alter defaults for description, time interval, and image size (<a href="http://www.bioneural.net/photos?http://www.bioneural.net/gallery2/main.php?g2_view=slideshow.Slideshow&#038;g2_itemId=2125">example</a>). NB <a href="http://www.bioneural.net/2006/11/19/fixing-feeds-for-the-siriux-gallery-theme/">fix</a> for RSS feeds using Siriux theme is no longer necessary;</li>
<li>Dropped <a href="http://txfx.net/code/wordpress/subscribe-to-comments/" rel="external">Subscribe to Comments</a> plugin as my subscriber database was being subjected to attack (also a source of bounced e-mails);</li>
<li>Dropped the <a href="http://prototype.conio.net/" rel="external">Prototype</a> JavaScript framework (and the dependent effects scripts of <a href="http://script.aculo.us/" rel="external">script.aculo.us</a> and <a href="http://cow.neondragon.net/stuff/reflection/" rel="external">Reflection.js</a>), migrating to <a href="http://jquery.com/" rel="external">jQuery</a> (as per <a href="http://stevelam.org/2007/08/k2-and-jquery/" rel="external">K2</a> and <a href="http://codex.wordpress.org/Version_2.2" rel="external">WordPress</a> itself);</li>
<li>To overcome the loss of Ajax-mediated K2 functions with the <a href="http://www.tuxlog.de/" rel="external">wp-forecast</a> plugin active, <a href="http://www.tuxlog.de/wordpress/2007/neue-version-von-wp-forecast-v10-beta/comment-page-14/#comment-1871" rel="external">rename</a> wp-forecast/functions.php to wp-forecast/funclib.php and within that file and within wp-forecast-admin.php change require_once(”functions.php”); to require_once(”funclib.php”);.</li>
</ul>
<p>What did I learn? I may not have any more <a href="http://www.bioneural.net/2007/12/15/hanging-up-the-stethoscope/">patients</a>, but I do have more patience than I thought.</p>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2007%2F12%2F27%2Fa-xmas-spent-upgrading-bioneuralnet%2F&amp;seed_title=A+Xmas+spent+upgrading+bioneural.net/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>Unravelling Amazon link formats</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2007%2F02%2F25%2Funravelling-amazon-link-formats%2F&amp;seed_title=Unravelling+Amazon+link+formats</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2007%2F02%2F25%2Funravelling-amazon-link-formats%2F&amp;seed_title=Unravelling+Amazon+link+formats#comments</comments>
		<pubDate>Sun, 25 Feb 2007 05:25:16 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[advertising]]></category>

		<category><![CDATA[amazon]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[shopping]]></category>

		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2007/02/25/unravelling-amazon-link-formats/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>According to <a href="http://www.haveamint.com/" rel="external">Mint</a>, most of my blog visitors are American. To reflect this I decided to change my default Amazon Associates links from the <a href="http://associates.amazon.co.uk" rel="external">UK</a> to the <a href="https://affiliate-program.amazon.com" rel="external">US</a>. In the process I got confused over the link syntax I should be using, but now have this sorted. For managing links to specific items on my site (automatically tagged with my Associates ID) I use Amazon Media Manager. <a href="http://www.sozu.co.uk/software/amm/" rel="external">AMM</a> is a WordPress plugin that will randomly show a specified number of product links, categories of which can be matched to categories on your blog. AMM development is not active, however, it is easy to hack the plugin to use the more recent link syntax.<br />
<span id="more-638"></span></p>
<h4>Which link to the Amazon homepage?</h4>
<p>My links to the UK store (as indicated by the -21 in my Associates ID) looked like this:</p>
<pre><code>http://www.amazon.co.uk/exec/obidos/redirect-home?tag=bioneuralblog-21&amp;amp;site=amazon</code></pre>
<p>Unfortunately you can't use the same Associates ID for each store; it is necessary to apply for an Associates ID for each program individually. Your referral fees thus cannot be combined. In my first e-mail from Amazon US I was advised that this was my unique Amazon.com homepage linking format:</p>
<pre><code>http://www.amazon.com?%5Fencoding=UTF8&amp;amp;tag=bioneuralnet-20</code></pre>
<p>Soon after I received a second e-mail confirming my application had been approved, saying that this was my unique Amazon.com homepage linking format:</p>
<pre><code>http://www.amazon.com/exec/obidos/redirect-home/bioneuralnet-20</code></pre>
<p>I contacted Customer Support and was advised to use the following syntax:</p>
<pre><code>http://www.amazon.com/?tag=bioneuralnet-20</code></pre>
<p>Hence my confusion. Some more prodding and Customer Service explained:</p>
<blockquote><p>
All of the links track to your account. Some formats are not compatible with some web building programs, so we supply a variety of linking options... the [last] link is the newest format.
</p></blockquote>
<h4>Syntax for linking to specific items</h4>
<p>It's a similar story with links to a specific Amazon.com item. For example, the AMM v1.5 plugin generates links using this syntax:</p>
<pre><code>http://www.amazon.com/exec/obidos/ASIN/0192627058/bioneuralnet-20</code></pre>
<p>However, Amazon.com advised me to use the following newer syntax to link directly to an item's detail page (although they prefer use of the Build Links <a href="http://associates.amazon.com" rel="external">tools</a>):</p>
<pre><code>http://www.amazon.com/dp/ASIN/ref=nosim/?tag=your_Associates_ID</code></pre>
<p>In this case:</p>
<ul>
<li>Replace ASIN with the 10-digit ASIN/ISBN of the product;</li>
<li>The text "ref=nosim" is what allows your visitor to be taken directly to an item's detail page when the link is used;</li>
<li>Replace "your_Associates_ID" with your Associates ID.</li>
</ul>
<p>As for the syntax AMM uses although it still works, it isn't preferred:</p>
<blockquote><p>
The API plug-in you are using, is an older link format. This format is still tracked, but instead of building more links with the old format, the new format, which goes directly to the new servers, should be used.</p>
<p>We don't "retire" old linking formats, since it would be a burden to our many Associates to have to replace old formats with new.
</p></blockquote>
<p>Fair enough. So I decided to automatically convert all my links into the new format in one fell swoop. After-all, isn't this <em>why</em> I'm using an Amazon Media <em>Manager</em>, rather than doing it all by hand?</p>
<h4>Hacking the AMM WordPress plugin</h4>
<p>It's easy to update AMM to use the more recent link syntax. There is one line in two files to change (in version 1.5 of the plugin). The first is line 294 in amm.php. Change this:</p>
<pre><code>return 'http://www.amazon' . $ext . '/exec/obidos/ASIN/' . $asin;</code></pre>
<p>To this:</p>
<pre><code>return 'http://www.amazon' . $ext . '/dp/' . $asin . '/ref=nosim/';</code></pre>
<p>The second is line 362 in amm/amm_output.php. Change this:</p>
<pre><code>return 'http://www.amazon' . $ext . '/exec/obidos/ASIN/' . $this-&gt;currentItem['amm_asin'] . '/' . $this-&gt;affiliate . '/';</code></pre>
<p>To this:</p>
<pre><code>return 'http://www.amazon' . $ext . '/dp/' . $this-&gt;currentItem['amm_asin'] . '/ref=nosim/?tag=' . $this-&gt;affiliate;</code></pre>
<p>Job done. Confusion cleared.</p>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2007%2F02%2F25%2Funravelling-amazon-link-formats%2F&amp;seed_title=Unravelling+Amazon+link+formats/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>Fixing feeds for the Siriux Gallery theme</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F11%2F19%2Ffixing-feeds-for-the-siriux-gallery-theme%2F&amp;seed_title=Fixing+feeds+for+the+Siriux+Gallery+theme</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F11%2F19%2Ffixing-feeds-for-the-siriux-gallery-theme%2F&amp;seed_title=Fixing+feeds+for+the+Siriux+Gallery+theme#comments</comments>
		<pubDate>Sun, 19 Nov 2006 09:50:23 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[gallery]]></category>

		<category><![CDATA[howto]]></category>

		<category><![CDATA[Photography]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[rss]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2006/11/19/fixing-feeds-for-the-siriux-gallery-theme/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>As previously <a href="http://www.bioneural.net/2006/06/02/iphoto-to-web-gallery-bypassing-mac/">noted</a>, the currently available RSS module (1.0.6) is incompatible with the Siriux theme for <a href="http://gallery.menalto.com" rel="external">Gallery</a> (2.1.2). I wanted to be able to offer a feed (photocast) for an album in my own <a href="http://www.bioneural.net/photos/">gallery</a>, but finding a hack for the code was only half of the problem. For some reason defining a feed in Gallery is very non-intuitive. Here's how it's done, step-by-step.<br />
<span id="more-594"></span><br />
There are perfectly valid reasons why you might want to offer a web (RSS) feed for a dynamic album on your website. In our case, as we explore and photograph <a href="http://www.bioneural.net/index.php?s=wellington">Wellington</a> ourselves, those with an interest in <a href="http://www.bioneural.net/category/project-koru/" rel="external">Project Koru</a> can visually explore with us via a photocast/ photostream. If they subscribe to the photo feed, they go where we go.</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2006/11/gallery-feeds.jpg" height="200" width="450" alt="Gallery-Feeds" /></p>
<h4>Hack the RSS module</h4>
<p>To improve compatibility with the Siriux theme, you need to edit <em>Callbacks.inc</em>, located in /gallery2/modules/rss/. As described <a href="http://sourceforge.net/tracker/index.php?func=detail&amp;aid=1508758&amp;group_id=7130&amp;atid=107130" rel="external">here</a>, make the following PHP edit:</p>
<pre><code>if (isset($blocks)) {
	foreach ($blocks as $block) {
		if ($block[0] == 'rss.RssBlock') {
		$params = $block[1];
		break;
		}
	}
}</code></pre>
<h4>Define a feed</h4>
<p>Using the instructions I found <a href="http://gallery.menalto.com/node/44720" rel="external">here</a> as a basis, with a bit of trial-and-error, the following steps proved successful. This assumes you have the RSS module installed and activated, and that the <em>Item actions</em> block is already set to display on album pages. First you need to add the RSS Feeds block:</p>
<ul>
<li>Login to your Gallery as administrator;</li>
<li><em>Edit</em> the Album for which you want to display a feed;</li>
<li>Add the <em>List of RSS Feeds </em> block to show on album (and/or photo) pages and Save.</li>
</ul>
<p>Now go to Site Admin to set up the allowed feed types:</p>
<ul>
<li>From the main menu, under <em>Export</em> choose <em>RSS</em>;</li>
<li>Uncheck <em>Allow Simple RSS Feed to be used</em> and check <em>Allow configurable RSS feeds to be used</em>;</li>
<li>Also check <em>Allow RSS feeds of photos inside an album</em> then <em>Save Settings</em>.</li>
</ul>
<p>Go back to the album for which you want to generate a feed:</p>
<ul>
<li>From the <em>album actions</em> drop-down menu, choose <em>Configure RSS Feeds</em>;</li>
<li>Add a new feed, giving it a name and description;</li>
<li>For <em>Type of feed</em>, choose <em>Items in this album</em>;</li>
<li>Set other feed options to suit and save.</li>
</ul>
<p>If successful, each page in your album should offer a clickable link to your new feed, together with a link to all feeds (if there are more) available via your Gallery installation:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2006/11/gallery-with-feed.jpg" height="530" width="450" alt="Gallery-With-Feed" /></p>
<p><em>Update 30.12.07</em>: The above edit is not necessary for Siriux version 1.1.3 as included with Gallery 2.2.4.</p>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F11%2F19%2Ffixing-feeds-for-the-siriux-gallery-theme%2F&amp;seed_title=Fixing+feeds+for+the+Siriux+Gallery+theme/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>Shorten your URLs</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F08%2F25%2Fshorten-your-urls%2F&amp;seed_title=Shorten+your+URLs</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F08%2F25%2Fshorten-your-urls%2F&amp;seed_title=Shorten+your+URLs#comments</comments>
		<pubDate>Fri, 25 Aug 2006 21:04:53 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Quicklinks]]></category>

		<category><![CDATA[mysql]]></category>

		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2006/08/25/shorten-your-urls/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p><a href="http://www.get-shorty.com" rel="external">Shorty</a> is free link aliasing utility like <a href="http://www.tinyurl.com/" rel="external">TinyURL</a> except it resides on your own server (requires PHP and MySQL). An alternative to writing redirect rules in your .htaccess file.</p>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F08%2F25%2Fshorten-your-urls%2F&amp;seed_title=Shorten+your+URLs/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
		<item>
		<title>Baking SimplePie with favicon topping</title>
		<link>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F07%2F01%2Fbaking-simplepie-with-favicon-topping%2F&amp;seed_title=Baking+SimplePie+with+favicon+topping</link>
		<comments>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F07%2F01%2Fbaking-simplepie-with-favicon-topping%2F&amp;seed_title=Baking+SimplePie+with+favicon+topping#comments</comments>
		<pubDate>Sat, 01 Jul 2006 00:17:52 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[howto]]></category>

		<category><![CDATA[metadata]]></category>

		<category><![CDATA[opml]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[rss]]></category>

		<category><![CDATA[webdev]]></category>

		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.bioneural.net/2006/07/01/baking-simplepie-with-favicon-topping/</guid>
		<description><![CDATA[<p><a href="http://creativecommons.org/licenses/by-nc-sa/2.5/" rel="license" title="This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License"><img src="http://www.bioneural.net/wp-content/themes/k2bn/styles/bioneural/cc.png" alt="CC" /></a> From <a href="http://www.bioneural.net/about/terms/">bioneural.net</a>:</p><p>Having <a href="http://www.bioneural.net/2006/06/15/embedding-istockphoto-feeds-revisited/">settled</a> on <a href="http://simplepie.org/" rel="external">SimplePie</a> as a solution for embedding iStockPhoto feeds, I decided to see if I could use it to parse the latest posts from multiple sites in my <a href="http://en.wikipedia.org/wiki/OPML" rel="external">OPML</a> file (<a href="http://en.wikipedia.org/wiki/Blogroll" rel="external">blogroll</a> if you prefer). Would it really be as simple to cook as it sounded? There were qualifiers, however. I wanted to show only a selection of headlines at any one time. I wanted to vary the order in which the sites were listed. And I wanted to automatically fetch and display the favicon for each site. Armed only with copy-and-paste level PHP know-how, I was going to need help in the kitchen&mdash;that much was clear at the outset.<br />
<span id="more-522"></span></p>
<p class="info"><em>Update 18.08.06</em>: Ryan has <a href="http://simplepie.org/support/viewtopic.php?pid=1029#p1029" rel="external">added</a> error handling for feeds which specify no author; this eliminates most of the fatal errors I was getting with some feeds. If a particular feed doesn't work for you there are several things to try: Is it specified in the page (required for auto-discovery) or must you specify the full feed URL cf. the domain name? Is the feed <a href="http://validator.w3.org/feed/" rel="external">valid</a>? If a site offers RSS and Atom feeds (WordPress sites do by default) try varying the feed format. Also, specifying the actual feed path rather than relying on auto-discovery should reduce display time. Many thanks Ryan!</p>
<h4>Link lists</h4>
<p>Lists of links to other sites are just plain boring. But they can be functional, potentially serving a number of purposes:</p>
<ul>
<li>Bookmarks that the siteowner uses to track sites of personal interest;</li>
<li>Serving readers by linking to sites with related news or resources;</li>
<li>Reciprocal link exchange (with the aim of increasing one's <a href="http://en.wikipedia.org/wiki/PageRank" rel="external">PageRank</a>/ Google listing);</li>
<li>Giving credit (e.g. services or software used in site construction);</li>
<li>Social bookmarking (e.g. <a href="http://del.icio.us/help/linkrolls" rel="external">my del.icio.us</a>);</li>
<li>Content for a sideblog or <a href="http://codex.wordpress.org/Adding_Asides" rel="external">asides</a> using RSS syndication.</li>
</ul>
<p><a href="http://www.wordpress.org" rel="external">WordPress</a> includes a links <a href="http://codex.wordpress.org/Links_Manager" rel="external">manager</a>, which has the option to tag links with <a href="http://gmpg.org/xfn/" rel="external">XFN</a> metadata using the "rel" link attribute. Such link relationships may involve self-identification/ site ownership, friendship type, a record of physical meetings (!), professional associations, geographic location, family or romantic ties. XFN is a tool for social networking much as <a href="http://del.icio.us/" rel="external">Del.icio.us</a> and <a href="http://digg.com/" rel="external">Digg</a> are tools for social bookmarking. Personally, I think this is taking link lists a bit far (and I <em>like</em> to be organized!).</p>
<p>Link lists can still be <em>more</em> functional than mere lists, even without tagging them with such metadata. Why list a site by name day-after-day? It doesn't change, yet the content of the site does. Sometimes, so does the author. And how do you know when it last had new content? But what is function without form, right? We also want our link lists to be aesthetically pleasing (OK, pretty).</p>
<p>So the aim here is to improve on the basic link list: to make it both more functional <em>and</em> more attractive.</p>
<h4>Prepare your ingredients</h4>
<p>We don't need much actually:</p>
<ul>
<li>An <a href="http://simplepie.org/docs/plugins/wordpress/" rel="external">installation</a> and activation of the SimplePie WordPress plugin (but you don't <a href="http://simplepie.org/docs/installation/requirements/" rel="external">need</a> WordPress or if you do have WordPress, you don't need to install the plugin if you follow <a href="http://simplepie.org/docs/installation/getting-started/" rel="external">these</a> instructions);</li>
<li>A WordPress page <a href="http://codex.wordpress.org/Pages#Page_Templates" rel="external">template</a> for the <a href="http://getk2.com/" rel="external">K2</a> theme (this is how I chose to implement it; again you don't need WordPress, and if you do have it but don't use K2 you can create your own page template);</li>
<li>An OPML file from which to extract the links (easy to export from <a href="http://www.newsgator.com/NGOLProduct.aspx?ProdID=NetNewsWire" rel="external">NetNewsWire</a>);</li>
<li>Some generic PHP code to shuffle and pick from a list. I found a snippet I thought would do at <a href="http://www.scriptygoddess.com" rel="external">Scriptygoddess</a>;</li>
<li>A Guru. I am indebted to Ryan Parman, one of the two SimplePie developers, for his patience and much-appreciated assistance via the SimplePie Support <a href="http://simplepie.org/support/" rel="external">Forum</a>.</li>
</ul>
<h4>Every pie needs a good base</h4>
<p>I didn't even realize WordPress page templates existed until I read Kristin's <a href="http://www.wiphey.com/2006/02/07/wp-quicky-1-9rules-style-links-page/" rel="external">post</a>. There are two steps: first we create a template, then we create a new WordPress page and tell it to use the template we just created.</p>
<p>Here's a skeletal page template that you can adapt (or not) for your own use:</p>
<pre><code>&lt;?php
/*
    Template Name: Baking
*/
?&gt;

&lt;div class="content"&gt;

    &lt;div class="primary"&gt;

        &lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt;

            &lt;div class="item"&gt;

                &lt;div class="pagetitle"&gt;
                    &lt;h2 id="post-&lt;?php the_ID(); ?&gt;"&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark" title='Permanent Link to "&lt;?php the_title(); ?&gt;"'&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt;
                &lt;/div&gt;

                &lt;div class="itemtext"&gt;

                &lt;/div&gt;&lt;!-- Close itemtext --&gt;

            &lt;/div&gt;&lt;!-- Close item --&gt;

        &lt;?php endwhile; endif; ?&gt;

    &lt;/div&gt;&lt;!-- Close primary --&gt;

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

&lt;/div&gt;&lt;!-- Close content --&gt;

&lt;?php get_footer(); ?&gt;</code></pre>
<p>Save this as baking.php and upload to your WordPress <em>themes</em> folder.</p>
<p>In WordPress Admin, choose Manage &gt; Pages &gt; Create New Page... Give the page a title but leave the content area blank and choose "Baking" from the <em>Page Template:</em> control:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2006/07/template.jpg" height="73" width="188" alt="Template" /></p>
<p>Save the new page and you're good to go. There's nothing on this page yet of course; we'll address that shortly. Let's first consider two other elements we want to build into the page: randomness and favicons.</p>
<h4>Mix well before baking</h4>
<p><a href="http://www.scriptygoddess.com/archives/2002/04/13/random-blog-list/" rel="external">Here</a> is the Scriptygoddess <em>random blogs list</em> script:</p>
<pre><code>&lt;?
$array = file("/path/to/your/file/bloglinks.php");
shuffle($array);
for ($i=0; $i&lt;10; $i++) {
echo $array[$i];
}
?&gt;</code></pre>
<p>First the code loads the links (from an external file) into an <a href="http://uk.php.net/manual/en/language.types.array.php" rel="external">array</a>, then it <a href="http://www.php.net/shuffle" rel="external">shuffles</a> them, selecting 10 (in this case) to output to the screen. Sounds good; we'll see it adapted below.</p>
<h4>Favicon topping</h4>
<p>I'm a big fan of <a href="http://en.wikipedia.org/wiki/Favicon" rel="external">favicons</a>. They're easy to <a href="http://www.degraeve.com/favicon/" rel="external">make</a> and I've used them in my blog in conjunction with "blockquote" since my CSS <a href="http://www.bioneural.net/2004/12/21/debugging-the-bioneuralblog-redesign/">reboot</a> in 2004. For example:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2006/07/9rules-cite.jpg" height="105" width="291" alt="9Rules-Cite" /></p>
<p>Instant recognition. A 16x16 pixel image is a valuable visual aid to source attribution and can confer authority on the cited wisdom. The markup is extremely simple:</p>
<pre><code>&lt;blockquote&gt;
&lt;img src="http://9rules.com/favicon.ico" alt="favicon" width="16" height="16" /&gt;
blah blah blah...
&lt;/blockquote&gt;</code></pre>
<p>I use CSS to have the favicon display as a fixed-size block element so it sits on a line of its own. Other folk use favicons in lists, presumably for partly decorative and partly navigational reasons. Here are some examples:</p>
<ul>
<li>9rules.com <a href="http://9rules.com/en/browse/" rel="external">Communities</a>;</li>
<li>Kristin Pishdadi's <a href="http://www.wiphey.com/links/" rel="external">Low End Theory</a>;</li>
<li>Ben Gray's <a href="http://www.openswitch.org/links/" rel="external">Open Switch</a>.</li>
</ul>
<p><img src="http://www.bioneural.net/wp-content/uploads/2006/07/9rules-favicons.jpg" height="89" width="248" alt="9Rules-Favicons" /><br />
<span class="caption">A 9rules.com favicon pick-list</span></p>
<p>Ben tells me he maintains his link list manually, and pointed me towards Kristin's inspirational <a href="http://www.wiphey.com/2006/02/07/wp-quicky-1-9rules-style-links-page/" rel="external">how-to</a> post. But I'd prefer to automate favicon-finding if possible.</p>
<p>There is WP plugin, <a href="http://dev.wp-plugins.org/wiki/favatars" rel="external">Favatars</a>, that does automatically gather and cache favicons. Caching is probably necessary since, as Ben also pointed out, page load times would otherwise increase (and storing permanent local copies might not reflect the favicon in use at the site). Unfortunately the plugin only works inside the WordPress "comment loop". There's an alternative PHP script that tries to guess the favicon URL <a href="http://www.peej.co.uk/projects/favatars.html" rel="external">here</a>, but my skills were not up to repurposing this either.</p>
<p>However, we can (in most cases) display a favicon much more simply using SimplePie and a neat PHP concatenation trick&mdash;the tying together of multiple strings into a single string. You'll see this in the code below; it was a bugger of a job to get all the punctuation right&mdash;and you can stop smirking if you've been coding PHP for years&mdash;this was all new to me!</p>
<h4>It wouldn't be pie without filling</h4>
<p>We have our base, the mixer is on stand-by, and we've decided how to prepare the topping. On to the filling...</p>
<p>The best way to present this is to see the finished page. It went through several earlier iterations, but this version has been re-worked by Ryan so that the code is more efficient (not so much jumping in-and-out of PHP blocks) and so that it loads only one feed into memory at a time (apparently PHP is readily exhausted). The page is commented so your can hopefully follow what's going on, and I've left in some of the lines that you will need to uncomment (and edit) if you are not using the WordPress plugin:</p>
<pre><code>&lt;?php
/*
    Template Name: Baking v4
*/

// Require simplepie.inc not necessary as already called via WP plugin
// require($_SERVER['DOCUMENT_ROOT'] . '/wp-content/plugins/simplepie.inc'); 

// Set cache folder to non-default location as used by WP plugin
$cache = $_SERVER['DOCUMENT_ROOT'] . '/wp-content/plugins/cache';

// Create array with any number of site URLs; SimplePie will auto-detect feed location
$myfeeds = array();

$myfeeds[] = "http://www.siteone.com";
$myfeeds[] = "http://www.sitetwo.com";
$myfeeds[] = "http://www.sitethree.com";

shuffle($myfeeds); // Randomize order of the feeds in array

// Manually setting content type and character encoding not required as set via WP get_header function
// header("Content-type: text/html; charset=utf-8");
get_header();
?&gt;

&lt;div class="content"&gt;

    &lt;div class="primary"&gt;

        &lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt;

            &lt;div class="item"&gt;

                &lt;div class="pagetitle"&gt;
                    &lt;h2 id="post-&lt;?php the_ID(); ?&gt;"&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark" title='Permanent Link to "&lt;?php the_title(); ?&gt;"'&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt;
                &lt;/div&gt;

                &lt;div class="itemtext"&gt;
                    &lt;h4&gt;Recent posts elsewhere&lt;/h4&gt;

                &lt;?php
                for ($i=0; $i&lt;10; $i++) { // Where 10 = number of posts to show
                    $feed = new SimplePie($myfeeds[$i], $cache);

                    if ($feed-&gt;data) {
                        echo '&lt;div class="sploop"&gt;';

                        $max = $feed-&gt;get_item_quantity(1); // Show only 1 post, the most recent
                        for ($x = 0; $x &lt; $max; $x++) {
                            $item = $feed-&gt;get_item($x);
                            $author = $item-&gt;get_author(0);

                            echo '&lt;span class="spfavicon"&gt;&lt;a href="' . $feed-&gt;get_feed_link() . '"&gt;' . '&lt;img src="' . $feed-&gt;get_feed_link() . '/favicon.ico" alt="X" width="16" height="16" /&gt;'. '&lt;/a&gt;&lt;/span&gt;';
                            echo '&lt;span class="sptitle"&gt;&lt;a rel="external" href="' . $item-&gt;get_permalink() . '"&gt;' . $item-&gt;get_title() . '&lt;/a&gt;&lt;/span&gt;';
                            echo '&lt;span class="spauthor"&gt;&amp;mdash;By ' . $author-&gt;get_name() . '&lt;/span&gt;';
                            echo '&lt;span class="spdate"&gt; on ' . $item-&gt;get_date('j M Y') . '&lt;/span&gt;';
                        }

                        echo '&lt;/div&gt;'; // Close sploop
                    }

                    unset($feed);
                }
                ?&gt;

                &lt;/div&gt;&lt;!-- Close itemtext --&gt;

            &lt;/div&gt;&lt;!-- Close item --&gt;

        &lt;?php endwhile; endif; ?&gt;

    &lt;/div&gt;&lt;!-- Close primary --&gt;

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

&lt;/div&gt;&lt;!-- Close content --&gt;

&lt;?php get_footer(); ?&gt;</code></pre>
<h4>Making it pretty</h4>
<p>I initially wanted to add some fancy styling (hence the classes in the markup). But then sometimes less is more. I decided not to add any CSS other than a rule for positioning the favicon:</p>
<pre><code>.spfavicon img {
	display: inline;
	position: relative;
	bottom: -4px;
	border: 0;
	}</code></pre>
<p>Any more images and it would look to crowded. Perhaps you don't like white space? Feel free to make some CSS suggestions!</p>
<p>I ended up with a link list with visual attribution and exposure of the latest content, the author, and the date the site's content was last refreshed. And lots of lovely white space:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2006/07/links-1.jpg" height="350" width="351" alt="Links-1" /></p>
<p>The "live" version is <a href="http://www.bioneural.net/links/">here</a>.</p>
<h4>Caveats</h4>
<ul>
<li>Not all sites work. I don't know why&mdash;perhaps a SimplePie bug? Several URLs in my array resulted in a fatal error. I commented them all out and uncommented them one-by-one to ID the troublemakers;</li>
<li>Not all sites have a favicon at root directory level. As I mentioned I found some PHP that might help here, but didn't manage to make it work due to sheer incompetence;</li>
<li>Favicons aren't cached, but caching (and automatic favicon-finding) is a SimplePie feature <a href="http://simplepie.org/support/viewtopic.php?id=151" rel="external">request</a>.</li>
</ul>
<h4>Is there any desert?</h4>
<p>The tweaking ain't over 'till the fat lady sings... and I ain't heard me no singing. If you want to show the feed title when hovering over the favicon, make this edit:</p>
<pre><code>echo '&lt;span class="spfavicon" title="' . $feed-&gt;get_feed_title() . '" &gt;&lt;a href="' . $feed-&gt;get_feed_link() . '"&gt;' . '&lt;img src="' . $feed-&gt;get_feed_link() . '/favicon.ico" alt="X" width="16" height="16" /&gt;'. '&lt;/a&gt;&lt;/span&gt;';</code></pre>
<p>If you want to show the item description when hovering over the post title, make this edit:</p>
<pre><code>echo '&lt;span class="sptitle"&gt;&lt;a rel="external" title="' . strip_tags($item-&gt;get_description()) . '" href="' . $item-&gt;get_permalink() . '"&gt;' . $item-&gt;get_title() . '&lt;/a&gt;&lt;/span&gt;';</code></pre>
<p>Firefox already displays an excerpt only:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2006/07/ffexcerpt.jpg" height="43" width="419" alt="Ffexcerpt" /></p>
<p>Ugly missing favicons in Firefox? Safari isn't a problem as when it can't load an image you'll see this "missing image" icon:</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2006/07/nofavsafari.jpg" height="22" width="191" alt="Nofavsafari" /></p>
<p>However, Firefox renders the alt text (here "X"; "favicon" is even worse!):</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2006/07/nofavff.jpg" height="26" width="185" alt="Nofavff" /></p>
<p>We can however create a favicon-like "alt" text (still valid XHTML, although it will displease the accessibility camp) and style it so that it is inline with the existing favicons:</p>
<pre><code>echo '&lt;span class="spfavicon" title="' . $feed-&gt;get_feed_title() . '"&gt;&lt;a href="' . $feed-&gt;get_feed_link() . '"&gt;' . '&lt;img src="' . $feed-&gt;get_feed_link() . '/favicon.ico" alt="&amp;curren;" style="font-size: 24px; padding-right: 6px;" width="16" height="16" /&gt;'. '&lt;/a&gt;&lt;/span&gt;';</code></pre>
<p>You'll now see this (the CSS causes the image and the alt text to be a similar size and vertically aligned):</p>
<p><img src="http://www.bioneural.net/wp-content/uploads/2006/07/fffix.jpg" height="66" width="199" alt="Fffix" /></p>
<p>Not perfect&mdash;but to my eye at least a whole lot better!</p>
<p class="download">For your convenience, <a href="http://www.bioneural.net/docs/page-baking.zip">here</a> is a SimplePie with favicon topping and the above extra ingredients that I prepared earlier. Bake in warm oven until you see a golden crust (.zip file, 4 KB)</p>
<p><em>Update 15.12.06</em>: SimplePie 1.0 b3 introduced the get_favicon() <a href="http://simplepie.org/docs/reference/misc/get_favicon/" rel="external">function</a>. You can use this to look for a favicon in the default location and, if not present, substitute a generic alternative&mdash;as per the following code:</p>
<pre><code>echo '&lt;span class="spfavicon" title="' . $feed-&gt;get_feed_title() . '"&gt;&lt;a href="' . $feed-&gt;get_feed_link() . '"&gt;' . '&lt;img src="' . $feed-&gt;get_favicon(true, 'http://www.bioneural.net/images/nofav.jpg') . '" alt="Favicon" style="font-size: 24px; padding-right: 6px;" width="16" height="16" /&gt;'. '&lt;/a&gt;&lt;/span&gt;';</code></pre>
<img src="http://www.bioneural.net/ff309e51/26673f11/CCBot/1.0 (+http://www.commoncrawl.org/bot.html).gif" />]]></description>
		<wfw:commentRss>http://www.bioneural.net/feeder/?FeederAction=clicked&amp;feed=Articles+%28RSS2%29&amp;seed=http%3A%2F%2Fwww.bioneural.net%2F2006%2F07%2F01%2Fbaking-simplepie-with-favicon-topping%2F&amp;seed_title=Baking+SimplePie+with+favicon+topping/feed/</wfw:commentRss>
		<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/</creativeCommons:license>
	</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.160 seconds -->
