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

<channel>
	<title>CogDogBlog &#187; php</title>
	<atom:link href="http://cogdogblog.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://cogdogblog.com</link>
	<description>Alan Levine&#039;s space for barking about and playing with technology</description>
	<lastBuildDate>Mon, 13 Feb 2012 03:36:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>
		<item>
		<title>More Code Fun: Reading (or ‘to Read’) List</title>
		<link>http://cogdogblog.com/2010/10/22/more-code-fun-reading-or-to-read-list/</link>
		<comments>http://cogdogblog.com/2010/10/22/more-code-fun-reading-or-to-read-list/#comments</comments>
		<pubDate>Sat, 23 Oct 2010 03:59:16 +0000</pubDate>
		<dc:creator>Alan Levine aka CogDog</dc:creator>
				<category><![CDATA[Blog Pile]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[php]]></category>

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

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

	$when = getdate($ts);

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

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

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

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

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

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

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

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

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

