<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"> <channel><title>Bill Erickson, WordPress Consultant</title> <link>http://www.billerickson.net</link> <description>WordPress Consulting</description> <lastBuildDate>Fri, 25 May 2012 15:13:31 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/BillErickson" /><feedburner:info uri="billerickson" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>BillErickson</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item><title>Migrating WordPress Websites</title><link>http://feedproxy.google.com/~r/BillErickson/~3/Fn49y6YliCg/</link> <comments>http://www.billerickson.net/migrating-wordpress-websites/#comments</comments> <pubDate>Wed, 23 May 2012 20:29:19 +0000</pubDate> <dc:creator>Bill Erickson</dc:creator> <category><![CDATA[Tutorial]]></category> <category><![CDATA[migration]]></category> <category><![CDATA[wordpress]]></category> <guid isPermaLink="false">http://www.billerickson.net/?p=4277</guid> <description><![CDATA[A step-by-step guide to migrating WordPress websites.]]></description> <content:encoded><![CDATA[<p>I wrote an article two years ago on <a
href="http://www.billerickson.net/how-to-move-your-wordpress-website/">how to move your WordPress website</a>, which has been one of my most popular posts.</p><p>Over the past two years I&#8217;ve found some improvements to my process, most notably around serialized arrays.</p><h3>Before Migrating, Custom Table Prefix</h3><p>When building a new website, make sure to use a custom table prefix (you define this in wp-config.php). If you started with an existing database, use <a
href="http://tdot-blog.com/wordpress/6-simple-steps-to-change-your-table-prefix-in-wordpress">this process</a> to change the prefix.</p><p>I like to make mine <code>[clientname][date]_</code>. So if my client was Automattic and I built the website today, the prefix would be <code>automattic05232012_</code>.</p><p>This is so that there&#8217;s no risk you upload your tables to a database with the same named tables. When working on an existing site, it&#8217;s important to have both sets of tables in the database so that if there&#8217;s any issues with the migration, you can quickly switch back to the old site while you figure out the issue.</p><h3>Migration Process</h3><ol><li>Backup the database tables. I like to use <a
href="http://www.sequelpro.com/">Sequel Pro</a> to connect to my database and export them, but you can also use the <a
href="http://wordpress.org/extend/plugins/adminer/">Adminer</a> WordPress plugin or phpMyAdmin through your server&#8217;s cPanel. The default export will the a .sql file, but you might want to use one of the compressed formats. Many hosts only allow you a small file upload (like 2MB), and compressing it can help you stay under that limit.</li><li>Backup the wp-content directory. This can be as easy as FTP&#8217;ing onto your server and dragging a copy of wp-content/ to your computer. If you have SSH access and are comfortable with command line, I like to make a tarball because it is much faster to download than a lot of small files. Use a command like this: <code>tar -pvczf wp-content.tar.gz wp-content/</code>. You can also use the <a
href="http://wordpress.org/extend/plugins/wp-engine-snapshot/">WPEngine Snapshot</a> plugin to make this tarball (it will also let you back up the database, but it includes every table in the database and I prefer to be more selective).</li><li>Upload the database to the new server. If WordPress is already installed, use the Adminer plugin to add the database. If not, you might use phpMyAdmin provided by the host.</li><li>Upload <a
href="http://interconnectit.com/124/search-and-replace-for-wordpress-databases/">searchreplacedb2.php</a> to the top level of your server (wherever wp-config.php is). This is used to find all the uses of the old domain and replace them with the new domain. The reason we&#8217;re using this tool instead of simply doing it in the database is that it will work with serialized arrays. Click the above link to read more about the problem and solution. If you&#8217;re really worried about security, do this locally or on your development server so that this file never has to be on the production server.</li><li>Load the the search and replace tool at http://www.yoursite.com/searchreplacedb2.php. It will auto-populate the database information from wp-config.php. Click &#8220;Next&#8221;, select the applicable tables, then on the find/replace screen type the old and new domain. Make sure you do not include a trailing slash (correct = http://www.yoursite.com | incorrect = http://www.yoursite.com/). Do the find and replace, then remove this file from your server.</li><li>If a brand new website, upload copy of WordPress along with your custom wp-content directory. If there&#8217;s already a WordPress website live, follow the rest of the steps below.</li><li>On your computer, unpackage the wp-content tarball (if you tarballed it), and then rename the folder wp-content.new. The name doesn&#8217;t matter, it just has to be different than wp-content. Upload the folder to the same directory that has the old wp-content/ .</li><li>Open wp-config.php. Find the line that starts with $table_prefix. Comment it out, and create a new $table_prefix line with your custom table prefix. <a
href="https://gist.github.com/05cb807ce392056b7a6d">It will look something like this</a>.</li><li>Save wp-config.php, and then immediately rename wp-content/ to wp-content.old/, and wp-content.new to wp-content/</li><li>Check the website&#8217;s homepage. If anything looks wrong, switch to the old site while you figure it out. Go into wp-config.php, comment out the new table prefix and remove the commenting on the old table prefix. Rename the wp-content directories back to how they were.</li><li>If the site is working, log in and go to Settings &gt; Permalinks, then click Save. This will update the permalink structure and ensure all URLs work. Then go to Settings &gt; Privacy and make sure you have the site visible to search engines.</li></ol> <img src="http://feeds.feedburner.com/~r/BillErickson/~4/Fn49y6YliCg" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://www.billerickson.net/migrating-wordpress-websites/feed/</wfw:commentRss> <slash:comments>9</slash:comments> <feedburner:origLink>http://www.billerickson.net/migrating-wordpress-websites/</feedburner:origLink></item> <item><title>A better, and easier, grid loop</title><link>http://feedproxy.google.com/~r/BillErickson/~3/v2RIWNddO7E/</link> <comments>http://www.billerickson.net/a-better-and-easier-grid-loop/#comments</comments> <pubDate>Thu, 15 Mar 2012 18:26:58 +0000</pubDate> <dc:creator>Bill Erickson</dc:creator> <category><![CDATA[Tutorial]]></category> <category><![CDATA[genesis]]></category> <category><![CDATA[gridloop]]></category> <category><![CDATA[intermediate]]></category> <category><![CDATA[wordpress]]></category> <guid isPermaLink="false">http://www.billerickson.net/?p=4242</guid> <description><![CDATA[Use the post_class filter to easily build a multi-column listing of posts.]]></description> <content:encoded><![CDATA[<p><em>Note: This technique can be used by all WordPress themes. I&#8217;m proposing it as a replacement for the Genesis-specific grid loop, so aspects of this post might be Genesis-specific.</em></p><p>A popular request is to list posts in multiple columns. I do it on <a
href="http://www.billerickson.net/blog/">my blog</a>, and do it often on my clients&#8217; sites.</p><p>Genesis developed a Grid Loop, which you can utilize inside your Genesis themes for this effect, and is how this blog does it. While very useful, it can be difficult to set up. I believe this is because they combined two separate functions: what content to display (your query) and how to display it.</p><p>By breaking those two functions we can use another feature of Genesis, the <a
href="http://www.studiopress.com/tutorials/content-column-classes">column classes</a>, to build grid loops easier. You can also copy that CSS to any WordPress theme and make it work too.</p><p>For this example I&#8217;ll be using a <a
href="https://github.com/billerickson/BE-Gallery">Gallery theme</a> I recently built. On the archive pages, it displays posts in three columns. See the screenshot above, or <a
href="http://photography.billerickson.net/sets/all/">click here</a>) for an example.</p><h3>Step 1: Multiple columns using <code>post_class</code></h2><p>The <code>post_class</code> filter lets us customize the classes applied to each post in the loop. Since I want this to only apply to archive pages, I&#8217;m placing it in archive.php.</p><div
id="gist-2040968" class="gist"><div
class="gist-file"><div
class="gist-data gist-syntax"><div
class="highlight"><pre><div class='line' id='LC1'><span class="cp">&lt;?php</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'><span class="sd">/**</span></div><div class='line' id='LC4'><span class="sd"> * Archive Post Class</span></div><div class='line' id='LC5'><span class="sd"> * @since 1.0.0</span></div><div class='line' id='LC6'><span class="sd"> *</span></div><div class='line' id='LC7'><span class="sd"> * Breaks the posts into three columns</span></div><div class='line' id='LC8'><span class="sd"> * @link http://www.billerickson.net/code/grid-loop-using-post-class</span></div><div class='line' id='LC9'><span class="sd"> *</span></div><div class='line' id='LC10'><span class="sd"> * @param array $classes</span></div><div class='line' id='LC11'><span class="sd"> * @return array</span></div><div class='line' id='LC12'><span class="sd"> */</span></div><div class='line' id='LC13'><span class="k">function</span> <span class="nf">be_archive_post_class</span><span class="p">(</span> <span class="nv">$classes</span> <span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC14'>	<span class="nv">$classes</span><span class="p">[]</span> <span class="o">=</span> <span class="s1">&#39;one-third&#39;</span><span class="p">;</span></div><div class='line' id='LC15'>	<span class="k">global</span> <span class="nv">$wp_query</span><span class="p">;</span></div><div class='line' id='LC16'>	<span class="k">if</span><span class="p">(</span> <span class="mi">0</span> <span class="o">==</span> <span class="nv">$wp_query</span><span class="o">-&gt;</span><span class="na">current_post</span> <span class="o">||</span> <span class="mi">0</span> <span class="o">==</span> <span class="nv">$wp_query</span><span class="o">-&gt;</span><span class="na">current_post</span> <span class="o">%</span> <span class="mi">3</span> <span class="p">)</span></div><div class='line' id='LC17'>		<span class="nv">$classes</span><span class="p">[]</span> <span class="o">=</span> <span class="s1">&#39;first&#39;</span><span class="p">;</span></div><div class='line' id='LC18'>	<span class="k">return</span> <span class="nv">$classes</span><span class="p">;</span></div><div class='line' id='LC19'><span class="p">}</span></div><div class='line' id='LC20'><span class="nx">add_filter</span><span class="p">(</span> <span class="s1">&#39;post_class&#39;</span><span class="p">,</span> <span class="s1">&#39;be_archive_post_class&#39;</span> <span class="p">);</span></div></pre></div></div><div
class="gist-meta"> <a
href="https://gist.github.com/raw/2040968/ee6ae9fc7df6837df2b36b3afc856bb4ac354b4b/gistfile1.aw" style="float:right;">view raw</a> <a
href="https://gist.github.com/2040968#file_gistfile1.aw" style="float:right;margin-right:10px;color:#666">gistfile1.aw</a> <a
href="https://gist.github.com/2040968">This Gist</a> brought to you by <a
href="http://github.com">GitHub</a>.</div></div></div><p>The first line adds a class of &#8216;one-third&#8217; to all posts. Then I grab the current post counter out of <code>$wp_query</code>, and if this is the first post ( <code>0 == $wp_query->current_post</code> ) or if the remainder of the current post divided by 3 is zero (this tells us the current post is the first in a row), apply a class of &#8220;first&#8221; as well.</p><p>That&#8217;s it! You now have your content broken into multiple columns. If you want two columns, use &#8216;one-half&#8217; and divide the current post by 2. If you want four columns, use &#8216;one-fourth&#8217; and divide the current post by 4.</p><h3>Step 2: Customize the Query</h2><p>When I view the archive page now, it&#8217;s in three columns but it&#8217;s only displaying 10 posts. The last post sits by itself in its own row. I&#8217;m going to modify the main query to show 27 posts per page. You could use any number you want, just make sure it&#8217;s a multiple of columns. For more information on customizing the main query, <a
href="http://www.billerickson.net/customize-the-wordpress-query/">see this post</a>.</p><div
id="gist-2045807" class="gist"><div
class="gist-file"><div
class="gist-data gist-syntax"><div
class="highlight"><pre><div class='line' id='LC1'><span class="cp">&lt;?php</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'><span class="nx">add_filter</span><span class="p">(</span> <span class="s1">&#39;pre_get_posts&#39;</span><span class="p">,</span> <span class="s1">&#39;be_archive_query&#39;</span> <span class="p">);</span></div><div class='line' id='LC4'><span class="sd">/**</span></div><div class='line' id='LC5'><span class="sd"> * Archive Query</span></div><div class='line' id='LC6'><span class="sd"> *</span></div><div class='line' id='LC7'><span class="sd"> * Sets all archives to 27 per page</span></div><div class='line' id='LC8'><span class="sd"> * @since 1.0.0</span></div><div class='line' id='LC9'><span class="sd"> * @link http://www.billerickson.net/customize-the-wordpress-query/</span></div><div class='line' id='LC10'><span class="sd"> *</span></div><div class='line' id='LC11'><span class="sd"> * @param object $query</span></div><div class='line' id='LC12'><span class="sd"> */</span></div><div class='line' id='LC13'><span class="k">function</span> <span class="nf">be_archive_query</span><span class="p">(</span> <span class="nv">$query</span> <span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC14'>	<span class="k">if</span><span class="p">(</span> <span class="nv">$query</span><span class="o">-&gt;</span><span class="na">is_main_query</span><span class="p">()</span> <span class="o">&amp;&amp;</span> <span class="nv">$query</span><span class="o">-&gt;</span><span class="na">is_archive</span><span class="p">()</span> <span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC15'>		<span class="nv">$query</span><span class="o">-&gt;</span><span class="na">set</span><span class="p">(</span> <span class="s1">&#39;posts_per_page&#39;</span><span class="p">,</span> <span class="mi">27</span> <span class="p">);</span></div><div class='line' id='LC16'>	<span class="p">}</span></div><div class='line' id='LC17'><span class="p">}</span></div></pre></div></div><div
class="gist-meta"> <a
href="https://gist.github.com/raw/2045807/f3aeb36ad4f68100fbeed8156a412c7f632d9157/gistfile1.aw" style="float:right;">view raw</a> <a
href="https://gist.github.com/2045807#file_gistfile1.aw" style="float:right;margin-right:10px;color:#666">gistfile1.aw</a> <a
href="https://gist.github.com/2045807">This Gist</a> brought to you by <a
href="http://github.com">GitHub</a>.</div></div></div><p>This code must go in functions.php, since the main query runs before it reaches archive.php (it checks the query to figure out what template to load).</p><h3>Even easier sitewide</h3><p>If you&#8217;re using this for all listings of posts (home, archive, search&#8230;), it is even easier to set up. Put the post_class filter in functions.php so it runs sitewide, and add a conditional to check if it isn&#8217;t singular:</p><div
id="gist-2046751" class="gist"><div
class="gist-file"><div
class="gist-data gist-syntax"><div
class="highlight"><pre><div class='line' id='LC1'><span class="cp">&lt;?php</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'><span class="sd">/**</span></div><div class='line' id='LC4'><span class="sd"> * Archive Post Class</span></div><div class='line' id='LC5'><span class="sd"> * @since 1.0.0</span></div><div class='line' id='LC6'><span class="sd"> *</span></div><div class='line' id='LC7'><span class="sd"> * Breaks the posts into three columns</span></div><div class='line' id='LC8'><span class="sd"> * @link http://www.billerickson.net/code/grid-loop-using-post-class</span></div><div class='line' id='LC9'><span class="sd"> *</span></div><div class='line' id='LC10'><span class="sd"> * @param array $classes</span></div><div class='line' id='LC11'><span class="sd"> * @return array</span></div><div class='line' id='LC12'><span class="sd"> */</span></div><div class='line' id='LC13'><span class="k">function</span> <span class="nf">be_archive_post_class</span><span class="p">(</span> <span class="nv">$classes</span> <span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC14'><br/></div><div class='line' id='LC15'>	<span class="c1">// Don&#39;t run on single posts or pages</span></div><div class='line' id='LC16'>	<span class="k">if</span><span class="p">(</span> <span class="nx">is_singular</span><span class="p">()</span> <span class="p">)</span></div><div class='line' id='LC17'>		<span class="k">return</span> <span class="nv">$classes</span><span class="p">;</span></div><div class='line' id='LC18'><br/></div><div class='line' id='LC19'>	<span class="nv">$classes</span><span class="p">[]</span> <span class="o">=</span> <span class="s1">&#39;one-third&#39;</span><span class="p">;</span></div><div class='line' id='LC20'>	<span class="k">global</span> <span class="nv">$wp_query</span><span class="p">;</span></div><div class='line' id='LC21'>	<span class="k">if</span><span class="p">(</span> <span class="mi">0</span> <span class="o">==</span> <span class="nv">$wp_query</span><span class="o">-&gt;</span><span class="na">current_post</span> <span class="o">||</span> <span class="mi">0</span> <span class="o">==</span> <span class="nv">$wp_query</span><span class="o">-&gt;</span><span class="na">current_post</span> <span class="o">%</span> <span class="mi">3</span> <span class="p">)</span></div><div class='line' id='LC22'>		<span class="nv">$classes</span><span class="p">[]</span> <span class="o">=</span> <span class="s1">&#39;first&#39;</span><span class="p">;</span></div><div class='line' id='LC23'>	<span class="k">return</span> <span class="nv">$classes</span><span class="p">;</span></div><div class='line' id='LC24'><span class="p">}</span></div><div class='line' id='LC25'><span class="nx">add_filter</span><span class="p">(</span> <span class="s1">&#39;post_class&#39;</span><span class="p">,</span> <span class="s1">&#39;be_archive_post_class&#39;</span> <span class="p">);</span></div></pre></div></div><div
class="gist-meta"> <a
href="https://gist.github.com/raw/2046751/99d9981d201aa38f2e2d05a7bff1a9679b1e6d86/gistfile1.aw" style="float:right;">view raw</a> <a
href="https://gist.github.com/2046751#file_gistfile1.aw" style="float:right;margin-right:10px;color:#666">gistfile1.aw</a> <a
href="https://gist.github.com/2046751">This Gist</a> brought to you by <a
href="http://github.com">GitHub</a>.</div></div></div><p>And instead of the function to customize the number of posts, go to Settings > Reading and tweak it there.</p> <img src="http://feeds.feedburner.com/~r/BillErickson/~4/v2RIWNddO7E" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://www.billerickson.net/a-better-and-easier-grid-loop/feed/</wfw:commentRss> <slash:comments>40</slash:comments> <feedburner:origLink>http://www.billerickson.net/a-better-and-easier-grid-loop/</feedburner:origLink></item> <item><title>Genesis Grid Loop Advanced</title><link>http://feedproxy.google.com/~r/BillErickson/~3/PqQ_-Z47rU0/</link> <comments>http://www.billerickson.net/genesis-grid-loop-advanced/#comments</comments> <pubDate>Sun, 12 Feb 2012 15:41:07 +0000</pubDate> <dc:creator>Bill Erickson</dc:creator> <category><![CDATA[Tutorial]]></category> <category><![CDATA[advanced]]></category> <category><![CDATA[genesis]]></category> <category><![CDATA[gridloop]]></category> <guid isPermaLink="false">http://www.billerickson.net/?p=4219</guid> <description><![CDATA[I recently worked with Gary Jones on refreshing his popular grid loop tutorial. ]]></description> <content:encoded><![CDATA[<p>I recently worked with Gary Jones on refreshing his popular grid loop tutorial.</p><p><a
href="http://code.garyjones.co.uk/genesis-grid-loop-advanced/">Read the full article here.</a></p> <img src="http://feeds.feedburner.com/~r/BillErickson/~4/PqQ_-Z47rU0" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://www.billerickson.net/genesis-grid-loop-advanced/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://www.billerickson.net/genesis-grid-loop-advanced/</feedburner:origLink></item> <item><title>Admin Pages with Genesis</title><link>http://feedproxy.google.com/~r/BillErickson/~3/4JFEbdWm3_0/</link> <comments>http://www.billerickson.net/admin-pages-with-genesis/#comments</comments> <pubDate>Sat, 21 Jan 2012 03:18:54 +0000</pubDate> <dc:creator>Bill Erickson</dc:creator> <category><![CDATA[Tutorial]]></category> <category><![CDATA[advanced]]></category> <category><![CDATA[genesis]]></category> <category><![CDATA[wordpress]]></category> <guid isPermaLink="false">http://www.billerickson.net/?p=4174</guid> <description><![CDATA[One of the best new features of Genesis 1.8 (and there are many) is a tool for making admin pages. These are needed if you&#8217;re building a plugin or a complex theme with site-wide settings that need to be managed. I recently built an Event Manager theme for promoting an event, and on our Event [...]]]></description> <content:encoded><![CDATA[<p>One of the best new features of Genesis 1.8 (and there are <a
href="http://genesischangelog.com/1.8">many</a>) is a tool for making admin pages. These are needed if you&#8217;re building a plugin or a complex theme with site-wide settings that need to be managed.</p><p>I recently built an Event Manager theme for promoting an event, and on our Event Theme Settings page we had fields for event date and location, so these could be used throughout the site and pulled from a single source.</p><p>This code is pretty technical, but it is 100x easier than making admin pages without Genesis. See this <a
href="http://www.chipbennett.net/2011/02/17/incorporating-the-settings-api-in-wordpress-themes/">10 page tutorial by Chip Bennett</a> for instructions on making them without Genesis&#8217; help.</p><p>You should only use this method if you&#8217;re building a Genesis theme or a Genesis-specific plugin. If you build a plugin for public distribution, make sure you put some checks in place to ensure the user is running Genesis (take a look at the AgentPress plugin code as an example).</p><p>Here&#8217;s the steps:</p><ol><li>Specify the page information. This includes the page&#8217;s name and default values for your fields.</li><li>Create the sanitization filters. These keep the page secure by ensuring the right type of data are entered.</li><li>Set up the help tab, a very useful feature that was improved in WordPress 3.3.</li><li>Add your metaboxes to the page.</li><li>Build your metaboxes.</li><li>Finally, add the new admin page to the backend.</li></ol><p>For a complete example, see the <a
href="https://github.com/billerickson/BE-Genesis-Child/blob/master/lib/admin/child-theme-settings.php">child-theme-settings.php</a> file in my <a
href="https://github.com/billerickson/BE-Genesis-Child">base child theme</a>.</p><h3>Specify the page information</h3><p>First, it&#8217;s best to keep all this code in its own file so your theme is easy to browse. I like to create a &#8220;lib&#8221; folder in my child theme where I store everything. In my example, I created /lib/admin/child-theme-settings.php, then added this to my functions.php to include it:</p><div
id="gist-1650047" class="gist"><div
class="gist-file"><div
class="gist-data gist-syntax"><div
class="highlight"><pre><div class='line' id='LC1'><span class="cp">&lt;?php</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'><span class="c1">// Setup Theme Settings</span></div><div class='line' id='LC4'><span class="k">include_once</span><span class="p">(</span> <span class="nx">CHILD_DIR</span> <span class="o">.</span> <span class="s1">&#39;/lib/admin/child-theme-settings.php&#39;</span><span class="p">);</span></div><div class='line' id='LC5'><br/></div></pre></div></div><div
class="gist-meta"> <a
href="https://gist.github.com/raw/1650047/ddf4c90427a301e3048b3319b3282b0c02859d70/gistfile1.aw" style="float:right;">view raw</a> <a
href="https://gist.github.com/1650047#file_gistfile1.aw" style="float:right;margin-right:10px;color:#666">gistfile1.aw</a> <a
href="https://gist.github.com/1650047">This Gist</a> brought to you by <a
href="http://github.com">GitHub</a>.</div></div></div><p>Now inside your child-theme-settings.php file, place the following:</p><div
id="gist-1650052" class="gist"><div
class="gist-file"><div
class="gist-data gist-syntax"><div
class="highlight"><pre><div class='line' id='LC1'><span class="cp">&lt;?php</span></div><div class='line' id='LC2'><span class="sd">/**</span></div><div class='line' id='LC3'><span class="sd"> * Child Theme Settings</span></div><div class='line' id='LC4'><span class="sd"> * Requires Genesis 1.8 or later</span></div><div class='line' id='LC5'><span class="sd"> *</span></div><div class='line' id='LC6'><span class="sd"> * This file registers all of this child theme&#39;s specific Theme Settings, accessible from</span></div><div class='line' id='LC7'><span class="sd"> * Genesis &gt; Child Theme Settings.</span></div><div class='line' id='LC8'><span class="sd"> *</span></div><div class='line' id='LC9'><span class="sd"> * @package     BE Genesis Child</span></div><div class='line' id='LC10'><span class="sd"> * @author      Bill Erickson &lt;bill@billerickson.net&gt;</span></div><div class='line' id='LC11'><span class="sd"> * @copyright   Copyright (c) 2011, Bill Erickson</span></div><div class='line' id='LC12'><span class="sd"> * @license     http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later)</span></div><div class='line' id='LC13'><span class="sd"> * @link        https://github.com/billerickson/BE-Genesis-Child</span></div><div class='line' id='LC14'><span class="sd"> */</span> </div><div class='line' id='LC15'>&nbsp;</div><div class='line' id='LC16'><span class="sd">/**</span></div><div class='line' id='LC17'><span class="sd"> * Registers a new admin page, providing content and corresponding menu item</span></div><div class='line' id='LC18'><span class="sd"> * for the Child Theme Settings page.</span></div><div class='line' id='LC19'><span class="sd"> *</span></div><div class='line' id='LC20'><span class="sd"> * @package BE Genesis Child</span></div><div class='line' id='LC21'><span class="sd"> * @subpackage Admin</span></div><div class='line' id='LC22'><span class="sd"> *</span></div><div class='line' id='LC23'><span class="sd"> * @since 1.0.0</span></div><div class='line' id='LC24'><span class="sd"> */</span></div><div class='line' id='LC25'><span class="k">class</span> <span class="nc">Child_Theme_Settings</span> <span class="k">extends</span> <span class="nx">Genesis_Admin_Boxes</span> <span class="p">{</span></div><div class='line' id='LC26'><br/></div><div class='line' id='LC27'>	<span class="sd">/**</span></div><div class='line' id='LC28'><span class="sd">	 * Create an admin menu item and settings page.</span></div><div class='line' id='LC29'><span class="sd">	 * </span></div><div class='line' id='LC30'><span class="sd">	 * @since 1.0.0</span></div><div class='line' id='LC31'><span class="sd">	 */</span></div><div class='line' id='LC32'>	<span class="k">function</span> <span class="nf">__construct</span><span class="p">()</span> <span class="p">{</span></div><div class='line' id='LC33'><br/></div><div class='line' id='LC34'>		<span class="c1">// Specify a unique page ID. </span></div><div class='line' id='LC35'>		<span class="nv">$page_id</span> <span class="o">=</span> <span class="s1">&#39;child&#39;</span><span class="p">;</span></div><div class='line' id='LC36'><br/></div><div class='line' id='LC37'>		<span class="c1">// Set it as a child to genesis, and define the menu and page titles</span></div><div class='line' id='LC38'>		<span class="nv">$menu_ops</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span></div><div class='line' id='LC39'>			<span class="s1">&#39;submenu&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span></div><div class='line' id='LC40'>				<span class="s1">&#39;parent_slug&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;genesis&#39;</span><span class="p">,</span></div><div class='line' id='LC41'>				<span class="s1">&#39;page_title&#39;</span>  <span class="o">=&gt;</span> <span class="s1">&#39;Genesis - Child Theme Settings&#39;</span><span class="p">,</span></div><div class='line' id='LC42'>				<span class="s1">&#39;menu_title&#39;</span>  <span class="o">=&gt;</span> <span class="s1">&#39;Child Theme Settings&#39;</span><span class="p">,</span></div><div class='line' id='LC43'>			<span class="p">)</span></div><div class='line' id='LC44'>		<span class="p">);</span></div><div class='line' id='LC45'><br/></div><div class='line' id='LC46'>		<span class="c1">// Set up page options. These are optional, so only uncomment if you want to change the defaults</span></div><div class='line' id='LC47'>		<span class="nv">$page_ops</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span></div><div class='line' id='LC48'>		<span class="c1">//	&#39;screen_icon&#39;       =&gt; &#39;options-general&#39;,</span></div><div class='line' id='LC49'>		<span class="c1">//	&#39;save_button_text&#39;  =&gt; &#39;Save Settings&#39;,</span></div><div class='line' id='LC50'>		<span class="c1">//	&#39;reset_button_text&#39; =&gt; &#39;Reset Settings&#39;,</span></div><div class='line' id='LC51'>		<span class="c1">//	&#39;save_notice_text&#39;  =&gt; &#39;Settings saved.&#39;,</span></div><div class='line' id='LC52'>		<span class="c1">//	&#39;reset_notice_text&#39; =&gt; &#39;Settings reset.&#39;,</span></div><div class='line' id='LC53'>		<span class="p">);</span>		</div><div class='line' id='LC54'><br/></div><div class='line' id='LC55'>		<span class="c1">// Give it a unique settings field. </span></div><div class='line' id='LC56'>		<span class="c1">// You&#39;ll access them from genesis_get_option( &#39;option_name&#39;, &#39;child-settings&#39; );</span></div><div class='line' id='LC57'>		<span class="nv">$settings_field</span> <span class="o">=</span> <span class="s1">&#39;child-settings&#39;</span><span class="p">;</span></div><div class='line' id='LC58'><br/></div><div class='line' id='LC59'>		<span class="c1">// Set the default values</span></div><div class='line' id='LC60'>		<span class="nv">$default_settings</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span></div><div class='line' id='LC61'>			<span class="s1">&#39;phone&#39;</span>   <span class="o">=&gt;</span> <span class="s1">&#39;&#39;</span><span class="p">,</span></div><div class='line' id='LC62'>			<span class="s1">&#39;address&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;&#39;</span><span class="p">,</span></div><div class='line' id='LC63'>		<span class="p">);</span></div><div class='line' id='LC64'><br/></div><div class='line' id='LC65'>		<span class="c1">// Create the Admin Page</span></div><div class='line' id='LC66'>		<span class="nv">$this</span><span class="o">-&gt;</span><span class="na">create</span><span class="p">(</span> <span class="nv">$page_id</span><span class="p">,</span> <span class="nv">$menu_ops</span><span class="p">,</span> <span class="nv">$page_ops</span><span class="p">,</span> <span class="nv">$settings_field</span><span class="p">,</span> <span class="nv">$default_settings</span> <span class="p">);</span></div><div class='line' id='LC67'><br/></div><div class='line' id='LC68'>		<span class="c1">// Initialize the Sanitization Filter</span></div><div class='line' id='LC69'>		<span class="nx">add_action</span><span class="p">(</span> <span class="s1">&#39;genesis_settings_sanitizer_init&#39;</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span> <span class="nv">$this</span><span class="p">,</span> <span class="s1">&#39;sanitization_filters&#39;</span> <span class="p">)</span> <span class="p">);</span></div><div class='line' id='LC70'><br/></div><div class='line' id='LC71'>	<span class="p">}</span></div><div class='line' id='LC72'><br/></div><div class='line' id='LC73'>	<span class="k">function</span> <span class="nf">sanitization_filters</span><span class="p">()</span> <span class="p">{</span></div><div class='line' id='LC74'><br/></div><div class='line' id='LC75'>	<span class="p">}</span></div><div class='line' id='LC76'><br/></div><div class='line' id='LC77'><span class="p">}</span></div></pre></div></div><div
class="gist-meta"> <a
href="https://gist.github.com/raw/1650052/7d87110613b6a1cb41c5c777ebb7949c2d6def78/gistfile1.aw" style="float:right;">view raw</a> <a
href="https://gist.github.com/1650052#file_gistfile1.aw" style="float:right;margin-right:10px;color:#666">gistfile1.aw</a> <a
href="https://gist.github.com/1650052">This Gist</a> brought to you by <a
href="http://github.com">GitHub</a>.</div></div></div><p>This is a lot of code, so I&#8217;ll walk through it:</p><ul><li>I start out with some page-specific documentation that describes what this page is (always a good practice).</li><li>Then there&#8217;s the documentation for our new class, Child_Theme_Settings</li><li>We create our new class by extending the existing Genesis_Admin_Boxes class</li><li>First thing in our new class is the <code>__construct()</code> method (functions inside of classes are called methods). This is what sets everything up.</li><li>We create an unique page ID for this page. I&#8217;m calling mine &#8216;child&#8217;, but you could call yours whatever you&#8217;d like. I recommend naming it the same as your child theme since it will contain your child-theme-specific settings.</li><li>Next we specify some information about the menu item. It&#8217;s a child of the &#8216;genesis&#8217; page, we give it a page title and a menu title.</li><li>Then we create the <code>$page_ops</code> variable which lets you customize some page settings. I&#8217;ve left the defaults in there and commented them out so you can see. Uncomment a line and then modify it to change the default.</li><li>Then we define the settings field. All the settings on this page will be grouped together. If you create a field called <code>address</code> you can get to it like this: <code>$address = genesis_get_option( 'option_name', 'child-settings' );</code></li><li>Finally, we create the admin page by adding all the variables together in the <code>create()</code> method.</li><li>I&#8217;ve also added the sanitation action (in <code>__construct()</code> method) and <code>sanitization_filters()</code> method to create the sanitization filters, which we&#8217;ll do in the next step.</li></ul><p>Before we move on, a few quick notes about classes. Everything inside the class should use the <code>__construct()</code> method for hooking to appropriate actions/filters. Classes are their own namespace, so you can name the methods whatever you&#8217;d like. Unlike standard functions where you always need to prefix, you don&#8217;t have to worry about any other function having the same name. And finally, when hooking methods to actions make sure you use <code>array( $this, 'method_name' )</code> instead of just <code>'method_name'</code>.</p><h3>Create the sanitization filters</h3><p>Sanitization is about ensuring the data collected is the type of data you expect. By limiting a checkbox to a 0 or 1, a title to no html&#8230; you&#8217;re able to prevent code you didn&#8217;t expect (whether malicious or not) from altering the way your theme/plugin works.</p><p>See my <a
href="http://www.billerickson.net/genesis-theme-options/#sanitization">previous post on Genesis options</a> for more details on sanitization filters.</p><p>I&#8217;m planning to have two fields on this page &#8211; phone and address &#8211; so I&#8217;ll register those as no_html. Update your sanitization_filters() method like this:</p><div
id="gist-1650805" class="gist"><div
class="gist-file"><div
class="gist-data gist-syntax"><div
class="highlight"><pre><div class='line' id='LC1'><span class="cp">&lt;?php</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'><br/></div><div class='line' id='LC4'><span class="sd">/** </span></div><div class='line' id='LC5'><span class="sd"> * Set up Sanitization Filters</span></div><div class='line' id='LC6'><span class="sd"> *</span></div><div class='line' id='LC7'><span class="sd"> * See /lib/classes/sanitization.php for all available filters.</span></div><div class='line' id='LC8'><span class="sd"> *</span></div><div class='line' id='LC9'><span class="sd"> * @since 1.0.0</span></div><div class='line' id='LC10'><span class="sd"> */</span>	</div><div class='line' id='LC11'><span class="k">function</span> <span class="nf">sanitization_filters</span><span class="p">()</span> <span class="p">{</span></div><div class='line' id='LC12'><br/></div><div class='line' id='LC13'>	<span class="nx">genesis_add_option_filter</span><span class="p">(</span> <span class="s1">&#39;no_html&#39;</span><span class="p">,</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">settings_field</span><span class="p">,</span></div><div class='line' id='LC14'>		<span class="k">array</span><span class="p">(</span></div><div class='line' id='LC15'>			<span class="s1">&#39;phone&#39;</span><span class="p">,</span></div><div class='line' id='LC16'>			<span class="s1">&#39;address&#39;</span><span class="p">,</span></div><div class='line' id='LC17'>		<span class="p">)</span> <span class="p">);</span></div><div class='line' id='LC18'><span class="p">}</span></div></pre></div></div><div
class="gist-meta"> <a
href="https://gist.github.com/raw/1650805/5559e64ed0c98627f85d36a59716b6fccd02ccb9/gistfile1.aw" style="float:right;">view raw</a> <a
href="https://gist.github.com/1650805#file_gistfile1.aw" style="float:right;margin-right:10px;color:#666">gistfile1.aw</a> <a
href="https://gist.github.com/1650805">This Gist</a> brought to you by <a
href="http://github.com">GitHub</a>.</div></div></div><h3>Help Tab</h3><p>While not required, it&#8217;s a good idea to put instructions and other useful information in the help tab. If you&#8217;d like to have a help tab, simply create a <code>help()</code> method in your class.</p><p>Here&#8217;s a screenshot of the help tab in my Event Theme. I don&#8217;t usually provide this much information, but the client plans to sell the theme so we wanted to provide as much information as possible.</p><p><img
src="http://www.billerickson.net/wp-content/uploads/2012/01/Screen-Shot-2012-01-20-at-8.19.21-PM-500x224.png" alt="" title="Screen Shot 2012-01-20 at 8.19.21 PM" class="aligncenter size-large wp-image-4185" /></p><p>To create a help tab, add this method inside your Child_Theme_Settings class ( so before the last } ).</p><div
id="gist-1650825" class="gist"><div
class="gist-file"><div
class="gist-data gist-syntax"><div
class="highlight"><pre><div class='line' id='LC1'><span class="cp">&lt;?php</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'><span class="sd">/**</span></div><div class='line' id='LC4'><span class="sd"> * Set up Help Tab</span></div><div class='line' id='LC5'><span class="sd"> * Genesis automatically looks for a help() function, and if provided uses it for the help tabs</span></div><div class='line' id='LC6'><span class="sd"> * @link http://wpdevel.wordpress.com/2011/12/06/help-and-screen-api-changes-in-3-3/</span></div><div class='line' id='LC7'><span class="sd"> *</span></div><div class='line' id='LC8'><span class="sd"> * @since 1.0.0</span></div><div class='line' id='LC9'><span class="sd"> */</span></div><div class='line' id='LC10'>&nbsp;<span class="k">function</span> <span class="nf">help</span><span class="p">()</span> <span class="p">{</span></div><div class='line' id='LC11'>&nbsp;	<span class="nv">$screen</span> <span class="o">=</span> <span class="nx">get_current_screen</span><span class="p">();</span></div><div class='line' id='LC12'><br/></div><div class='line' id='LC13'>	<span class="nv">$screen</span><span class="o">-&gt;</span><span class="na">add_help_tab</span><span class="p">(</span> <span class="k">array</span><span class="p">(</span></div><div class='line' id='LC14'>		<span class="s1">&#39;id&#39;</span>      <span class="o">=&gt;</span> <span class="s1">&#39;sample-help&#39;</span><span class="p">,</span> </div><div class='line' id='LC15'>		<span class="s1">&#39;title&#39;</span>   <span class="o">=&gt;</span> <span class="s1">&#39;Sample Help&#39;</span><span class="p">,</span></div><div class='line' id='LC16'>		<span class="s1">&#39;content&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;&lt;p&gt;Help content goes here.&lt;/p&gt;&#39;</span><span class="p">,</span></div><div class='line' id='LC17'>	<span class="p">)</span> <span class="p">);</span></div><div class='line' id='LC18'>&nbsp;<span class="p">}</span></div><div class='line' id='LC19'><br/></div></pre></div></div><div
class="gist-meta"> <a
href="https://gist.github.com/raw/1650825/91027e0db156a5ef4b75e64fb73a0a12879c7742/gistfile1.aw" style="float:right;">view raw</a> <a
href="https://gist.github.com/1650825#file_gistfile1.aw" style="float:right;margin-right:10px;color:#666">gistfile1.aw</a> <a
href="https://gist.github.com/1650825">This Gist</a> brought to you by <a
href="http://github.com">GitHub</a>.</div></div></div><p>Provide an unique ID for the tab, then give it a title (shown on the left) and HTML content (shown on the right). For multiple tabs, simply repeat the <code>$screen->add_help_tab()</code> method inside your <code>help()</code> method.</p><h3>Add your metaboxes</h3><p>We&#8217;ll now create a method inside our class called <code>metaboxes()</code>. For each metabox we&#8217;d like to add to our page, we&#8217;ll write a simple one line of code to <code>add_meta_box()</code>.</p><div
id="gist-1650841" class="gist"><div
class="gist-file"><div
class="gist-data gist-syntax"><div
class="highlight"><pre><div class='line' id='LC1'><span class="cp">&lt;?php</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'><span class="sd">/**</span></div><div class='line' id='LC4'><span class="sd"> * Register metaboxes on Child Theme Settings page</span></div><div class='line' id='LC5'><span class="sd"> *</span></div><div class='line' id='LC6'><span class="sd"> * @since 1.0.0</span></div><div class='line' id='LC7'><span class="sd"> *</span></div><div class='line' id='LC8'><span class="sd"> * @see Child_Theme_Settings::contact_information() Callback for contact information</span></div><div class='line' id='LC9'><span class="sd"> */</span></div><div class='line' id='LC10'><span class="k">function</span> <span class="nf">metaboxes</span><span class="p">()</span> <span class="p">{</span></div><div class='line' id='LC11'><br/></div><div class='line' id='LC12'>	<span class="nx">add_meta_box</span><span class="p">(</span><span class="s1">&#39;contact-information&#39;</span><span class="p">,</span> <span class="s1">&#39;Contact Information&#39;</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span> <span class="nv">$this</span><span class="p">,</span> <span class="s1">&#39;contact_information&#39;</span> <span class="p">),</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">pagehook</span><span class="p">,</span> <span class="s1">&#39;main&#39;</span><span class="p">,</span> <span class="s1">&#39;high&#39;</span><span class="p">);</span></div><div class='line' id='LC13'><br/></div><div class='line' id='LC14'><span class="p">}</span></div><div class='line' id='LC15'><br/></div></pre></div></div><div
class="gist-meta"> <a
href="https://gist.github.com/raw/1650841/bee2fa8d90d2eebdff93b6cb63ac4599912f908d/gistfile1.aw" style="float:right;">view raw</a> <a
href="https://gist.github.com/1650841#file_gistfile1.aw" style="float:right;margin-right:10px;color:#666">gistfile1.aw</a> <a
href="https://gist.github.com/1650841">This Gist</a> brought to you by <a
href="http://github.com">GitHub</a>.</div></div></div><p>I&#8217;ve added a single metabox with an ID of &#8216;contact-information&#8217;, a title of &#8216;Contact Information&#8217;, a callback function (where the actual metabox code is) of <code>contact_information()</code>, I&#8217;m putting it on the current page, it goes in the main column (not that there&#8217;s any other columns for it) and I want it positioned at the top. For more information on this function, see <a
href="http://codex.wordpress.org/Function_Reference/add_meta_box">add_meta_box()</a> in the Codex.</p><h3>Build your metaboxes</h3><p>In the previous method we referenced a callback function called <code>contact_information()</code>. Now it&#8217;s time to build this.</p><p>My metabox, Contact Information, will contain two fields. Phone will be a text field, and Address is a textarea. For examples of more fields, look at the actual Genesis admin pages (/lib/admin/&#8230;). And I&#8217;ve heard there might be a tool similar to our <a
href="https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress">Custom Metabox Library</a> for making Genesis admin fields (talk with <a
href="http://designsbynickthegeek.com/">NickTheGeek</a>).</p><p>This method also goes inside your Child_Theme_Settings class.</p><div
id="gist-1650919" class="gist"><div
class="gist-file"><div
class="gist-data gist-syntax"><div
class="highlight"><pre><div class='line' id='LC1'><span class="cp">&lt;?php</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'><span class="sd">/**</span></div><div class='line' id='LC4'><span class="sd"> * Callback for Contact Information metabox</span></div><div class='line' id='LC5'><span class="sd"> *</span></div><div class='line' id='LC6'><span class="sd"> * @since 1.0.0</span></div><div class='line' id='LC7'><span class="sd"> *</span></div><div class='line' id='LC8'><span class="sd"> * @see Child_Theme_Settings::metaboxes()</span></div><div class='line' id='LC9'><span class="sd"> */</span></div><div class='line' id='LC10'><span class="k">function</span> <span class="nf">contact_information</span><span class="p">()</span> <span class="p">{</span></div><div class='line' id='LC11'><br/></div><div class='line' id='LC12'>	<span class="k">echo</span> <span class="s1">&#39;&lt;p&gt;Phone:&lt;br /&gt;&#39;</span><span class="p">;</span></div><div class='line' id='LC13'>	<span class="k">echo</span> <span class="s1">&#39;&lt;input type=&quot;text&quot; name=&quot;&#39;</span> <span class="o">.</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">get_field_name</span><span class="p">(</span> <span class="s1">&#39;phone&#39;</span> <span class="p">)</span> <span class="o">.</span> <span class="s1">&#39;&quot; id=&quot;&#39;</span> <span class="o">.</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">get_field_id</span><span class="p">(</span> <span class="s1">&#39;phone&#39;</span> <span class="p">)</span> <span class="o">.</span> <span class="s1">&#39;&quot; value=&quot;&#39;</span> <span class="o">.</span> <span class="nx">esc_attr</span><span class="p">(</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">get_field_value</span><span class="p">(</span> <span class="s1">&#39;phone&#39;</span> <span class="p">)</span> <span class="p">)</span> <span class="o">.</span> <span class="s1">&#39;&quot; size=&quot;50&quot; /&gt;&#39;</span><span class="p">;</span></div><div class='line' id='LC14'>	<span class="k">echo</span> <span class="s1">&#39;&lt;/p&gt;&#39;</span><span class="p">;</span></div><div class='line' id='LC15'><br/></div><div class='line' id='LC16'>	<span class="k">echo</span> <span class="s1">&#39;&lt;p&gt;Address&lt;/p&gt;&#39;</span><span class="p">;</span></div><div class='line' id='LC17'>	<span class="k">echo</span> <span class="s1">&#39;&lt;p&gt;&lt;textarea name=&quot;&#39;</span> <span class="o">.</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">get_field_name</span><span class="p">(</span> <span class="s1">&#39;address&#39;</span> <span class="p">)</span> <span class="o">.</span> <span class="s1">&#39;&quot; cols=&quot;78&quot; rows=&quot;8&quot;&gt;&#39;</span> <span class="o">.</span> <span class="nx">esc_textarea</span><span class="p">(</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">get_field_value</span><span class="p">(</span> <span class="s1">&#39;address&#39;</span> <span class="p">)</span> <span class="p">)</span> <span class="o">.</span> <span class="s1">&#39;&lt;/textarea&gt;&lt;/p&gt;&#39;</span><span class="p">;</span>		</div><div class='line' id='LC18'><span class="p">}</span></div><div class='line' id='LC19'><br/></div></pre></div></div><div
class="gist-meta"> <a
href="https://gist.github.com/raw/1650919/afb614b886023f8f487fa2b60059caf5896e5b19/gistfile1.aw" style="float:right;">view raw</a> <a
href="https://gist.github.com/1650919#file_gistfile1.aw" style="float:right;margin-right:10px;color:#666">gistfile1.aw</a> <a
href="https://gist.github.com/1650919">This Gist</a> brought to you by <a
href="http://github.com">GitHub</a>.</div></div></div><p>The important thing to note here is the handy methods that are built into the class (examples below are for the field &#8216;phone&#8217; ).</p><ul><li><code>$this->get_field_name( 'phone' );</code></li><li><code>$this->get_field_id( 'phone' );</code></li><li><code>$this->get_field_value( 'phone' );</code></li></ul><h3>That&#8217;s It!</h3><p>That&#8217;s all it takes to build custom admin pages in Genesis. The code definitely looks complicated, but once you get started it&#8217;s pretty easy to modify it to your needs. StudioPress has done all the hard (and repetitive) work for you, so you just have to specify the things that are unique to the page.</p><p>Here&#8217;s the completed code:</p><div
id="gist-1650977" class="gist"><div
class="gist-file"><div
class="gist-data gist-syntax"><div
class="highlight"><pre><div class='line' id='LC1'><span class="cp">&lt;?php</span></div><div class='line' id='LC2'><span class="sd">/**</span></div><div class='line' id='LC3'><span class="sd"> * Child Theme Settings</span></div><div class='line' id='LC4'><span class="sd"> * Requires Genesis 1.8 or later</span></div><div class='line' id='LC5'><span class="sd"> *</span></div><div class='line' id='LC6'><span class="sd"> * This file registers all of this child theme&#39;s specific Theme Settings, accessible from</span></div><div class='line' id='LC7'><span class="sd"> * Genesis &gt; Child Theme Settings.</span></div><div class='line' id='LC8'><span class="sd"> *</span></div><div class='line' id='LC9'><span class="sd"> * @package     BE Genesis Child</span></div><div class='line' id='LC10'><span class="sd"> * @author      Bill Erickson &lt;bill@billerickson.net&gt;</span></div><div class='line' id='LC11'><span class="sd"> * @copyright   Copyright (c) 2011, Bill Erickson</span></div><div class='line' id='LC12'><span class="sd"> * @license     http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later)</span></div><div class='line' id='LC13'><span class="sd"> * @link        https://github.com/billerickson/BE-Genesis-Child</span></div><div class='line' id='LC14'><span class="sd"> */</span> </div><div class='line' id='LC15'>&nbsp;</div><div class='line' id='LC16'><span class="sd">/**</span></div><div class='line' id='LC17'><span class="sd"> * Registers a new admin page, providing content and corresponding menu item</span></div><div class='line' id='LC18'><span class="sd"> * for the Child Theme Settings page.</span></div><div class='line' id='LC19'><span class="sd"> *</span></div><div class='line' id='LC20'><span class="sd"> * @package BE Genesis Child</span></div><div class='line' id='LC21'><span class="sd"> * @subpackage Admin</span></div><div class='line' id='LC22'><span class="sd"> *</span></div><div class='line' id='LC23'><span class="sd"> * @since 1.0.0</span></div><div class='line' id='LC24'><span class="sd"> */</span></div><div class='line' id='LC25'><span class="k">class</span> <span class="nc">Child_Theme_Settings</span> <span class="k">extends</span> <span class="nx">Genesis_Admin_Boxes</span> <span class="p">{</span></div><div class='line' id='LC26'><br/></div><div class='line' id='LC27'>	<span class="sd">/**</span></div><div class='line' id='LC28'><span class="sd">	 * Create an admin menu item and settings page.</span></div><div class='line' id='LC29'><span class="sd">	 * </span></div><div class='line' id='LC30'><span class="sd">	 * @since 1.0.0</span></div><div class='line' id='LC31'><span class="sd">	 */</span></div><div class='line' id='LC32'>	<span class="k">function</span> <span class="nf">__construct</span><span class="p">()</span> <span class="p">{</span></div><div class='line' id='LC33'><br/></div><div class='line' id='LC34'>		<span class="c1">// Specify a unique page ID. </span></div><div class='line' id='LC35'>		<span class="nv">$page_id</span> <span class="o">=</span> <span class="s1">&#39;child&#39;</span><span class="p">;</span></div><div class='line' id='LC36'><br/></div><div class='line' id='LC37'>		<span class="c1">// Set it as a child to genesis, and define the menu and page titles</span></div><div class='line' id='LC38'>		<span class="nv">$menu_ops</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span></div><div class='line' id='LC39'>			<span class="s1">&#39;submenu&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span></div><div class='line' id='LC40'>				<span class="s1">&#39;parent_slug&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;genesis&#39;</span><span class="p">,</span></div><div class='line' id='LC41'>				<span class="s1">&#39;page_title&#39;</span>  <span class="o">=&gt;</span> <span class="s1">&#39;Genesis - Child Theme Settings&#39;</span><span class="p">,</span></div><div class='line' id='LC42'>				<span class="s1">&#39;menu_title&#39;</span>  <span class="o">=&gt;</span> <span class="s1">&#39;Child Theme Settings&#39;</span><span class="p">,</span></div><div class='line' id='LC43'>			<span class="p">)</span></div><div class='line' id='LC44'>		<span class="p">);</span></div><div class='line' id='LC45'><br/></div><div class='line' id='LC46'>		<span class="c1">// Set up page options. These are optional, so only uncomment if you want to change the defaults</span></div><div class='line' id='LC47'>		<span class="nv">$page_ops</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span></div><div class='line' id='LC48'>		<span class="c1">//	&#39;screen_icon&#39;       =&gt; &#39;options-general&#39;,</span></div><div class='line' id='LC49'>		<span class="c1">//	&#39;save_button_text&#39;  =&gt; &#39;Save Settings&#39;,</span></div><div class='line' id='LC50'>		<span class="c1">//	&#39;reset_button_text&#39; =&gt; &#39;Reset Settings&#39;,</span></div><div class='line' id='LC51'>		<span class="c1">//	&#39;save_notice_text&#39;  =&gt; &#39;Settings saved.&#39;,</span></div><div class='line' id='LC52'>		<span class="c1">//	&#39;reset_notice_text&#39; =&gt; &#39;Settings reset.&#39;,</span></div><div class='line' id='LC53'>		<span class="p">);</span>		</div><div class='line' id='LC54'><br/></div><div class='line' id='LC55'>		<span class="c1">// Give it a unique settings field. </span></div><div class='line' id='LC56'>		<span class="c1">// You&#39;ll access them from genesis_get_option( &#39;option_name&#39;, &#39;child-settings&#39; );</span></div><div class='line' id='LC57'>		<span class="nv">$settings_field</span> <span class="o">=</span> <span class="s1">&#39;child-settings&#39;</span><span class="p">;</span></div><div class='line' id='LC58'><br/></div><div class='line' id='LC59'>		<span class="c1">// Set the default values</span></div><div class='line' id='LC60'>		<span class="nv">$default_settings</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span></div><div class='line' id='LC61'>			<span class="s1">&#39;phone&#39;</span>   <span class="o">=&gt;</span> <span class="s1">&#39;&#39;</span><span class="p">,</span></div><div class='line' id='LC62'>			<span class="s1">&#39;address&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;&#39;</span><span class="p">,</span></div><div class='line' id='LC63'>		<span class="p">);</span></div><div class='line' id='LC64'><br/></div><div class='line' id='LC65'>		<span class="c1">// Create the Admin Page</span></div><div class='line' id='LC66'>		<span class="nv">$this</span><span class="o">-&gt;</span><span class="na">create</span><span class="p">(</span> <span class="nv">$page_id</span><span class="p">,</span> <span class="nv">$menu_ops</span><span class="p">,</span> <span class="nv">$page_ops</span><span class="p">,</span> <span class="nv">$settings_field</span><span class="p">,</span> <span class="nv">$default_settings</span> <span class="p">);</span></div><div class='line' id='LC67'><br/></div><div class='line' id='LC68'>		<span class="c1">// Initialize the Sanitization Filter</span></div><div class='line' id='LC69'>		<span class="nx">add_action</span><span class="p">(</span> <span class="s1">&#39;genesis_settings_sanitizer_init&#39;</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span> <span class="nv">$this</span><span class="p">,</span> <span class="s1">&#39;sanitization_filters&#39;</span> <span class="p">)</span> <span class="p">);</span></div><div class='line' id='LC70'><br/></div><div class='line' id='LC71'>	<span class="p">}</span></div><div class='line' id='LC72'><br/></div><div class='line' id='LC73'>	<span class="sd">/** </span></div><div class='line' id='LC74'><span class="sd">	 * Set up Sanitization Filters</span></div><div class='line' id='LC75'><span class="sd">	 *</span></div><div class='line' id='LC76'><span class="sd">	 * See /lib/classes/sanitization.php for all available filters.</span></div><div class='line' id='LC77'><span class="sd">	 *</span></div><div class='line' id='LC78'><span class="sd">	 * @since 1.0.0</span></div><div class='line' id='LC79'><span class="sd">	 */</span>	</div><div class='line' id='LC80'>	<span class="k">function</span> <span class="nf">sanitization_filters</span><span class="p">()</span> <span class="p">{</span></div><div class='line' id='LC81'><br/></div><div class='line' id='LC82'>		<span class="nx">genesis_add_option_filter</span><span class="p">(</span> <span class="s1">&#39;no_html&#39;</span><span class="p">,</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">settings_field</span><span class="p">,</span></div><div class='line' id='LC83'>			<span class="k">array</span><span class="p">(</span></div><div class='line' id='LC84'>				<span class="s1">&#39;phone&#39;</span><span class="p">,</span></div><div class='line' id='LC85'>				<span class="s1">&#39;address&#39;</span><span class="p">,</span></div><div class='line' id='LC86'>			<span class="p">)</span> <span class="p">);</span></div><div class='line' id='LC87'>	<span class="p">}</span></div><div class='line' id='LC88'><br/></div><div class='line' id='LC89'>	<span class="sd">/**</span></div><div class='line' id='LC90'><span class="sd">	 * Set up Help Tab</span></div><div class='line' id='LC91'><span class="sd">	 * Genesis automatically looks for a help() function, and if provided uses it for the help tabs</span></div><div class='line' id='LC92'><span class="sd">	 * @link http://wpdevel.wordpress.com/2011/12/06/help-and-screen-api-changes-in-3-3/</span></div><div class='line' id='LC93'><span class="sd">	 *</span></div><div class='line' id='LC94'><span class="sd">	 * @since 1.0.0</span></div><div class='line' id='LC95'><span class="sd">	 */</span></div><div class='line' id='LC96'>	 <span class="k">function</span> <span class="nf">help</span><span class="p">()</span> <span class="p">{</span></div><div class='line' id='LC97'>	 	<span class="nv">$screen</span> <span class="o">=</span> <span class="nx">get_current_screen</span><span class="p">();</span></div><div class='line' id='LC98'><br/></div><div class='line' id='LC99'>		<span class="nv">$screen</span><span class="o">-&gt;</span><span class="na">add_help_tab</span><span class="p">(</span> <span class="k">array</span><span class="p">(</span></div><div class='line' id='LC100'>			<span class="s1">&#39;id&#39;</span>      <span class="o">=&gt;</span> <span class="s1">&#39;sample-help&#39;</span><span class="p">,</span> </div><div class='line' id='LC101'>			<span class="s1">&#39;title&#39;</span>   <span class="o">=&gt;</span> <span class="s1">&#39;Sample Help&#39;</span><span class="p">,</span></div><div class='line' id='LC102'>			<span class="s1">&#39;content&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;&lt;p&gt;Help content goes here.&lt;/p&gt;&#39;</span><span class="p">,</span></div><div class='line' id='LC103'>		<span class="p">)</span> <span class="p">);</span></div><div class='line' id='LC104'>	 <span class="p">}</span></div><div class='line' id='LC105'><br/></div><div class='line' id='LC106'>	<span class="sd">/**</span></div><div class='line' id='LC107'><span class="sd">	 * Register metaboxes on Child Theme Settings page</span></div><div class='line' id='LC108'><span class="sd">	 *</span></div><div class='line' id='LC109'><span class="sd">	 * @since 1.0.0</span></div><div class='line' id='LC110'><span class="sd">	 *</span></div><div class='line' id='LC111'><span class="sd">	 * @see Child_Theme_Settings::contact_information() Callback for contact information</span></div><div class='line' id='LC112'><span class="sd">	 */</span></div><div class='line' id='LC113'>	<span class="k">function</span> <span class="nf">metaboxes</span><span class="p">()</span> <span class="p">{</span></div><div class='line' id='LC114'><br/></div><div class='line' id='LC115'>		<span class="nx">add_meta_box</span><span class="p">(</span><span class="s1">&#39;contact-information&#39;</span><span class="p">,</span> <span class="s1">&#39;Contact Information&#39;</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span> <span class="nv">$this</span><span class="p">,</span> <span class="s1">&#39;contact_information&#39;</span> <span class="p">),</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">pagehook</span><span class="p">,</span> <span class="s1">&#39;main&#39;</span><span class="p">,</span> <span class="s1">&#39;high&#39;</span><span class="p">);</span></div><div class='line' id='LC116'><br/></div><div class='line' id='LC117'>	<span class="p">}</span></div><div class='line' id='LC118'><br/></div><div class='line' id='LC119'>	<span class="sd">/**</span></div><div class='line' id='LC120'><span class="sd">	 * Callback for Contact Information metabox</span></div><div class='line' id='LC121'><span class="sd">	 *</span></div><div class='line' id='LC122'><span class="sd">	 * @since 1.0.0</span></div><div class='line' id='LC123'><span class="sd">	 *</span></div><div class='line' id='LC124'><span class="sd">	 * @see Child_Theme_Settings::metaboxes()</span></div><div class='line' id='LC125'><span class="sd">	 */</span></div><div class='line' id='LC126'>	<span class="k">function</span> <span class="nf">contact_information</span><span class="p">()</span> <span class="p">{</span></div><div class='line' id='LC127'><br/></div><div class='line' id='LC128'>		<span class="k">echo</span> <span class="s1">&#39;&lt;p&gt;Phone:&lt;br /&gt;&#39;</span><span class="p">;</span></div><div class='line' id='LC129'>		<span class="k">echo</span> <span class="s1">&#39;&lt;input type=&quot;text&quot; name=&quot;&#39;</span> <span class="o">.</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">get_field_name</span><span class="p">(</span> <span class="s1">&#39;phone&#39;</span> <span class="p">)</span> <span class="o">.</span> <span class="s1">&#39;&quot; id=&quot;&#39;</span> <span class="o">.</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">get_field_id</span><span class="p">(</span> <span class="s1">&#39;phone&#39;</span> <span class="p">)</span> <span class="o">.</span> <span class="s1">&#39;&quot; value=&quot;&#39;</span> <span class="o">.</span> <span class="nx">esc_attr</span><span class="p">(</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">get_field_value</span><span class="p">(</span> <span class="s1">&#39;phone&#39;</span> <span class="p">)</span> <span class="p">)</span> <span class="o">.</span> <span class="s1">&#39;&quot; size=&quot;50&quot; /&gt;&#39;</span><span class="p">;</span></div><div class='line' id='LC130'>		<span class="k">echo</span> <span class="s1">&#39;&lt;/p&gt;&#39;</span><span class="p">;</span></div><div class='line' id='LC131'><br/></div><div class='line' id='LC132'>		<span class="k">echo</span> <span class="s1">&#39;&lt;p&gt;Address&lt;/p&gt;&#39;</span><span class="p">;</span></div><div class='line' id='LC133'>		<span class="k">echo</span> <span class="s1">&#39;&lt;p&gt;&lt;textarea name=&quot;&#39;</span> <span class="o">.</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">get_field_name</span><span class="p">(</span> <span class="s1">&#39;address&#39;</span> <span class="p">)</span> <span class="o">.</span> <span class="s1">&#39;&quot; cols=&quot;78&quot; rows=&quot;8&quot;&gt;&#39;</span> <span class="o">.</span> <span class="nx">esc_textarea</span><span class="p">(</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">get_field_value</span><span class="p">(</span> <span class="s1">&#39;address&#39;</span> <span class="p">)</span> <span class="p">)</span> <span class="o">.</span> <span class="s1">&#39;&lt;/textarea&gt;&lt;/p&gt;&#39;</span><span class="p">;</span>		</div><div class='line' id='LC134'>	<span class="p">}</span></div><div class='line' id='LC135'><br/></div><div class='line' id='LC136'><br/></div><div class='line' id='LC137'><span class="p">}</span></div><div class='line' id='LC138'><br/></div><div class='line' id='LC139'><br/></div><div class='line' id='LC140'><span class="nx">add_action</span><span class="p">(</span> <span class="s1">&#39;genesis_admin_menu&#39;</span><span class="p">,</span> <span class="s1">&#39;be_add_child_theme_settings&#39;</span> <span class="p">);</span></div><div class='line' id='LC141'><span class="sd">/**</span></div><div class='line' id='LC142'><span class="sd"> * Add the Theme Settings Page</span></div><div class='line' id='LC143'><span class="sd"> *</span></div><div class='line' id='LC144'><span class="sd"> * @since 1.0.0</span></div><div class='line' id='LC145'><span class="sd"> */</span></div><div class='line' id='LC146'><span class="k">function</span> <span class="nf">be_add_child_theme_settings</span><span class="p">()</span> <span class="p">{</span></div><div class='line' id='LC147'>	<span class="k">global</span> <span class="nv">$_child_theme_settings</span><span class="p">;</span></div><div class='line' id='LC148'>	<span class="nv">$_child_theme_settings</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Child_Theme_Settings</span><span class="p">;</span>	 	</div><div class='line' id='LC149'><span class="p">}</span></div><div class='line' id='LC150'><br/></div></pre></div></div><div
class="gist-meta"> <a
href="https://gist.github.com/raw/1650977/e03ac15bef2990ebfbc39bfa1e474d97016fc1e2/gistfile1.aw" style="float:right;">view raw</a> <a
href="https://gist.github.com/1650977#file_gistfile1.aw" style="float:right;margin-right:10px;color:#666">gistfile1.aw</a> <a
href="https://gist.github.com/1650977">This Gist</a> brought to you by <a
href="http://github.com">GitHub</a>.</div></div></div><p>And once you do have your custom admin page up-and-running, you&#8217;ll need to access that information. Just use <code>genesis_get_option( [field-name], [settings-field] );</code>.</p><p>So in the above example, to access the phone number use: <code>$phone = genesis_get_option( 'phone', 'child-settings' );</code>.</p> <img src="http://feeds.feedburner.com/~r/BillErickson/~4/4JFEbdWm3_0" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://www.billerickson.net/admin-pages-with-genesis/feed/</wfw:commentRss> <slash:comments>11</slash:comments> <feedburner:origLink>http://www.billerickson.net/admin-pages-with-genesis/</feedburner:origLink></item> <item><title>Manually Curated Related Posts</title><link>http://feedproxy.google.com/~r/BillErickson/~3/m9zFufzTgkA/</link> <comments>http://www.billerickson.net/manually-curated-related-posts/#comments</comments> <pubDate>Tue, 17 Jan 2012 02:44:45 +0000</pubDate> <dc:creator>Bill Erickson</dc:creator> <category><![CDATA[Tutorial]]></category> <category><![CDATA[advanced]]></category> <category><![CDATA[functionality]]></category> <category><![CDATA[related-posts]]></category> <category><![CDATA[wordpress]]></category> <guid isPermaLink="false">http://www.billerickson.net/?p=4148</guid> <description><![CDATA[Here's a way to specify which posts show up as "related" to the current post, as an alternative to the many plugins that automatically generate your list of related posts.]]></description> <content:encoded><![CDATA[<p>There&#8217;s a bunch of plugins to automatically generate related posts &#8211; <a
href="http://wordpress.org/extend/plugins/yet-another-related-posts-plugin/">YARPP</a> is my personal favorite. But some people prefer to have more control over their related posts and manually select them. This can be set up pretty easily using the <a
href="http://wordpress.org/extend/plugins/posts-to-posts/">Posts 2 Posts</a> plugin.</p><p>There&#8217;s three pieces of code we&#8217;ll add to our core functionality plugin <sup><a
href="#footnote-1">1</a></sup>:</p><ol><li>Register the connection. This adds the metaboxes for linking posts.</li><li>Pre-Loop code. This adds the related posts information to the $wp_query (better performance)</li><li>Display Related Posts.</li></ol><h3>Register the Connection</h3><div
id="gist-1624373" class="gist"><div
class="gist-file"><div
class="gist-data gist-syntax"><div
class="highlight"><pre><div class='line' id='LC1'><span class="cp">&lt;?php</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'><span class="nx">add_action</span><span class="p">(</span> <span class="s1">&#39;init&#39;</span><span class="p">,</span> <span class="s1">&#39;be_post_type_connections&#39;</span> <span class="p">);</span></div><div class='line' id='LC4'><span class="sd">/**</span></div><div class='line' id='LC5'><span class="sd"> * Related Post Connection</span></div><div class='line' id='LC6'><span class="sd"> * @author Bill Erickson</span></div><div class='line' id='LC7'><span class="sd"> * @link http://www.billerickson.net/manually-curated-related-posts/</span></div><div class='line' id='LC8'><span class="sd"> *</span></div><div class='line' id='LC9'><span class="sd"> * @uses Posts2Posts</span></div><div class='line' id='LC10'><span class="sd"> * @link https://github.com/scribu/wp-posts-to-posts/wiki</span></div><div class='line' id='LC11'><span class="sd"> */</span></div><div class='line' id='LC12'><span class="k">function</span> <span class="nf">be_post_type_connections</span><span class="p">()</span> <span class="p">{</span></div><div class='line' id='LC13'><br/></div><div class='line' id='LC14'>	<span class="c1">// Make Sure plugin is active</span></div><div class='line' id='LC15'>	<span class="k">if</span> <span class="p">(</span> <span class="o">!</span><span class="nb">function_exists</span><span class="p">(</span> <span class="s1">&#39;p2p_register_connection_type&#39;</span> <span class="p">)</span> <span class="p">)</span></div><div class='line' id='LC16'>		<span class="k">return</span><span class="p">;</span></div><div class='line' id='LC17'><br/></div><div class='line' id='LC18'>	<span class="nx">p2p_register_connection_type</span><span class="p">(</span> <span class="k">array</span><span class="p">(</span></div><div class='line' id='LC19'>		<span class="s1">&#39;name&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;related-articles&#39;</span><span class="p">,</span> <span class="c1">// unique name</span></div><div class='line' id='LC20'>		<span class="s1">&#39;from&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;post&#39;</span><span class="p">,</span></div><div class='line' id='LC21'>		<span class="s1">&#39;to&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;post&#39;</span><span class="p">,</span></div><div class='line' id='LC22'>		<span class="s1">&#39;title&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span> <span class="s1">&#39;to&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;All Connections&#39;</span><span class="p">,</span> <span class="s1">&#39;from&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;Related Articles&#39;</span> <span class="p">)</span></div><div class='line' id='LC23'>	<span class="p">)</span> <span class="p">);</span></div><div class='line' id='LC24'><span class="p">}</span></div></pre></div></div><div
class="gist-meta"> <a
href="https://gist.github.com/raw/1624373/62440d38d2234f1d3d3b2058b5a954741ed5c94f/gistfile1.aw" style="float:right;">view raw</a> <a
href="https://gist.github.com/1624373#file_gistfile1.aw" style="float:right;margin-right:10px;color:#666">gistfile1.aw</a> <a
href="https://gist.github.com/1624373">This Gist</a> brought to you by <a
href="http://github.com">GitHub</a>.</div></div></div><p>I&#8217;m creating this connection from the <code>post</code> post type, to the <code>post</code> post type. So when you&#8217;re editing a post, you can select other posts to connect it to. This actually creates two metaboxes: a <code>from</code> metabox that you use to connect the current post to others, and a <code>to</code> metabox that shows what posts have already been connected to this one. I&#8217;ve labeled the <code>from</code> metabox &#8220;Related Articles&#8221; since this is what is displayed as related to the current post, and I labeled <code>to</code> &#8220;All Connections&#8221;.</p><p>Once you add this code to your site, you should see metaboxes like this when editing a post:</p><p><img
src="http://www.billerickson.net/wp-content/uploads/2012/01/Screen-Shot-2012-01-16-at-9.24.08-PM.png" alt="" title="Screen Shot 2012-01-16 at 9.24.08 PM" class="aligncenter size-full wp-image-4158" /></p><h3>Pre-Loop Code</h3><div
id="gist-1624451" class="gist"><div
class="gist-file"><div
class="gist-data gist-syntax"><div
class="highlight"><pre><div class='line' id='LC1'><span class="cp">&lt;?php</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'><span class="sd">/**</span></div><div class='line' id='LC4'><span class="sd"> * Related Posts Before Loop</span></div><div class='line' id='LC5'><span class="sd"> * Adds connection data to $wp_query. Run before the loop.</span></div><div class='line' id='LC6'><span class="sd"> *</span></div><div class='line' id='LC7'><span class="sd"> * @author Bill Erickson</span></div><div class='line' id='LC8'><span class="sd"> * @link http://www.billerickson.net/manually-curated-related-posts/</span></div><div class='line' id='LC9'><span class="sd"> */</span></div><div class='line' id='LC10'><span class="k">function</span> <span class="nf">be_related_posts_pre_loop</span><span class="p">()</span> <span class="p">{</span></div><div class='line' id='LC11'>&nbsp;	<span class="c1">// Make Sure plugin is active</span></div><div class='line' id='LC12'>&nbsp;	<span class="k">if</span> <span class="p">(</span> <span class="o">!</span><span class="nb">function_exists</span><span class="p">(</span> <span class="s1">&#39;p2p_register_connection_type&#39;</span> <span class="p">)</span> <span class="p">)</span></div><div class='line' id='LC13'>		<span class="k">return</span><span class="p">;</span></div><div class='line' id='LC14'><br/></div><div class='line' id='LC15'>	<span class="k">global</span> <span class="nv">$wp_query</span><span class="p">;</span></div><div class='line' id='LC16'>	<span class="nx">p2p_type</span><span class="p">(</span> <span class="s1">&#39;related-articles&#39;</span> <span class="p">)</span><span class="o">-&gt;</span><span class="na">each_connected</span><span class="p">(</span> <span class="nv">$wp_query</span> <span class="p">);</span>	</div><div class='line' id='LC17'><span class="p">}</span></div><div class='line' id='LC18'><br/></div></pre></div></div><div
class="gist-meta"> <a
href="https://gist.github.com/raw/1624451/5c49ee7321dc037199113aedd677bb4731995959/gistfile1.aw" style="float:right;">view raw</a> <a
href="https://gist.github.com/1624451#file_gistfile1.aw" style="float:right;margin-right:10px;color:#666">gistfile1.aw</a> <a
href="https://gist.github.com/1624451">This Gist</a> brought to you by <a
href="http://github.com">GitHub</a>.</div></div></div><p>As described in the <a
href="https://github.com/scribu/wp-posts-to-posts/wiki/Looping-The-Loop">Posts 2 Posts wiki</a>, when dealing with archive pages its much better to add the connected posts to the $wp_query before you run the loop.</p><h3>Display Related Posts</h3><div
id="gist-1624461" class="gist"><div
class="gist-file"><div
class="gist-data gist-syntax"><div
class="highlight"><pre><div class='line' id='LC1'><span class="cp">&lt;?php</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'><span class="sd">/**</span></div><div class='line' id='LC4'><span class="sd"> * Display Related Posts</span></div><div class='line' id='LC5'><span class="sd"> * @author Bill Erickson</span></div><div class='line' id='LC6'><span class="sd"> * @link http://www.billerickson.net/manually-curated-related-posts/</span></div><div class='line' id='LC7'><span class="sd"> */</span></div><div class='line' id='LC8'><span class="k">function</span> <span class="nf">be_related_posts</span><span class="p">()</span> <span class="p">{</span></div><div class='line' id='LC9'>&nbsp;	<span class="c1">// Make Sure plugin is active</span></div><div class='line' id='LC10'>&nbsp;	<span class="k">if</span> <span class="p">(</span> <span class="o">!</span><span class="nb">function_exists</span><span class="p">(</span> <span class="s1">&#39;p2p_register_connection_type&#39;</span> <span class="p">)</span> <span class="p">)</span></div><div class='line' id='LC11'>		<span class="k">return</span><span class="p">;</span></div><div class='line' id='LC12'><br/></div><div class='line' id='LC13'>	<span class="k">global</span> <span class="nv">$post</span><span class="p">;</span></div><div class='line' id='LC14'>	<span class="k">if</span><span class="p">(</span> <span class="nb">isset</span><span class="p">(</span> <span class="nv">$post</span><span class="o">-&gt;</span><span class="na">connected</span> <span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="k">empty</span><span class="p">(</span> <span class="nv">$post</span><span class="o">-&gt;</span><span class="na">connected</span> <span class="p">)</span> <span class="p">)</span><span class="o">:</span></div><div class='line' id='LC15'>		<span class="k">echo</span> <span class="s1">&#39;&lt;div class=&quot;related-posts&quot;&gt;&#39;</span><span class="p">;</span></div><div class='line' id='LC16'>		<span class="nv">$count</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span></div><div class='line' id='LC17'>		<span class="k">foreach</span><span class="p">(</span> <span class="nv">$post</span><span class="o">-&gt;</span><span class="na">connected</span> <span class="k">as</span> <span class="nv">$related</span> <span class="p">)</span><span class="o">:</span></div><div class='line' id='LC18'>			<span class="k">if</span><span class="p">(</span> <span class="nv">$count</span> <span class="o">&lt;</span> <span class="mi">6</span> <span class="p">)</span> <span class="p">{</span>	</div><div class='line' id='LC19'>				<span class="k">echo</span> <span class="s1">&#39;&lt;div class=&quot;related-post&quot;&gt;&#39;</span><span class="p">;</span></div><div class='line' id='LC20'>				<span class="k">echo</span> <span class="s1">&#39;&lt;a class=&quot;image&quot; href=&quot;&#39;</span> <span class="o">.</span> <span class="nx">get_permalink</span><span class="p">(</span> <span class="nv">$related</span><span class="o">-&gt;</span><span class="na">ID</span> <span class="p">)</span> <span class="o">.</span> <span class="s1">&#39;&quot;&gt;&#39;</span><span class="p">;</span></div><div class='line' id='LC21'>				<span class="nv">$cat</span> <span class="o">=</span> <span class="nx">wp_get_object_terms</span><span class="p">(</span> <span class="nv">$related</span><span class="o">-&gt;</span><span class="na">ID</span><span class="p">,</span> <span class="s1">&#39;category&#39;</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span> <span class="s1">&#39;count&#39;</span> <span class="o">=&gt;</span> <span class="mi">1</span> <span class="p">)</span> <span class="p">);</span></div><div class='line' id='LC22'>				<span class="k">echo</span> <span class="s1">&#39;&lt;span class=&quot;category&quot;&gt;&#39;</span> <span class="o">.</span> <span class="nv">$cat</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-&gt;</span><span class="na">name</span> <span class="o">.</span> <span class="s1">&#39;&lt;/span&gt;&#39;</span><span class="p">;</span></div><div class='line' id='LC23'>				<span class="k">echo</span> <span class="nx">get_the_post_thumbnail</span><span class="p">(</span> <span class="nv">$related</span><span class="o">-&gt;</span><span class="na">ID</span><span class="p">,</span> <span class="s1">&#39;be_home_small&#39;</span> <span class="p">);</span></div><div class='line' id='LC24'>				<span class="k">echo</span> <span class="s1">&#39;&lt;/a&gt;&#39;</span><span class="p">;</span></div><div class='line' id='LC25'>				<span class="k">echo</span> <span class="s1">&#39;&lt;a class=&quot;title&quot; href=&quot;&#39;</span> <span class="o">.</span> <span class="nx">get_permalink</span><span class="p">(</span> <span class="nv">$related</span><span class="o">-&gt;</span><span class="na">ID</span> <span class="p">)</span> <span class="o">.</span> <span class="s1">&#39;&quot;&gt;&#39;</span> <span class="o">.</span> <span class="nv">$related</span><span class="o">-&gt;</span><span class="na">post_title</span> <span class="o">.</span> <span class="s1">&#39;&lt;/a&gt;&#39;</span><span class="p">;</span></div><div class='line' id='LC26'>				<span class="k">echo</span> <span class="s1">&#39;&lt;/div&gt;&#39;</span><span class="p">;</span></div><div class='line' id='LC27'>				<span class="nv">$count</span><span class="o">++</span><span class="p">;</span></div><div class='line' id='LC28'>			<span class="p">}</span></div><div class='line' id='LC29'>		<span class="k">endforeach</span><span class="p">;</span></div><div class='line' id='LC30'>		<span class="k">echo</span> <span class="s1">&#39;&lt;/div&gt;&#39;</span><span class="p">;</span></div><div class='line' id='LC31'>	<span class="k">endif</span><span class="p">;</span></div><div class='line' id='LC32'><span class="p">}</span></div><div class='line' id='LC33'><br/></div></pre></div></div><div
class="gist-meta"> <a
href="https://gist.github.com/raw/1624461/b8fd68966bdfe5e20ac38b04735c6695e65eac2b/gistfile1.aw" style="float:right;">view raw</a> <a
href="https://gist.github.com/1624461#file_gistfile1.aw" style="float:right;margin-right:10px;color:#666">gistfile1.aw</a> <a
href="https://gist.github.com/1624461">This Gist</a> brought to you by <a
href="http://github.com">GitHub</a>.</div></div></div><p>You can of course display the related posts however you&#8217;d like. For my specific implementation, I wanted to limit it to 5, display the post image at a specific size, float the category name on top of the post image, and then display the title below the image.</p><p>The important thing to note is that <code>$post->connected</code> is an array of post objects, so use the <code>foreach()</code> to loop through them and then display the post data however you&#8217;d like.</p><h3>Integrating it with your theme</h3><p>Once you&#8217;ve added this code to your core functionality plugin, you have to actually call it in your theme. Just place <code>be_related_posts_pre_loop()</code> before you call <a
href="http://codex.wordpress.org/The_Loop">the loop</a>, and <code>be_related_posts()</code> somewhere inside the loop. If you&#8217;re using <a
href="http://www.billerickson.net/go/genesis/" title="Genesis">Genesis</a>, it has hooks throughout the theme, so you just need to add the following two lines to your theme&#8217;s functions.php file (alter the second line to change the positioning of the related posts):</p><div
id="gist-1624498" class="gist"><div
class="gist-file"><div
class="gist-data gist-syntax"><div
class="highlight"><pre><div class='line' id='LC1'><span class="cp">&lt;?php</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'><span class="c1">// Related Posts (see mu-plugins/lib/functions/related-posts.php</span></div><div class='line' id='LC4'><span class="nx">add_action</span><span class="p">(</span> <span class="s1">&#39;genesis_before_loop&#39;</span><span class="p">,</span> <span class="s1">&#39;be_related_posts_pre_loop&#39;</span> <span class="p">);</span></div><div class='line' id='LC5'><span class="nx">add_action</span><span class="p">(</span> <span class="s1">&#39;genesis_after_post_content&#39;</span><span class="p">,</span> <span class="s1">&#39;be_related_posts&#39;</span><span class="p">,</span> <span class="mi">15</span> <span class="p">);</span></div><div class='line' id='LC6'><br/></div></pre></div></div><div
class="gist-meta"> <a
href="https://gist.github.com/raw/1624498/92956d0b85cb5b3766081a3ee44a2f4970adc0a3/gistfile1.aw" style="float:right;">view raw</a> <a
href="https://gist.github.com/1624498#file_gistfile1.aw" style="float:right;margin-right:10px;color:#666">gistfile1.aw</a> <a
href="https://gist.github.com/1624498">This Gist</a> brought to you by <a
href="http://github.com">GitHub</a>.</div></div></div><p>I&#8217;d love to hear any thoughts you have about this, especially if you have experience with Posts 2 Posts.</p><ol
class="footnote"><li
id="footnote-1"><strong>Core Functionality Plugin</strong><br
/> While you could put all this code in your theme&#8217;s functions.php file, a <a
href="http://www.billerickson.net/core-functionality-plugin/" title="Core Functionality Plugin">core functionality plugin</a> is better for things like this because if you change your theme in the future, you&#8217;ll want to easily move this functionality to your new theme. If it&#8217;s in a plugin, all you have to do is add two lines to your theme (call the pre-loop code and then the display code). If all the code is in your old theme, you have to dig through all your files, figuring out how you built your related posts section so you can duplicate it in your new theme. In my core functionality plugin, I created <em>/lib/functions/related-posts.php</em> so that all the code was on one location.</li></ol> <img src="http://feeds.feedburner.com/~r/BillErickson/~4/m9zFufzTgkA" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://www.billerickson.net/manually-curated-related-posts/feed/</wfw:commentRss> <slash:comments>5</slash:comments> <feedburner:origLink>http://www.billerickson.net/manually-curated-related-posts/</feedburner:origLink></item> <item><title>Using Column Classes</title><link>http://feedproxy.google.com/~r/BillErickson/~3/VzpodhXNUNQ/</link> <comments>http://www.billerickson.net/using-column-classes/#comments</comments> <pubDate>Fri, 23 Dec 2011 15:52:57 +0000</pubDate> <dc:creator>Bill Erickson</dc:creator> <category><![CDATA[Tutorial]]></category> <category><![CDATA[basic]]></category> <category><![CDATA[css]]></category> <category><![CDATA[wordpress]]></category> <guid isPermaLink="false">http://www.billerickson.net/?p=4114</guid> <description><![CDATA[Here's how I make multiple columns of content.]]></description> <content:encoded><![CDATA[<p><a
href="http://www.billerickson.net/go/genesis">Genesis</a> comes pre-built with a great bit of CSS called Column Classes. This allows you to easily make <a
href="http://demo.studiopress.com/genesis/columns">multiple columns of content</a> with a bit of CSS. You can also add this to any theme with the CSS at <a
href="http://www.studiopress.com/tutorials/genesis/content-column-classes">bottom of this page</a>.</p><p>There&#8217;s two different ways I set up client sites to use this:</p><ul><li>Adding Editor Styles</li><li>Div Shortcode Plugin</li></ul><h3>Adding Editor Styles</h3><p>If the client is somewhat comfortable with HTML &#8211; she&#8217;s not afraid to click the &#8220;HTML&#8221; tab in the editor &#8211; then I&#8217;ll add the column classes to the editor&#8217;s stylesheet. This will make it so the columns are visible in the editor and the client can easily see where the content she&#8217;s writing will show up. I also recommend using the fullscreen editor when using this because the inline one is a bit too small.</p><p>In your theme, create a file called <code>editor-style.css</code> and add the column class CSS styles to it. You can also add any other styles you&#8217;d like reflected in the editor (I often add the headlines styles so the client can visually see how her h2&#8242;s and h3&#8242;s will look from the editor).</p><p>Then, add this to your functions.php file: <code>add_editor_style( 'editor-style.css' );</code>.</p><p>That&#8217;s it! Now when editing a post, switch to HTML view and add this:</p><div
id="gist-1514523" class="gist"><div
class="gist-file"><div
class="gist-data gist-syntax"><div
class="highlight"><pre><div class='line' id='LC1'>&lt;div class=&quot;one-half first&quot;&gt;</div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'>Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.</div><div class='line' id='LC4'><br/></div><div class='line' id='LC5'>&lt;/div&gt;</div><div class='line' id='LC6'><br/></div><div class='line' id='LC7'>&lt;div class=&quot;one-half&quot;&gt;</div><div class='line' id='LC8'><br/></div><div class='line' id='LC9'>Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.</div><div class='line' id='LC10'><br/></div><div class='line' id='LC11'>&lt;/div&gt;</div></pre></div></div><div
class="gist-meta"> <a
href="https://gist.github.com/raw/1514523/88d40139eafe7b11e97a192684c20569cc4fa5c2/gistfile1.txt" style="float:right;">view raw</a> <a
href="https://gist.github.com/1514523#file_gistfile1.txt" style="float:right;margin-right:10px;color:#666">gistfile1.txt</a> <a
href="https://gist.github.com/1514523">This Gist</a> brought to you by <a
href="http://github.com">GitHub</a>.</div></div></div><p>When you switch back to Visual view, your editor should look like this:</p><p><img
class="alignnone size-large wp-image-4115" title="columns-in-visual-editor" src="http://www.billerickson.net/wp-content/uploads/2011/12/columns-in-visual-editor-500x199.jpg" alt="" /></p><h3>Div Shortcode Plugin</h3><p>For those who get completely lost in the HTML tab, I have a plugin that let&#8217;s them use [div] shortcodes. Once <a
href="http://www.wordpress.org/extend/plugins/div-shortcode">Div Shortcode Plugin</a> is activated, they just have to write something like this in the Visual Editor:</p><div
id="gist-1514517" class="gist"><div
class="gist-file"><div
class="gist-data gist-syntax"><div
class="highlight"><pre><div class='line' id='LC1'>[div class=&quot;one-half first&quot;]</div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'>This is the left column</div><div class='line' id='LC4'><br/></div><div class='line' id='LC5'>[end-div]</div><div class='line' id='LC6'><br/></div><div class='line' id='LC7'>[div class=&quot;one-half&quot;]</div><div class='line' id='LC8'><br/></div><div class='line' id='LC9'>This is the right column</div><div class='line' id='LC10'><br/></div><div class='line' id='LC11'>[end-div]</div></pre></div></div><div
class="gist-meta"> <a
href="https://gist.github.com/raw/1514517/40ffb5dc078c84ed1c0726a021bebe1896e0a2a9/gistfile1.txt" style="float:right;">view raw</a> <a
href="https://gist.github.com/1514517#file_gistfile1.txt" style="float:right;margin-right:10px;color:#666">gistfile1.txt</a> <a
href="https://gist.github.com/1514517">This Gist</a> brought to you by <a
href="http://github.com">GitHub</a>.</div></div></div><p>The benefit here is that they can see exactly where in the Visual editor one column is ending and another is beginning. They&#8217;re able to control div&#8217;s without ever switching to the HTML view (where they might get lost).</p><h3>Other Notes</h3><p>When building out a site, I&#8217;ll often create two sample pages using each technique so the client can choose which is best for her.</p><p>If every page will have the same number of columns, you might consider <a
href="http://wp.smashingmagazine.com/2011/10/14/advanced-layout-templates-in-wordpress-content-editor/">pre-populating the content area with default text</a>. This way they never have to switch to HTML mode to create the columns &#8211; they are there already.</p><p>It looks like a future version of Genesis might include icons in the TinyMCE Editor for creating the columns, which will give you one more way for doing this.</p> <img src="http://feeds.feedburner.com/~r/BillErickson/~4/VzpodhXNUNQ" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://www.billerickson.net/using-column-classes/feed/</wfw:commentRss> <slash:comments>6</slash:comments> <feedburner:origLink>http://www.billerickson.net/using-column-classes/</feedburner:origLink></item> <item><title>Reusing Template Files</title><link>http://feedproxy.google.com/~r/BillErickson/~3/zB9SU8EvDGo/</link> <comments>http://www.billerickson.net/reusing-wordpress-theme-files/#comments</comments> <pubDate>Wed, 07 Dec 2011 21:09:29 +0000</pubDate> <dc:creator>Bill Erickson</dc:creator> <category><![CDATA[Tutorial]]></category> <category><![CDATA[intermediate]]></category> <category><![CDATA[template]]></category> <category><![CDATA[wordpress]]></category> <guid isPermaLink="false">http://www.billerickson.net/?p=4067</guid> <description><![CDATA[I walk you through building your own template hierarchy, to specify which template to use under certain conditions.]]></description> <content:encoded><![CDATA[<p>WordPress&#8217; built-in <a
href="http://codex.wordpress.org/Template_Hierarchy">template hierarchy</a> is very useful for reusing template files on standard websites. If you have something you want used for all category archives, use category.php. If you want a template file to be used on all archives (category, tag, search&#8230;), use archive.php.</p><p>But when you&#8217;re building websites with complex content structures, you&#8217;ll often need to build a very specific template hierarchy of your own, or else duplicate a lot of code.</p><p>I&#8217;m building a site right now with four custom post types, and each post type has 2-4 taxonomies. Take a look at the screenshot above. The &#8216;recipe&#8217; post type has two taxonomies: &#8216;name-range&#8217; which allows the client to break down the list of recipes by name (ex: A-D, E-G&#8230;), and &#8216;base&#8217; (dropdown says category), which is a shared taxonomy with another post type that specifies the alcoholic base of the cocktail.</p><p>I want a single template file that is used in all of these situations:</p><ul><li>Recipe post type archive</li><li>Name Range taxonomy archive</li><li>Base taxonomy archive (if post type is also &#8216;recipe&#8217;)</li></ul><p>For this, I&#8217;ll use the <code>template_include</code> filter. This filter runs right after WordPress determines what template it thinks it should use, but before that template is actually loaded. This is where you can hop in and specify your own template hierarchy.</p><p>Without this technique, I&#8217;d need to put the same code in archive-recipe.php, taxononomy-name-range.php, and taxonomy-base.php (with some extra code in here to check for the current post type).</p><div
id="gist-1444548" class="gist"><div
class="gist-file"><div
class="gist-data gist-syntax"><div
class="highlight"><pre><div class='line' id='LC1'><span class="cp">&lt;?php</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'><span class="sd">/**</span></div><div class='line' id='LC4'><span class="sd"> * Template Chooser</span></div><div class='line' id='LC5'><span class="sd"> * Use CPT archive templates for taxonomies</span></div><div class='line' id='LC6'><span class="sd"> * @author Bill Erickson</span></div><div class='line' id='LC7'><span class="sd"> * @link http://www.billerickson.net/code/use-same-template-for-taxonomy-and-cpt-archive/</span></div><div class='line' id='LC8'><span class="sd"> *</span></div><div class='line' id='LC9'><span class="sd"> * @param string, default template path</span></div><div class='line' id='LC10'><span class="sd"> * @return string, modified template path</span></div><div class='line' id='LC11'><span class="sd"> *</span></div><div class='line' id='LC12'><span class="sd"> */</span></div><div class='line' id='LC13'><span class="k">function</span> <span class="nf">be_template_chooser</span><span class="p">(</span> <span class="nv">$template</span> <span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC14'><br/></div><div class='line' id='LC15'>	<span class="k">if</span><span class="p">(</span> <span class="nx">is_post_type_archive</span><span class="p">(</span> <span class="s1">&#39;recipe&#39;</span> <span class="p">)</span> <span class="o">||</span> <span class="nx">is_tax</span><span class="p">(</span> <span class="s1">&#39;name-range&#39;</span> <span class="p">)</span> <span class="o">||</span> <span class="p">(</span> <span class="nx">is_tax</span><span class="p">(</span> <span class="s1">&#39;base&#39;</span> <span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="s1">&#39;recipe&#39;</span> <span class="o">==</span> <span class="nx">get_post_type</span><span class="p">()</span> <span class="p">)</span> <span class="p">)</span></div><div class='line' id='LC16'>		<span class="nv">$template</span> <span class="o">=</span> <span class="nx">get_query_template</span><span class="p">(</span> <span class="s1">&#39;archive-recipe&#39;</span> <span class="p">);</span></div><div class='line' id='LC17'>	<span class="k">return</span> <span class="nv">$template</span><span class="p">;</span></div><div class='line' id='LC18'><span class="p">}</span></div><div class='line' id='LC19'><span class="nx">add_filter</span><span class="p">(</span> <span class="s1">&#39;template_include&#39;</span><span class="p">,</span> <span class="s1">&#39;be_template_chooser&#39;</span> <span class="p">);</span></div></pre></div></div><div
class="gist-meta"> <a
href="https://gist.github.com/raw/1444548/594881761f9be9118b71b0e293a698d9ba537470/gistfile1.aw" style="float:right;">view raw</a> <a
href="https://gist.github.com/1444548#file_gistfile1.aw" style="float:right;margin-right:10px;color:#666">gistfile1.aw</a> <a
href="https://gist.github.com/1444548">This Gist</a> brought to you by <a
href="http://github.com">GitHub</a>.</div></div></div><p>The code above says &#8220;if this is the post type archive for &#8216;recipe&#8217;, the taxonomy archive &#8216;name-range&#8217;, or the taxonomy archive &#8216;base&#8217; AND post type &#8216;recipe&#8217;, then use the template file archive-recipe.php.&#8221;</p><p>I also like to generalize this section checker into its own function so I can use it elsewhere. You might want to add a body class called &#8216;section-recipe&#8217; if any of these templates are in use. Here&#8217;s how:</p><div
id="gist-1444580" class="gist"><div
class="gist-file"><div
class="gist-data gist-syntax"><div
class="highlight"><pre><div class='line' id='LC1'><span class="cp">&lt;?php</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'><span class="sd">/**</span></div><div class='line' id='LC4'><span class="sd"> * Return Archive Section</span></div><div class='line' id='LC5'><span class="sd"> * @author Bill Erickson</span></div><div class='line' id='LC6'><span class="sd"> * @link http://www.billerickson.net/code/helper-function-for-template-include-and-body-class/</span></div><div class='line' id='LC7'><span class="sd"> * </span></div><div class='line' id='LC8'><span class="sd"> * @param null</span></div><div class='line' id='LC9'><span class="sd"> * @return string</span></div><div class='line' id='LC10'><span class="sd"> */</span></div><div class='line' id='LC11'><span class="k">function</span> <span class="nf">be_return_archive_section</span><span class="p">()</span> <span class="p">{</span></div><div class='line' id='LC12'>	<span class="k">if</span><span class="p">(</span> <span class="nx">is_post_type_archive</span><span class="p">(</span> <span class="s1">&#39;lifestyle&#39;</span> <span class="p">)</span> <span class="o">||</span> <span class="nx">is_tax</span><span class="p">(</span> <span class="s1">&#39;lifestyle-section&#39;</span> <span class="p">)</span> <span class="o">||</span> <span class="nx">is_tax</span><span class="p">(</span> <span class="s1">&#39;lifestyle-type&#39;</span> <span class="p">)</span> <span class="o">||</span> <span class="nx">is_tax</span><span class="p">(</span> <span class="s1">&#39;lifestyle-series&#39;</span> <span class="p">)</span> <span class="p">)</span></div><div class='line' id='LC13'>		<span class="k">return</span> <span class="s1">&#39;lifestyle&#39;</span><span class="p">;</span></div><div class='line' id='LC14'><br/></div><div class='line' id='LC15'>	<span class="k">if</span><span class="p">(</span> <span class="nx">is_post_type_archive</span><span class="p">(</span> <span class="s1">&#39;recipe&#39;</span> <span class="p">)</span> <span class="o">||</span> <span class="nx">is_tax</span><span class="p">(</span> <span class="s1">&#39;name-range&#39;</span> <span class="p">)</span> <span class="o">||</span> <span class="p">(</span> <span class="nx">is_tax</span><span class="p">(</span> <span class="s1">&#39;base&#39;</span> <span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="s1">&#39;recipe&#39;</span> <span class="o">==</span> <span class="nx">get_post_type</span><span class="p">()</span> <span class="p">)</span> <span class="p">)</span></div><div class='line' id='LC16'>		<span class="k">return</span> <span class="s1">&#39;recipe&#39;</span><span class="p">;</span>		</div><div class='line' id='LC17'><br/></div><div class='line' id='LC18'>	<span class="k">if</span><span class="p">(</span> <span class="nx">is_post_type_archive</span><span class="p">(</span> <span class="s1">&#39;brand&#39;</span> <span class="p">)</span> <span class="o">||</span> <span class="p">(</span> <span class="nx">is_tax</span><span class="p">(</span> <span class="s1">&#39;base&#39;</span> <span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="s1">&#39;brand&#39;</span> <span class="o">==</span> <span class="nx">get_post_type</span><span class="p">()</span> <span class="p">)</span> <span class="p">)</span></div><div class='line' id='LC19'>		<span class="k">return</span> <span class="s1">&#39;brand&#39;</span><span class="p">;</span></div><div class='line' id='LC20'><br/></div><div class='line' id='LC21'>	<span class="k">if</span><span class="p">(</span> <span class="nx">is_post_type_archive</span><span class="p">(</span> <span class="s1">&#39;experience&#39;</span> <span class="p">)</span> <span class="p">)</span></div><div class='line' id='LC22'>		<span class="k">return</span> <span class="s1">&#39;experience&#39;</span><span class="p">;</span></div><div class='line' id='LC23'><br/></div><div class='line' id='LC24'>	<span class="k">return</span> <span class="k">false</span><span class="p">;</span></div><div class='line' id='LC25'><span class="p">}</span></div><div class='line' id='LC26'><br/></div><div class='line' id='LC27'><span class="nx">add_filter</span><span class="p">(</span> <span class="s1">&#39;template_include&#39;</span><span class="p">,</span> <span class="s1">&#39;be_template_chooser&#39;</span> <span class="p">);</span></div><div class='line' id='LC28'><span class="sd">/**</span></div><div class='line' id='LC29'><span class="sd"> * Template Chooser</span></div><div class='line' id='LC30'><span class="sd"> * Use CPT archive templates for taxonomies</span></div><div class='line' id='LC31'><span class="sd"> * @author Bill Erickson</span></div><div class='line' id='LC32'><span class="sd"> * @link http://www.billerickson.net/code/use-same-template-for-taxonomy-and-cpt-archive/</span></div><div class='line' id='LC33'><span class="sd"> *</span></div><div class='line' id='LC34'><span class="sd"> * @param string, default template path</span></div><div class='line' id='LC35'><span class="sd"> * @return string, modified template path</span></div><div class='line' id='LC36'><span class="sd"> *</span></div><div class='line' id='LC37'><span class="sd"> */</span></div><div class='line' id='LC38'><span class="k">function</span> <span class="nf">be_template_chooser</span><span class="p">(</span> <span class="nv">$template</span> <span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC39'>	<span class="k">if</span> <span class="p">(</span> <span class="nx">be_return_archive_section</span><span class="p">()</span> <span class="p">)</span> </div><div class='line' id='LC40'>		<span class="nv">$template</span> <span class="o">=</span> <span class="nx">get_query_template</span><span class="p">(</span> <span class="s1">&#39;archive-&#39;</span> <span class="o">.</span> <span class="nx">be_return_archive_section</span><span class="p">()</span> <span class="p">);</span>	</div><div class='line' id='LC41'><br/></div><div class='line' id='LC42'>	<span class="k">return</span> <span class="nv">$template</span><span class="p">;</span></div><div class='line' id='LC43'><span class="p">}</span></div><div class='line' id='LC44'><br/></div><div class='line' id='LC45'><span class="nx">add_filter</span><span class="p">(</span> <span class="s1">&#39;body_class&#39;</span><span class="p">,</span> <span class="s1">&#39;be_section_body_classes&#39;</span> <span class="p">);</span></div><div class='line' id='LC46'><span class="sd">/**</span></div><div class='line' id='LC47'><span class="sd"> * Section Body Classes</span></div><div class='line' id='LC48'><span class="sd"> * @author Bill Erickson</span></div><div class='line' id='LC49'><span class="sd"> * </span></div><div class='line' id='LC50'><span class="sd"> * @param array $classes</span></div><div class='line' id='LC51'><span class="sd"> * @return array</span></div><div class='line' id='LC52'><span class="sd"> */</span></div><div class='line' id='LC53'><span class="k">function</span> <span class="nf">be_section_body_classes</span><span class="p">(</span> <span class="nv">$classes</span> <span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC54'>	<span class="k">if</span><span class="p">(</span> <span class="nx">be_return_archive_section</span><span class="p">()</span> <span class="p">)</span></div><div class='line' id='LC55'>		<span class="nv">$classes</span><span class="p">[]</span> <span class="o">=</span> <span class="s1">&#39;section-&#39;</span> <span class="o">.</span> <span class="nx">be_return_archive_section</span><span class="p">();</span></div><div class='line' id='LC56'><br/></div><div class='line' id='LC57'>	<span class="k">return</span> <span class="nv">$classes</span><span class="p">;</span></div><div class='line' id='LC58'><span class="p">}</span></div></pre></div></div><div
class="gist-meta"> <a
href="https://gist.github.com/raw/1444580/eb67f349f2e0523fa47f920b046031866b63a46f/gistfile1.aw" style="float:right;">view raw</a> <a
href="https://gist.github.com/1444580#file_gistfile1.aw" style="float:right;margin-right:10px;color:#666">gistfile1.aw</a> <a
href="https://gist.github.com/1444580">This Gist</a> brought to you by <a
href="http://github.com">GitHub</a>.</div></div></div><p>First I&#8217;m creating a function that returns the current section if there&#8217;s a match, and &#8216;false&#8217; if there isn&#8217;t.</p><p>Then I have my template redirect function. If the current page is in a section, it loads the template &#8216;archive-$section&#8217; (ex: archive-recipe.php).</p><p>Then I have my body class filter. If the current page is in a section, it adds the body class &#8216;section-$section&#8217; (ex: &#8216;section-recipe&#8217; ).</p><p>If you add a new taxonomy, just edit the <code>be_return_archive_section()</code> function to specify the section it belongs in, and it will automatically use the correct template file and have the body class.</p> <img src="http://feeds.feedburner.com/~r/BillErickson/~4/zB9SU8EvDGo" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://www.billerickson.net/reusing-wordpress-theme-files/feed/</wfw:commentRss> <slash:comments>9</slash:comments> <feedburner:origLink>http://www.billerickson.net/reusing-wordpress-theme-files/</feedburner:origLink></item> <item><title>Custom Metaboxes 0.7</title><link>http://feedproxy.google.com/~r/BillErickson/~3/hT851h9weyQ/</link> <comments>http://www.billerickson.net/custom-metaboxes-0-point-7/#comments</comments> <pubDate>Mon, 14 Nov 2011 20:40:56 +0000</pubDate> <dc:creator>Bill Erickson</dc:creator> <category><![CDATA[Release]]></category> <category><![CDATA[wordpress]]></category> <guid isPermaLink="false">http://www.billerickson.net/?p=4043</guid> <description><![CDATA[Use this code library to easily create metaboxes with all different types of fields. I review some of the newest features to CMB 0.7]]></description> <content:encoded><![CDATA[<h3><a
href="https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress">» Download the CMB Library here</a></h3><p>It&#8217;s been about six months since my original <a
href="http://www.billerickson.net/wordpress-metaboxes/">Custom Metaboxes</a> post announcing the release of this code library for easily creating metaboxes. If you haven&#8217;t had a look at it since then, I highly recommend you hop on Github and <a
href="https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress">look at the latest version</a> and the <a
href="https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress/wiki">wiki</a>.</p><h3>Some of the features:</h3><ul><li>The ability to create metaboxes with a simple array rather than a ton of code. Compare <a
href="http://wp.smashingmagazine.com/2011/10/04/create-custom-post-meta-boxes-wordpress/">this tutorial</a> (without our library) to <a
href="https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress/blob/master/example-functions.php">these examples</a> (with our library).</li><li>Choose from <a
href="https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress/wiki/Field-Types">20 included field types</a>, or <a
href="https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress/wiki/Adding-your-own-field-types">add your own field types</a></li><li>You can <a
href="https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress/wiki/Display-Options">limit the metabox</a> to specific post types, page template, page IDs, or <a
href="https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress/wiki/Adding-your-own-show_on-filters">create your own filter</a> for where it should show up</li><li>This can be used by both themes and plugins. And as long as you initialize it correctly (see bottom of <a
href="https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress/blob/master/example-functions.php">example-functions.php</a>), it can be used by a theme and as many plugins as you like at the same time.</li></ul><h3>My favorite field types:</h3><ul><li>WYSIWYG. If you&#8217;re using WordPress 3.3, this will automatically use the new wp_editor which gives you a ton of flexibility.</li><li>Taxonomy field types (select, radio, multicheck). If you&#8217;re dealing with a lot of taxonomies, the default metabox provided by WordPress takes up a lot of screen real estate. Include taxonomies in your custom metabox instead. Using select or radio is also a great way to force users to only select one taxonomy term.</li><li>File upload. Use the built-in media uploader to allow the user to upload any file they want. You can also store the attachment ID in case you want to retrieve other image sizes.</li><li>Title. If your metabox has a lot of fields in it, use the title field type to create subheadings and instructions.</li><li>Text (standard, medium, and small). This is as simple as it comes, but also the one you&#8217;ll use most often.</li><li>text_date_timestamp. This one uses a date picker to let the user select a date, and then saves it as a UNIX timestamp. This is great for event metaboxes because you can then <a
href="http://www.billerickson.net/customize-the-wordpress-query/#example-postmeta">query based on the date</a>.</li></ul><p>The contributors of this code library, in no particular order, include: Andrew Norcross, Jared Atchison, Travis Smith, Randy Hoyt, Jeremy Pry, Andrew Ryno, Patrick Forringer, Chris Olbekson, Stefan Crain  &#8230;and me.</p><p>Please use this code, and consider contributing any improvements you make. If you create any <a
href="https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress/wiki/Adding-your-own-field-types">field types</a> or<a
href="https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress/wiki/Adding-your-own-show_on-filters"> show_on filters</a>, post them on the wiki. If you find any bugs, post them in <a
href="https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress/issues">issues</a> (and even better, post the fix!).</p> <img src="http://feeds.feedburner.com/~r/BillErickson/~4/hT851h9weyQ" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://www.billerickson.net/custom-metaboxes-0-point-7/feed/</wfw:commentRss> <slash:comments>39</slash:comments> <feedburner:origLink>http://www.billerickson.net/custom-metaboxes-0-point-7/</feedburner:origLink></item> <item><title>Changes to my site</title><link>http://feedproxy.google.com/~r/BillErickson/~3/qGQOOO2IwpA/</link> <comments>http://www.billerickson.net/changes-to-my-site/#comments</comments> <pubDate>Sun, 30 Oct 2011 15:21:48 +0000</pubDate> <dc:creator>Bill Erickson</dc:creator> <category><![CDATA[General]]></category> <guid isPermaLink="false">http://www.billerickson.net/?p=4014</guid> <description><![CDATA[I&#8217;ve spent the weekend cleaning up the content of my site. The biggest thing I&#8217;ve done is migrate all the code from all my posts to github. This might mess with feedreaders a bit (some might not include the code), but it will make maintaining the code much easier. Keeping WordPress from messing up code [...]]]></description> <content:encoded><![CDATA[<p>I&#8217;ve spent the weekend cleaning up the content of my site. The biggest thing I&#8217;ve done is migrate all the code from all my posts to github. This might mess with feedreaders a bit (some might not include the code), but it will make maintaining the code much easier.</p><p>Keeping WordPress from messing up code you&#8217;re sharing in the post editor can be difficult, and a lot of my old posts had mangled code. By moving everything to github I don&#8217;t have to worry about this anymore. It also means I can have a single source of code linked from multiple places (in a blog post, in a code snippet post&#8230;).</p><p>Other changes:</p><ul><li>Created a <a
href="http://www.billerickson.net/code">Code Snippets</a> area of my site. There&#8217;s a lot of little things I&#8217;d like to store on here but didn&#8217;t warrant a full blog post. It also makes searching through this code easier (there&#8217;s a tag cloud at the top). The RSS feed for my code snippets is <a
href="http://feeds.feedburner.com/BillEricksonCode">http://feeds.feedburner.com/BillEricksonCode</a></li><li>I&#8217;ve added an &#8220;old&#8221; category to my blog. If a tutorial is in this category, it is automatically appended with a notice that the code in here might not work and is no longer maintained. These posts are also excluded from search.</li><li>I created a <a
href="http://www.billerickson.net/contributions/">Contributions</a> page, which lists all my tutorials, themes, plugins, code snippets, patches, and developer tools. It&#8217;s great to finally have all this listed in one place.</li></ul><p>So take a look around the site and let me know what you think.</p> <img src="http://feeds.feedburner.com/~r/BillErickson/~4/qGQOOO2IwpA" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://www.billerickson.net/changes-to-my-site/feed/</wfw:commentRss> <slash:comments>2</slash:comments> <feedburner:origLink>http://www.billerickson.net/changes-to-my-site/</feedburner:origLink></item> <item><title>Gallery Metabox</title><link>http://feedproxy.google.com/~r/BillErickson/~3/R5ozjyWIGtc/</link> <comments>http://www.billerickson.net/gallery-metabox/#comments</comments> <pubDate>Fri, 28 Oct 2011 15:31:01 +0000</pubDate> <dc:creator>Bill Erickson</dc:creator> <category><![CDATA[Release]]></category> <category><![CDATA[gallery]]></category> <category><![CDATA[images]]></category> <category><![CDATA[plugin]]></category> <category><![CDATA[wordpress]]></category> <guid isPermaLink="false">http://www.billerickson.net/?p=3582</guid> <description><![CDATA[I've built a simple plugin that shows all the attached images when editing a post.]]></description> <content:encoded><![CDATA[<p>I&#8217;ve been building a lot of galleries using WordPress&#8217; built-in gallery feature. The biggest issue is that the gallery feature is rather hidden. You have to click the &#8220;Upload Image&#8221; icon (which itself is hard for people new to WordPress to find), then click the &#8220;Gallery&#8221; tab.</p><p>To make it easier for my clients, I&#8217;ve written a simple plugin called <a
href="http://wordpress.org/extend/plugins/gallery-metabox">Gallery Metabox</a>. This adds a metabox below the post editor that displays all the attached images. It also has a lot of filters in place for a developer to customize it specifically to the project (see the plugin page for more information).</p><p>For instance, if you&#8217;re <a
href="http://www.billerickson.net/wordpress-add-custom-fields-media-gallery/">adding a custom field to the uploader</a> to specify which images are in a rotator, you can make the metabox <a
href="https://gist.github.com/1321001">only show these images</a>.</p><p>I just built a site for a client that has a photo gallery.</p><p><img
src="http://www.billerickson.net/wp-content/uploads/2011/10/frontend-500x419.jpg" alt="" title="frontend" width="500" height="419" class="alignnone size-large wp-image-3591" /></p><p>I created a page template called &#8220;Photos&#8221; which replaces the content area with a photo rotator. But if you edit the page, the edit screen was pretty useless. There&#8217;s a big empty wysiwyg, and to get to the actual images in the gallery you have to click a small icon, then go to the Gallery tab.</p><p>I&#8217;ve added the plugin, along with some code that <a
href="https://gist.github.com/1320990">limits the metabox to this page template</a>. I&#8217;ve also added the following code to the theme&#8217;s functions.php file to remove the post editor on this page template:</p><div
id="gist-1321431" class="gist"><div
class="gist-file"><div
class="gist-data gist-syntax"><div
class="highlight"><pre><div class='line' id='LC1'><span class="cp">&lt;?php</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'><span class="sd">/**</span></div><div class='line' id='LC4'><span class="sd"> * Hide Editor</span></div><div class='line' id='LC5'><span class="sd"> * @author Bill Erickson</span></div><div class='line' id='LC6'><span class="sd"> * @link http://www.billerickson.net/code/hide-editor-on-specific-page-template/</span></div><div class='line' id='LC7'><span class="sd"> */</span></div><div class='line' id='LC8'><span class="k">function</span> <span class="nf">be_hide_editor</span><span class="p">()</span> <span class="p">{</span></div><div class='line' id='LC9'>	<span class="c1">// Get the Post ID</span></div><div class='line' id='LC10'>	<span class="k">if</span><span class="p">(</span> <span class="nb">isset</span><span class="p">(</span> <span class="nv">$_GET</span><span class="p">[</span><span class="s1">&#39;post&#39;</span><span class="p">]</span> <span class="p">)</span> <span class="p">)</span> <span class="nv">$post_id</span> <span class="o">=</span> <span class="nv">$_GET</span><span class="p">[</span><span class="s1">&#39;post&#39;</span><span class="p">];</span></div><div class='line' id='LC11'>	<span class="k">elseif</span><span class="p">(</span> <span class="nb">isset</span><span class="p">(</span> <span class="nv">$_POST</span><span class="p">[</span><span class="s1">&#39;post_ID&#39;</span><span class="p">]</span> <span class="p">)</span> <span class="p">)</span> <span class="nv">$post_id</span> <span class="o">=</span> <span class="nv">$_POST</span><span class="p">[</span><span class="s1">&#39;post_ID&#39;</span><span class="p">];</span></div><div class='line' id='LC12'>	<span class="k">if</span><span class="p">(</span> <span class="o">!</span><span class="nb">isset</span><span class="p">(</span> <span class="nv">$post_id</span> <span class="p">)</span> <span class="p">)</span> <span class="k">return</span><span class="p">;</span></div><div class='line' id='LC13'><br/></div><div class='line' id='LC14'>	<span class="c1">// Get the Page Template</span></div><div class='line' id='LC15'>	<span class="nv">$template_file</span> <span class="o">=</span> <span class="nx">get_post_meta</span><span class="p">(</span> <span class="nv">$post_id</span><span class="p">,</span> <span class="s1">&#39;_wp_page_template&#39;</span><span class="p">,</span> <span class="k">true</span> <span class="p">);</span></div><div class='line' id='LC16'><br/></div><div class='line' id='LC17'>	<span class="c1">// Exclude on these templates</span></div><div class='line' id='LC18'>	<span class="nv">$exclude_templates</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span> <span class="s1">&#39;template-branch.php&#39;</span> <span class="p">);</span></div><div class='line' id='LC19'><br/></div><div class='line' id='LC20'>	<span class="c1">// Exclude on these IDs</span></div><div class='line' id='LC21'>	<span class="nv">$exclude_ids</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span> <span class="nx">get_option</span><span class="p">(</span> <span class="s1">&#39;page_on_front&#39;</span> <span class="p">)</span> <span class="p">);</span></div><div class='line' id='LC22'><br/></div><div class='line' id='LC23'>	<span class="k">if</span><span class="p">(</span> <span class="nb">in_array</span><span class="p">(</span> <span class="nv">$template_file</span><span class="p">,</span> <span class="nv">$exclude_templates</span> <span class="p">)</span> <span class="o">||</span> <span class="nb">in_array</span><span class="p">(</span> <span class="nv">$post_id</span><span class="p">,</span> <span class="nv">$exclude_ids</span> <span class="p">)</span> <span class="p">)</span></div><div class='line' id='LC24'>		<span class="nx">wp_enqueue_style</span><span class="p">(</span> <span class="s1">&#39;hide-editor&#39;</span><span class="p">,</span> <span class="nx">get_stylesheet_directory_uri</span><span class="p">()</span> <span class="o">.</span> <span class="s1">&#39;/lib/css/hide-editor.css&#39;</span> <span class="p">);</span></div><div class='line' id='LC25'><span class="p">}</span></div><div class='line' id='LC26'><span class="nx">add_action</span><span class="p">(</span> <span class="s1">&#39;admin_enqueue_scripts&#39;</span><span class="p">,</span> <span class="s1">&#39;be_hide_editor&#39;</span> <span class="p">);</span></div></pre></div></div><div
class="gist-meta"> <a
href="https://gist.github.com/raw/1321431/09986f98c51a8a4a2f8c345b16fd561c092708a8/functions.php" style="float:right;">view raw</a> <a
href="https://gist.github.com/1321431#file_functions.php" style="float:right;margin-right:10px;color:#666">functions.php</a> <a
href="https://gist.github.com/1321431">This Gist</a> brought to you by <a
href="http://github.com">GitHub</a>.</div></div><div
class="gist-file"><div
class="gist-data gist-syntax"><div
class="highlight"><pre><div class='line' id='LC1'><span class="nf">#postdivrich</span><span class="p">{</span><span class="k">display</span><span class="o">:</span> <span class="k">none</span><span class="p">;}</span></div></pre></div></div><div
class="gist-meta"> <a
href="https://gist.github.com/raw/1321431/9c3363a51f3f2a98e20076e38c612f3291151d2f/hide-editor.css" style="float:right;">view raw</a> <a
href="https://gist.github.com/1321431#file_hide_editor.css" style="float:right;margin-right:10px;color:#666">hide-editor.css</a> <a
href="https://gist.github.com/1321431">This Gist</a> brought to you by <a
href="http://github.com">GitHub</a>.</div></div></div><p>So now this is what they see when editing that page:</p><p><img
src="http://www.billerickson.net/wp-content/uploads/2011/10/backend-500x310.jpg" alt="" title="backend" width="500" height="310" class="alignnone size-large wp-image-3590" /></p><p>This is by far a much easier user interface for this specific page template. And even if your page isn&#8217;t solely a gallery, I think this is a useful plugin for quickly seeing which images you have attached to the page or displaying in a gallery/rotator.</p> <img src="http://feeds.feedburner.com/~r/BillErickson/~4/R5ozjyWIGtc" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://www.billerickson.net/gallery-metabox/feed/</wfw:commentRss> <slash:comments>37</slash:comments> <feedburner:origLink>http://www.billerickson.net/gallery-metabox/</feedburner:origLink></item> </channel> </rss>

