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

<channel>
	<title>Nerdaphernalia &#187; templates</title>
	<atom:link href="http://striderweb.com/nerdaphernalia/tag/templates/feed/" rel="self" type="application/rss+xml" />
	<link>http://striderweb.com/nerdaphernalia</link>
	<description>"It's All Geek To Me"</description>
	<lastBuildDate>Wed, 21 Dec 2011 18:51:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Automated Indexes and wp_reset_query()</title>
		<link>http://striderweb.com/nerdaphernalia/2008/01/automated-indexes-and-wp_reset_query/</link>
		<comments>http://striderweb.com/nerdaphernalia/2008/01/automated-indexes-and-wp_reset_query/#comments</comments>
		<pubDate>Thu, 31 Jan 2008 20:47:46 +0000</pubDate>
		<dc:creator>Stephen R</dc:creator>
				<category><![CDATA[Webcraft]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress functions]]></category>

		<guid isPermaLink="false">http://striderweb.com/nerdaphernalia/2008/01/automated-indexes-and-wp_reset_query/</guid>
		<description><![CDATA[I&#8217;ve made a code change to the WordPress indexing system outlined in my previous post. If you had problems with the template, try the new code. What I&#8217;ve done is add the wp_reset_query() function to the end of the loop that gathers the pages. This can avoid conflicts with other code that may be running [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve made a code change to the WordPress indexing system outlined in <a href="/nerdaphernalia/2008/01/automated-indexes/">my previous post</a>.  If you had problems with the template, try the new code.</p>
<p>What I&#8217;ve done is add the <code>wp_reset_query()</code> function to the end of the loop that gathers the pages.  This can avoid conflicts with other code that may be running in your templates.</p>
<p>In general, it&#8217;s good advice to any of you WordPress coders out there who use the <code>query_posts()</code> function, or in general run custom instances of the <code>$wp_query</code> object in plugins or templates.  When you&#8217;re done with whatever you&#8217;re doing, put things back the way you found them by following it up with a call to <code>wp_reset_query()</code>.</p>
<p>(By the way &#8212; it isn&#8217;t terribly well documented yet, but the original discussion leading to the function&#8217;s creation can be found at <a href="http://trac.wordpress.org/ticket/4741">http://trac.wordpress.org/ticket/4741</a>.)</p>
<hr />
© <a href="http://striderweb.com/">Stephen Rider</a> 2008
<p>This article was originally published at <a href="http://striderweb.com/nerdaphernalia">Nerdaphernalia</a>.  <a href="http://planetwordpress.planetozh.com/" rel="nofollow">Planet WordPress</a> is authorized to reproduce WordPress-related entries.  <em>If you're reading this at any other web site, the site owner is stealing copyrighted work.  Please visit the original page:</em></p>

<small><a href="http://striderweb.com/nerdaphernalia/2008/01/automated-indexes-and-wp_reset_query/">Permalink to Automated Indexes and wp_reset_query()</a></small>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://striderweb.com/nerdaphernalia/2008/01/automated-indexes-and-wp_reset_query/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Automated Indexes</title>
		<link>http://striderweb.com/nerdaphernalia/2008/01/automated-indexes/</link>
		<comments>http://striderweb.com/nerdaphernalia/2008/01/automated-indexes/#comments</comments>
		<pubDate>Wed, 09 Jan 2008 16:20:17 +0000</pubDate>
		<dc:creator>Stephen R</dc:creator>
				<category><![CDATA[GUI Goodness]]></category>
		<category><![CDATA[Webcraft]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://striderweb.com/nerdaphernalia/2008/01/automated-indexes/</guid>
		<description><![CDATA[This site has several areas where there is a page that serves as an index for a bunch of sub-pages. Some good examples seen from this page are the &#8220;Features&#8221; and &#8220;Webcraft&#8221; sections of Nerdaphernalia. If you look at those pages they are simply lists of various articles with a short description for each. Originally [...]]]></description>
			<content:encoded><![CDATA[<p>This site has several areas where there is a page that serves as an index for a bunch of sub-pages.  Some good examples seen from this page are the &#8220;<a href="/nerdaphernalia/features/">Features</a>&#8221; and &#8220;<a href="/nerdaphernalia/webcraft/">Webcraft</a>&#8221; sections of Nerdaphernalia.  If you look at those pages they are simply lists of various articles with a short description for each.</p>
<p>Originally I was simply hand-crafting those lists within the normal Page editor screen in WordPress.  More recently I&#8217;ve been tinkering with a better system, and I&#8217;ve finally gotten it working.  (It would have worked a <em>lot</em> more quickly, but a third-party plugin involved had a bug, which I had to fix myself &#8212; more on that in a moment&#8230;.)  The end result is <span class="pullquote">a straightforward system for fully automated section index pages</span>.</p>
<p>The first thing that needs to be done is to make a page template for the sections.  I made a copy of the <code>page.php</code> file in my theme and renamed it <code>section_index.php</code>.  Just below the code that displays the main content, I put the following:</p>
<pre><code >&lt;ul class="section_index"&gt;
&lt;?php
	query_posts('child_of='.$post-&gt;ID.'&amp;static=true&amp;posts_per_page=-1&amp;order=ASC');
	if(have_posts()) : while (have_posts()) : the_post(); ?&gt;
		&lt;li&gt;&lt;a href="&lt;?php the_permalink();?&gt;"&gt;&lt;?php the_title();?&gt;&lt;/a&gt;&lt;br /&gt;
		&lt;?php the_excerpt(); ?&gt;&lt;/li&gt;
	&lt;?php endwhile; endif; wp_reset_query(); ?&gt;
&lt;/ul&gt;</code>
</pre>
<p>Just below that, I removed the Comments code.  Depending on your theme, you may or may not have to do that too.</p>
<p>One more thing &#8212; in order for WordPress to recognize our new template as a Page Template, we need to put the following up at the top of the file, just inside the opening&nbsp;&#8221;<code>&lt;?php</code>&#8221; :</p>
<pre>
<code >/*
Template Name: Section Index
*/</code>
</pre>
<p>Having done that, our new template will now show up in the Edit Page screen in the &#8220;Page Template&#8221; list.  Not so fast, though!  It won&#8217;t work quite yet &#8212; there&#8217;s a bit more we need to do.  Let&#8217;s back up for a moment and take a look at one line of our template code:</p>
<pre>
<code >query_posts('child_of='.$post-&gt;ID.'&amp;static=true&amp;posts_per_page=-1&amp;order=ASC');</code>
</pre>
<p>See that &#8220;child_of&#8221; parameter?  That&#8217;s not something that WordPress recognizes.  <span class="pullquote">If you run a page with that template now, your blog will have an attack of the vapors</span>!  We need to teach it a new trick first.</p>
<p>We&#8217;re going to need two plugins, which just so happen to be A) highly complementary, and B) programmed by the same person:  Peter &#8220;westi&#8221; Westwood.  Go download and install these two plugins:</p>
<ul>
<li><a href="http://blog.ftwr.co.uk/wordpress/page-excerpt/">PJW Page Excerpt</a></li>
<li><a href="http://blog.ftwr.co.uk/wordpress/query-child-of-page/">PJW Query Child Of</a></li>
</ul>
<p><code>PJW Page Excerpt</code> is a very straightforward plugin.  You know how a blog post can have a custom &#8220;excerpt&#8221;?  Once you activate this plugin, Pages can have them too.</p>
<p><code>PJW Query Child Of</code> is going to teach WordPress that new trick we were just talking about a minute ago.  Once you activate this plugin, the <code>query_posts()</code> function in WordPress will know what to do with the <code>child_of</code> parameter.  (As a side note, this was the plugin with the bug I fixed.  Peter had accidentally uploaded an earlier version of the file&#8230;.)</p>
<p>Once you have those both activated, you need to go into the edit screen for each Page in the section, and add a bit of &#8220;summary&#8221; text in the Excerpt field.  This text is going to appear below the Page title in the index.</p>
<p>One last step and we&#8217;re done:  Go the the edit screen for the section index Page, and set the template to (you guessed it) &#8220;Section Index&#8221;.  You might want to also change the text in the main content area &#8212; that will appear above the Page listing itself.  For an example of the end result, take a look at the <a href="/nerdaphernalia/features/">Features</a> page on this site.</p>
<p>After you&#8217;ve set this up, making new sections is simple: when you make the section&#8217;s main page, set the template to &#8220;Section Index&#8221;.  Then, when making new Pages, remember to write a short description in the Excerpt section.  The index Page will automatically populate with new sub-pages as you add them.</p>
<p>One final note:  if you don&#8217;t want page descriptions in your index, and just want a raw list of Page titles, you can use the pre-existing <code><a href="http://codex.wordpress.org/wp_list_pages">wp_list_pages</a>()</code> function.  It&#8217;s part of WordPress already, so you don&#8217;t need the plugins to use it.  I think the method I describe here is a lot more flexible, but you can save some steps if your needs are simpler than mine.</p>
<p class="note">But Wait!  There&#8217;s More!  Here&#8217;s a free bonus tip for you:  Copy the following and paste it into your Section Index template file between the <code >&lt;?php the_title();?&gt;&lt;/a&gt;</code> and the <code >&lt;br /&gt;</code>.  See what happens!  <img src='http://striderweb.com/nerdaphernalia/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<pre>
<code >&lt;?php edit_post_link(__('Edit', 'sandbox'),'&lt;span class="edit-link"&gt;','&lt;/span&gt;') ?&gt;</code>
</pre>
<p>Good luck!</p>
<p class="update">[Update: added <code >wp_reset_query();</code> to the template code above.  This is a reset that might avoid some conflicts with other code running on your site.]</p>
<hr />
© <a href="http://striderweb.com/">Stephen Rider</a> 2008
<p>This article was originally published at <a href="http://striderweb.com/nerdaphernalia">Nerdaphernalia</a>.  <a href="http://planetwordpress.planetozh.com/" rel="nofollow">Planet WordPress</a> is authorized to reproduce WordPress-related entries.  <em>If you're reading this at any other web site, the site owner is stealing copyrighted work.  Please visit the original page:</em></p>

<small><a href="http://striderweb.com/nerdaphernalia/2008/01/automated-indexes/">Permalink to Automated Indexes</a></small>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://striderweb.com/nerdaphernalia/2008/01/automated-indexes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

