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

<channel>
	<title>Bill Erickson&#187; wordpress</title>
	<atom:link href="http://www.billerickson.net/tag/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.billerickson.net</link>
	<description>WordPress Consulting</description>
	<lastBuildDate>Wed, 01 Feb 2012 15:32:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Admin Pages with Genesis</title>
		<link>http://www.billerickson.net/admin-pages-with-genesis/</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>
]]></content:encoded>
			<wfw:commentRss>http://www.billerickson.net/admin-pages-with-genesis/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Manually Curated Related Posts</title>
		<link>http://www.billerickson.net/manually-curated-related-posts/</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>
]]></content:encoded>
			<wfw:commentRss>http://www.billerickson.net/manually-curated-related-posts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Column Classes</title>
		<link>http://www.billerickson.net/using-column-classes/</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>
]]></content:encoded>
			<wfw:commentRss>http://www.billerickson.net/using-column-classes/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Reusing Template Files</title>
		<link>http://www.billerickson.net/reusing-wordpress-theme-files/</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>
]]></content:encoded>
			<wfw:commentRss>http://www.billerickson.net/reusing-wordpress-theme-files/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Custom Metaboxes 0.7</title>
		<link>http://www.billerickson.net/custom-metaboxes-0-point-7/</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>
]]></content:encoded>
			<wfw:commentRss>http://www.billerickson.net/custom-metaboxes-0-point-7/feed/</wfw:commentRss>
		<slash:comments>35</slash:comments>
		</item>
		<item>
		<title>Gallery Metabox</title>
		<link>http://www.billerickson.net/gallery-metabox/</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 on Specific Template Page</span></div><div class='line' id='LC5'><span class="sd"> *</span></div><div class='line' id='LC6'><span class="sd"> */</span></div><div class='line' id='LC7'><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='LC8'>	<span class="c1">// Get the Post ID</span></div><div class='line' id='LC9'>	<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='LC10'>	<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='LC11'>	<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='LC12'><br/></div><div class='line' id='LC13'>	<span class="c1">// Get the Page Template</span></div><div class='line' id='LC14'>	<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='LC15'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC16'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span><span class="p">(</span> <span class="s1">&#39;template-photos.php&#39;</span> <span class="o">==</span> <span class="nv">$template_file</span> <span class="p">)</span></div><div class='line' id='LC17'>&nbsp;&nbsp;&nbsp;&nbsp;	<span class="k">echo</span> <span class="s1">&#39;&lt;style&gt;#postdivrich{display: none;}&lt;/style&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><div class='line' id='LC20'><span class="nx">add_action</span><span class="p">(</span> <span class="s1">&#39;admin_init&#39;</span><span class="p">,</span> <span class="s1">&#39;be_hide_editor&#39;</span> <span class="p">);</span></div><div class='line' id='LC21'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1321431/e109efa0db87bc4c9d6778f2c6c580be9e85b090/gistfile1.aw" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1321431#file_gistfile1.aw" style="float:right;margin-right:10px;color:#666">gistfile1.aw</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>
]]></content:encoded>
			<wfw:commentRss>http://www.billerickson.net/gallery-metabox/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>Core Functionality Plugin</title>
		<link>http://www.billerickson.net/core-functionality-plugin/</link>
		<comments>http://www.billerickson.net/core-functionality-plugin/#comments</comments>
		<pubDate>Fri, 28 Oct 2011 00:27:53 +0000</pubDate>
		<dc:creator>Bill Erickson</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[intermediate]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.billerickson.net/?p=3575</guid>
		<description><![CDATA[A WordPress theme should only contain that which relates to the look and feel of the site. Any core functionality belongs in a plugin.]]></description>
			<content:encoded><![CDATA[<p>As described in more detail by others (<a href="http://ottopress.com/2011/creating-a-site-specific-snippets-plugin/">Otto</a>, <a href="http://wpcandy.com/teaches/how-to-create-a-functionality-plugin">WPCandy</a>&#8230;), a WordPress theme should only contain that which relates to the look and feel of the site. Any core functionality belongs in a plugin.</p>
<p>A good rule-of-thumb is that anything a user would expect to keep after changing themes belongs in a plugin. This includes custom post types, taxonomies, metaboxes, and shortcodes.</p>
<p>For specific functionality that&#8217;s reusable and/or the client might want to selectively disable, it&#8217;s best to build as its own plugin. Many times I&#8217;ll turn these into <a href="http://wordpress.org/extend/plugins/profile/billerickson">public plugins</a>.</p>
<p>For everything else that&#8217;s project-specific but should be theme-independent, I put in a plugin called <a href="https://github.com/billerickson/Core-Functionality">Core Functionality</a>. That&#8217;s the base plugin I now use. Of course you&#8217;ll want to delete everything that&#8217;s not relevant &#8211; I have the code for post types, taxonomies, and metaboxes in there because they are used most often.</p>
<p><a href="https://github.com/billerickson/BE-Genesis-Child">My base</a> child theme <a href="https://github.com/billerickson/BE-Genesis-Child/blob/cd0dec33ff982de6b25c80f877a3f539ad801ee8/functions.php">used to</a> have all these in the theme. Over the past few months I&#8217;ve been moving them to a core functionality plugin on each project, but it&#8217;s about time I finally update the base child theme and pull the functionality out into its own plugin.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.billerickson.net/core-functionality-plugin/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Adding fields to the Media Gallery</title>
		<link>http://www.billerickson.net/wordpress-add-custom-fields-media-gallery/</link>
		<comments>http://www.billerickson.net/wordpress-add-custom-fields-media-gallery/#comments</comments>
		<pubDate>Mon, 26 Sep 2011 20:34:57 +0000</pubDate>
		<dc:creator>Bill Erickson</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[advanced]]></category>
		<category><![CDATA[media]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.billerickson.net/?p=3555</guid>
		<description><![CDATA[Here's two ways to customize the media uploader: adding a "Photo credit" section, and adding an "Include in Rotator" selection.]]></description>
			<content:encoded><![CDATA[<p>Images in WordPress can have as much metadata (data about the image) as you want. WordPress stores images as posts in the &#8220;attachment&#8221; post type, so all the standard WordPress functions you&#8217;re used to using with posts also work with images. For example, <a href="http://www.billerickson.net/wordpress-featured-image-captions/">captions are stored as excerpts</a>.</p>
<p>If you want to collect additional information on a post you typically <a href="http://www.billerickson.net/wordpress-metaboxes/">use a metabox</a>. For images, you can add your custom fields directly to the media uploader. </p>
<p>There&#8217;s two filters we&#8217;ll use: <code>attachment_fields_to_edit</code> and <code>attachment_fields_to_save</code>.</p>
<p>I&#8217;m going to provide two examples that I use often: adding a &#8220;Photo credit&#8221; section, and adding an &#8220;Include in Rotator&#8221; selection.</p>
<h3>Adding Photo Credit</h3>
<p>You&#8217;ll often need to provide attribution to the source of images you use on your website. Rather than sticking it at the top or bottom of the post, we can add that information as photo metadata and then include it in the theme.</p>
<p>I&#8217;m going to add two text fields, Photographer Name and Photographer URL.</p>
<div id="gist-1243250" 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"> * Add Photographer Name and URL fields to media uploader</span></div><div class='line' id='LC5'><span class="sd"> *</span></div><div class='line' id='LC6'><span class="sd"> * @param $form_fields array, fields to include in attachment form</span></div><div class='line' id='LC7'><span class="sd"> * @param $post object, attachment record in database</span></div><div class='line' id='LC8'><span class="sd"> * @return $form_fields, modified form fields</span></div><div class='line' id='LC9'><span class="sd"> */</span></div><div class='line' id='LC10'>&nbsp;</div><div class='line' id='LC11'><span class="k">function</span> <span class="nf">be_attachment_field_credit</span><span class="p">(</span> <span class="nv">$form_fields</span><span class="p">,</span> <span class="nv">$post</span> <span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC12'>	<span class="nv">$form_fields</span><span class="p">[</span><span class="s1">&#39;be-photographer-name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span></div><div class='line' id='LC13'>		<span class="s1">&#39;label&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;Photographer Name&#39;</span><span class="p">,</span></div><div class='line' id='LC14'>		<span class="s1">&#39;input&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;text&#39;</span><span class="p">,</span></div><div class='line' id='LC15'>		<span class="s1">&#39;value&#39;</span> <span class="o">=&gt;</span> <span class="nx">get_post_meta</span><span class="p">(</span> <span class="nv">$post</span><span class="o">-&gt;</span><span class="na">ID</span><span class="p">,</span> <span class="s1">&#39;be_photographer_name&#39;</span><span class="p">,</span> <span class="k">true</span> <span class="p">),</span></div><div class='line' id='LC16'>		<span class="s1">&#39;helps&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;If provided, photo credit will be displayed&#39;</span><span class="p">,</span></div><div class='line' id='LC17'>	<span class="p">);</span></div><div class='line' id='LC18'><br/></div><div class='line' id='LC19'>	<span class="nv">$form_fields</span><span class="p">[</span><span class="s1">&#39;be-photographer-url&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span></div><div class='line' id='LC20'>		<span class="s1">&#39;label&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;Photographer URL&#39;</span><span class="p">,</span></div><div class='line' id='LC21'>		<span class="s1">&#39;input&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;text&#39;</span><span class="p">,</span></div><div class='line' id='LC22'>		<span class="s1">&#39;value&#39;</span> <span class="o">=&gt;</span> <span class="nx">get_post_meta</span><span class="p">(</span> <span class="nv">$post</span><span class="o">-&gt;</span><span class="na">ID</span><span class="p">,</span> <span class="s1">&#39;be_photographer_url&#39;</span><span class="p">,</span> <span class="k">true</span> <span class="p">),</span></div><div class='line' id='LC23'>		<span class="s1">&#39;helps&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;If provided, photographer name will link here&#39;</span><span class="p">,</span></div><div class='line' id='LC24'>	<span class="p">);</span></div><div class='line' id='LC25'><br/></div><div class='line' id='LC26'>	<span class="k">return</span> <span class="nv">$form_fields</span><span class="p">;</span></div><div class='line' id='LC27'><span class="p">}</span></div><div class='line' id='LC28'><br/></div><div class='line' id='LC29'><span class="nx">add_filter</span><span class="p">(</span> <span class="s1">&#39;attachment_fields_to_edit&#39;</span><span class="p">,</span> <span class="s1">&#39;be_attachment_field_credit&#39;</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">2</span> <span class="p">);</span></div><div class='line' id='LC30'><br/></div><div class='line' id='LC31'><span class="sd">/**</span></div><div class='line' id='LC32'><span class="sd"> * Save values of Photographer Name and URL in media uploader</span></div><div class='line' id='LC33'><span class="sd"> *</span></div><div class='line' id='LC34'><span class="sd"> * @param $post array, the post data for database</span></div><div class='line' id='LC35'><span class="sd"> * @param $attachment array, attachment fields from $_POST form</span></div><div class='line' id='LC36'><span class="sd"> * @return $post array, modified post data</span></div><div class='line' id='LC37'><span class="sd"> */</span></div><div class='line' id='LC38'><br/></div><div class='line' id='LC39'><span class="k">function</span> <span class="nf">be_attachment_field_credit_save</span><span class="p">(</span> <span class="nv">$post</span><span class="p">,</span> <span class="nv">$attachment</span> <span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC40'>	<span class="k">if</span><span class="p">(</span> <span class="nb">isset</span><span class="p">(</span> <span class="nv">$attachment</span><span class="p">[</span><span class="s1">&#39;be-photographer-name&#39;</span><span class="p">]</span> <span class="p">)</span> <span class="p">)</span></div><div class='line' id='LC41'>		<span class="nx">update_post_meta</span><span class="p">(</span> <span class="nv">$post</span><span class="p">[</span><span class="s1">&#39;ID&#39;</span><span class="p">],</span> <span class="s1">&#39;be_photographer_name&#39;</span><span class="p">,</span> <span class="nv">$attachment</span><span class="p">[</span><span class="s1">&#39;be-photographer-name&#39;</span><span class="p">]</span> <span class="p">);</span></div><div class='line' id='LC42'><br/></div><div class='line' id='LC43'>	<span class="k">if</span><span class="p">(</span> <span class="nb">isset</span><span class="p">(</span> <span class="nv">$attachment</span><span class="p">[</span><span class="s1">&#39;be-photographer-url&#39;</span><span class="p">]</span> <span class="p">)</span> <span class="p">)</span></div><div class='line' id='LC44'>		<span class="nx">update_post_meta</span><span class="p">(</span> <span class="nv">$post</span><span class="p">[</span><span class="s1">&#39;ID&#39;</span><span class="p">],</span> <span class="s1">&#39;be_photographer_url&#39;</span><span class="p">,</span> <span class="nv">$attachment</span><span class="p">[</span><span class="s1">&#39;be-photographer-url&#39;</span><span class="p">]</span> <span class="p">);</span></div><div class='line' id='LC45'><br/></div><div class='line' id='LC46'>	<span class="k">return</span> <span class="nv">$post</span><span class="p">;</span></div><div class='line' id='LC47'><span class="p">}</span></div><div class='line' id='LC48'><br/></div><div class='line' id='LC49'><span class="nx">add_filter</span><span class="p">(</span> <span class="s1">&#39;attachment_fields_to_save&#39;</span><span class="p">,</span> <span class="s1">&#39;be_attachment_field_credit_save&#39;</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">2</span> <span class="p">);</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1243250/430e570520d39b90b608c981ab6da71becc0544c/gistfile1.aw" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1243250#file_gistfile1.aw" style="float:right;margin-right:10px;color:#666">gistfile1.aw</a>
            <a href="https://gist.github.com/1243250">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>In the first function we used a simple array to specify the field&#8217;s Label, input type, value, and help text. In the second function, we check to see if a value has been set for those fields, and if so we update the post metadata.</p>
<p>To access this information in our theme, we simply have to get the post meta for the thumbnail. Assuming we want it for the featured image, we&#8217;d do something like this: <code>get_post_meta( get_post_thumbnail_id(), 'be_photographer_name', true );</code></p>
<h3>Include in Rotator</h3>
<p>Adding text fields is rather easy. What if you want something more custom? If you use the &#8216;html&#8217; input type, you can output whatever HTML you&#8217;d like. </p>
<p>I love using the built-in Gallery feature in WordPress for managing image rotators on specific posts or pages. The problem is that all images are included in the gallery. So I add an &#8220;Include in Rotator&#8221; option when editing the image, and then I can query for all attached images that were marked &#8220;Yes&#8221;.</p>
<p>For more examples of creating html inputs for the media gallery, look in /wp-admin/includes/media.php.</p>
<div id="gist-1243276" 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"> * Add &quot;Include in Rotator&quot; option to media uploader</span></div><div class='line' id='LC6'><span class="sd"> * Limited to Home page</span></div><div class='line' id='LC7'><span class="sd"> *</span></div><div class='line' id='LC8'><span class="sd"> * @param $form_fields array, fields to include in attachment form</span></div><div class='line' id='LC9'><span class="sd"> * @param $post object, attachment record in database</span></div><div class='line' id='LC10'><span class="sd"> * @return $form_fields, modified form fields</span></div><div class='line' id='LC11'><span class="sd"> */</span></div><div class='line' id='LC12'>&nbsp;</div><div class='line' id='LC13'><span class="k">function</span> <span class="nf">be_attachment_field_rotator</span><span class="p">(</span> <span class="nv">$form_fields</span><span class="p">,</span> <span class="nv">$post</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">// Only show on the in-page media uploader</span></div><div class='line' id='LC16'>	<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='LC17'>	<span class="k">if</span><span class="p">(</span> <span class="s1">&#39;media-upload&#39;</span> <span class="o">!==</span> <span class="nv">$screen</span><span class="o">-&gt;</span><span class="na">base</span> <span class="p">)</span></div><div class='line' id='LC18'>		<span class="k">return</span> <span class="nv">$form_fields</span><span class="p">;</span></div><div class='line' id='LC19'><br/></div><div class='line' id='LC20'>	<span class="c1">// Only show on front page</span></div><div class='line' id='LC21'>	<span class="k">if</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="o">!==</span> <span class="nv">$post</span><span class="o">-&gt;</span><span class="na">post_parent</span> <span class="p">)</span></div><div class='line' id='LC22'>		<span class="k">return</span> <span class="nv">$form_fields</span><span class="p">;</span></div><div class='line' id='LC23'><br/></div><div class='line' id='LC24'>	<span class="c1">// Set up options</span></div><div class='line' id='LC25'>	<span class="nv">$options</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span> <span class="s1">&#39;1&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;Yes&#39;</span><span class="p">,</span> <span class="s1">&#39;0&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;No&#39;</span> <span class="p">);</span></div><div class='line' id='LC26'><br/></div><div class='line' id='LC27'>	<span class="c1">// Get currently selected value</span></div><div class='line' id='LC28'>	<span class="nv">$selected</span> <span class="o">=</span> <span class="nx">get_post_meta</span><span class="p">(</span> <span class="nv">$post</span><span class="o">-&gt;</span><span class="na">ID</span><span class="p">,</span> <span class="s1">&#39;be_rotator_include&#39;</span><span class="p">,</span> <span class="k">true</span> <span class="p">);</span></div><div class='line' id='LC29'><br/></div><div class='line' id='LC30'>	<span class="c1">// If no selected value, default to &#39;No&#39;</span></div><div class='line' id='LC31'>	<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">$selected</span> <span class="p">)</span> <span class="p">)</span> </div><div class='line' id='LC32'>		<span class="nv">$selected</span> <span class="o">=</span> <span class="s1">&#39;0&#39;</span><span class="p">;</span></div><div class='line' id='LC33'><br/></div><div class='line' id='LC34'>	<span class="c1">// Display each option	</span></div><div class='line' id='LC35'>	<span class="k">foreach</span> <span class="p">(</span> <span class="nv">$options</span> <span class="k">as</span> <span class="nv">$value</span> <span class="o">=&gt;</span> <span class="nv">$label</span> <span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC36'>		<span class="nv">$checked</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">;</span></div><div class='line' id='LC37'>		<span class="nv">$css_id</span> <span class="o">=</span> <span class="s1">&#39;rotator-include-option-&#39;</span> <span class="o">.</span> <span class="nv">$value</span><span class="p">;</span></div><div class='line' id='LC38'><br/></div><div class='line' id='LC39'>		<span class="k">if</span> <span class="p">(</span> <span class="nv">$selected</span> <span class="o">==</span> <span class="nv">$value</span> <span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC40'>			<span class="nv">$checked</span> <span class="o">=</span> <span class="s2">&quot; checked=&#39;checked&#39;&quot;</span><span class="p">;</span></div><div class='line' id='LC41'>		<span class="p">}</span></div><div class='line' id='LC42'><br/></div><div class='line' id='LC43'>		<span class="nv">$html</span> <span class="o">=</span> <span class="s2">&quot;&lt;div class=&#39;rotator-include-option&#39;&gt;&lt;input type=&#39;radio&#39; name=&#39;attachments[</span><span class="si">$post-&gt;ID</span><span class="s2">][be-rotator-include]&#39; id=&#39;</span><span class="si">{</span><span class="nv">$css_id</span><span class="si">}</span><span class="s2">&#39; value=&#39;</span><span class="si">{</span><span class="nv">$value</span><span class="si">}</span><span class="s2">&#39;</span><span class="si">$checked</span><span class="s2"> /&gt;&quot;</span><span class="p">;</span></div><div class='line' id='LC44'><br/></div><div class='line' id='LC45'>		<span class="nv">$html</span> <span class="o">.=</span> <span class="s2">&quot;&lt;label for=&#39;</span><span class="si">{</span><span class="nv">$css_id</span><span class="si">}</span><span class="s2">&#39;&gt;</span><span class="si">$label</span><span class="s2">&lt;/label&gt;&quot;</span><span class="p">;</span></div><div class='line' id='LC46'><br/></div><div class='line' id='LC47'>		<span class="nv">$html</span> <span class="o">.=</span> <span class="s1">&#39;&lt;/div&gt;&#39;</span><span class="p">;</span></div><div class='line' id='LC48'><br/></div><div class='line' id='LC49'>		<span class="nv">$out</span><span class="p">[]</span> <span class="o">=</span> <span class="nv">$html</span><span class="p">;</span></div><div class='line' id='LC50'>	<span class="p">}</span></div><div class='line' id='LC51'><br/></div><div class='line' id='LC52'>	<span class="c1">// Construct the form field</span></div><div class='line' id='LC53'>	<span class="nv">$form_fields</span><span class="p">[</span><span class="s1">&#39;be-include-rotator&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span></div><div class='line' id='LC54'>		<span class="s1">&#39;label&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;Include in Rotator&#39;</span><span class="p">,</span></div><div class='line' id='LC55'>		<span class="s1">&#39;input&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;html&#39;</span><span class="p">,</span></div><div class='line' id='LC56'>		<span class="s1">&#39;html&#39;</span>  <span class="o">=&gt;</span> <span class="nb">join</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">,</span> <span class="nv">$out</span><span class="p">),</span></div><div class='line' id='LC57'>	<span class="p">);</span></div><div class='line' id='LC58'><br/></div><div class='line' id='LC59'>	<span class="c1">// Return all form fields</span></div><div class='line' id='LC60'>	<span class="k">return</span> <span class="nv">$form_fields</span><span class="p">;</span></div><div class='line' id='LC61'><span class="p">}</span></div><div class='line' id='LC62'><br/></div><div class='line' id='LC63'><span class="nx">add_filter</span><span class="p">(</span> <span class="s1">&#39;attachment_fields_to_edit&#39;</span><span class="p">,</span> <span class="s1">&#39;be_attachment_field_rotator&#39;</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">2</span> <span class="p">);</span></div><div class='line' id='LC64'><br/></div><div class='line' id='LC65'><br/></div><div class='line' id='LC66'><span class="sd">/**</span></div><div class='line' id='LC67'><span class="sd"> * Save value of &quot;Include in Rotator&quot; selection in media uploader</span></div><div class='line' id='LC68'><span class="sd"> *</span></div><div class='line' id='LC69'><span class="sd"> * @param $post array, the post data for database</span></div><div class='line' id='LC70'><span class="sd"> * @param $attachment array, attachment fields from $_POST form</span></div><div class='line' id='LC71'><span class="sd"> * @return $post array, modified post data</span></div><div class='line' id='LC72'><span class="sd"> */</span></div><div class='line' id='LC73'>&nbsp;</div><div class='line' id='LC74'><span class="k">function</span> <span class="nf">be_attachment_field_rotator_save</span><span class="p">(</span> <span class="nv">$post</span><span class="p">,</span> <span class="nv">$attachment</span> <span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC75'>	<span class="k">if</span><span class="p">(</span> <span class="nb">isset</span><span class="p">(</span> <span class="nv">$attachment</span><span class="p">[</span><span class="s1">&#39;be-rotator-include&#39;</span><span class="p">]</span> <span class="p">)</span> <span class="p">)</span> </div><div class='line' id='LC76'>		<span class="nx">update_post_meta</span><span class="p">(</span> <span class="nv">$post</span><span class="p">[</span><span class="s1">&#39;ID&#39;</span><span class="p">],</span> <span class="s1">&#39;be_rotator_include&#39;</span><span class="p">,</span> <span class="nv">$attachment</span><span class="p">[</span><span class="s1">&#39;be-rotator-include&#39;</span><span class="p">]</span> <span class="p">);</span></div><div class='line' id='LC77'><br/></div><div class='line' id='LC78'>	<span class="k">return</span> <span class="nv">$post</span><span class="p">;</span></div><div class='line' id='LC79'><span class="p">}</span></div><div class='line' id='LC80'><br/></div><div class='line' id='LC81'><span class="nx">add_filter</span><span class="p">(</span> <span class="s1">&#39;attachment_fields_to_save&#39;</span><span class="p">,</span> <span class="s1">&#39;be_attachment_field_rotator_save&#39;</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">2</span> <span class="p">);</span></div><div class='line' id='LC82'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1243276/270c26ac24b2178a5eff8e769abddc5be9dc2b43/gistfile1.aw" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1243276#file_gistfile1.aw" style="float:right;margin-right:10px;color:#666">gistfile1.aw</a>
            <a href="https://gist.github.com/1243276">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>Then when I want to get all the attached images that are going in the rotator, I run something like this:</p>
<div id="gist-1243289" 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">// Get all images attached to post that have &quot;Include in Rotator&quot; marked as &quot;Yes&quot;</span></div><div class='line' id='LC4'><span class="k">global</span> <span class="nv">$post</span><span class="p">;</span></div><div class='line' id='LC5'><span class="nv">$args</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span> </div><div class='line' id='LC6'>	<span class="s1">&#39;post_parent&#39;</span> <span class="o">=&gt;</span> <span class="nv">$post</span><span class="o">-&gt;</span><span class="na">ID</span><span class="p">,</span></div><div class='line' id='LC7'>	<span class="s1">&#39;post_type&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;attachment&#39;</span><span class="p">,</span></div><div class='line' id='LC8'>	<span class="s1">&#39;post_mime_type&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;image&#39;</span><span class="p">,</span></div><div class='line' id='LC9'>	<span class="s1">&#39;post_status&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;inherit&#39;</span><span class="p">,</span></div><div class='line' id='LC10'>	<span class="s1">&#39;posts_per_page&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;-1&#39;</span><span class="p">,</span></div><div class='line' id='LC11'>	<span class="s1">&#39;order&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;ASC&#39;</span><span class="p">,</span></div><div class='line' id='LC12'>	<span class="s1">&#39;orderby&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;menu_order&#39;</span><span class="p">,</span></div><div class='line' id='LC13'>	<span class="s1">&#39;meta_query&#39;</span> <span class="o">=&gt;</span> <span class="k">array</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;key&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;be_rotator_include&#39;</span><span class="p">,</span></div><div class='line' id='LC16'>			<span class="s1">&#39;value&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;1&#39;</span></div><div class='line' id='LC17'>		<span class="p">)</span></div><div class='line' id='LC18'>	<span class="p">)</span></div><div class='line' id='LC19'><span class="p">);</span></div><div class='line' id='LC20'><br/></div><div class='line' id='LC21'><span class="nv">$images</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">WP_Query</span><span class="p">(</span> <span class="nv">$args</span> <span class="p">);</span></div><div class='line' id='LC22'><span class="k">if</span><span class="p">(</span> <span class="o">!</span><span class="nv">$images</span><span class="o">-&gt;</span><span class="na">have_posts</span><span class="p">()</span> <span class="p">)</span></div><div class='line' id='LC23'>	<span class="k">return</span><span class="p">;</span></div><div class='line' id='LC24'><span class="k">while</span><span class="p">(</span> <span class="nv">$images</span><span class="o">-&gt;</span><span class="na">have_posts</span><span class="p">()</span> <span class="p">)</span><span class="o">:</span> <span class="nv">$images</span><span class="o">-&gt;</span><span class="na">the_post</span><span class="p">();</span> <span class="k">global</span> <span class="nv">$post</span><span class="p">;</span></div><div class='line' id='LC25'><br/></div><div class='line' id='LC26'>	<span class="c1">// Echo image url</span></div><div class='line' id='LC27'>	<span class="nv">$image</span> <span class="o">=</span> <span class="nx">wp_get_attachment_image_src</span><span class="p">(</span> <span class="nv">$post</span><span class="o">-&gt;</span><span class="na">ID</span><span class="p">,</span> <span class="s1">&#39;be_featured&#39;</span> <span class="p">);</span></div><div class='line' id='LC28'>	<span class="k">echo</span> <span class="nv">$image</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">.</span> <span class="s1">&#39;&lt;br /&gt;&#39;</span><span class="p">;</span></div><div class='line' id='LC29'><br/></div><div class='line' id='LC30'><span class="k">endwhile</span><span class="p">;</span> <span class="nx">wp_reset_query</span><span class="p">();</span></div><div class='line' id='LC31'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1243289/81cdcc23b50bb6325ccf3806a8377d9ead822dd8/gistfile1.aw" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1243289#file_gistfile1.aw" style="float:right;margin-right:10px;color:#666">gistfile1.aw</a>
            <a href="https://gist.github.com/1243289">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.billerickson.net/wordpress-add-custom-fields-media-gallery/feed/</wfw:commentRss>
		<slash:comments>35</slash:comments>
		</item>
		<item>
		<title>Customizing the WordPress Query</title>
		<link>http://www.billerickson.net/customize-the-wordpress-query/</link>
		<comments>http://www.billerickson.net/customize-the-wordpress-query/#comments</comments>
		<pubDate>Fri, 23 Sep 2011 20:04:00 +0000</pubDate>
		<dc:creator>Bill Erickson</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[intermediate]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.billerickson.net/?p=3345</guid>
		<description><![CDATA[One of the most powerful features of WordPress is the WP Query. Here's how to control it.]]></description>
			<content:encoded><![CDATA[<p>One of the most powerful features of WordPress is the WP Query. It is what determines what content is displayed on what page. And often you&#8217;ll want to modify this query to your specific needs. Some examples:</p>
<ul>
<li>Don&#8217;t display posts from Category X on the homepage</li>
<li>Increase or decrease the number of posts displayed per page for a specific post type</li>
<li>Determine which posts are shown and their order based on postmeta</li>
<li>Inside your page, do a separate query for different content</li>
</ul>
<p>Andrew Nacin recently <a href="http://www.slideshare.net/andrewnacin/you-dont-know-query-wordcamp-portland-2011">gave a great talk</a> on using the query, which you can look at for some more technical information on what&#8217;s happening behind the scenes. I&#8217;m going to focus this tutorial on common uses. </p>
<p>First, what not to do. <strong>Don&#8217;t use query_posts()</strong>. As you can see from <a href="http://codex.wordpress.org/Function_Reference/query_posts">the Codex</a> page, there&#8217;s a lot of caveats to it. I really can&#8217;t think of an instance where this function is advisable.</p>
<p>There&#8217;s two approaches you should take depending on your needs.</p>
<h3>Create a new query to run inside your page or template.</h3>
<p>This is best when the content you&#8217;re displaying is being loaded in addition to your current page&#8217;s content. For instance, if you had a page about Spain and wanted to show your 5 most recent blog posts about Spain at the bottom. </p>
<p>For this you&#8217;ll use the <code>WP_Query</code> class. For more information, see my post on <a href="http://www.billerickson.net/custom-wordpress-queries/">Custom WordPress Queries</a>. Also take a look at my <a href="http://wordpress.org/extend/plugins/display-posts-shortcode/">Display Posts Shortcode</a> plugin, which might save you from having to write any code.</p>
<h3>Customize the Main Query</h3>
<p>If you want to alter which content is returned on a page, you most likely will be modifying the main query. The first three examples above all require altering the main query.</p>
<p>WordPress has a very handy hook called <code>pre_get_posts</code>. It fires once all the query settings are ready but right before the actual query takes place. This is where we&#8217;ll jump in and modify the query settings if needed. </p>
<p>All our functions are going to have a similar structure. First we&#8217;re going to make sure we&#8217;re accessing the main query. If we don&#8217;t check this first our code will affect everything from nav menus to recent comments widgets. We&#8217;ll do this by checking <code>$query->is_main_query()</code>. <em>This was added in WordPress 3.3. For earlier versions, compare <code>$query</code> to the global <code>$wp_the_query</code> variable, as shown below in the 3.2 code below.</em></p>
<p>Then we&#8217;ll check to make sure the conditions are right for our modification. If you only want it on the homepage, we&#8217;ll make sure the query is for home ( <code>$query->is_home()</code> ).</p>
<p>Finally, we&#8217;ll make our modification by using the <code>$query->set( 'key', 'value' )</code> method. To see all possible modifications you can make to the query, review the <a href="http://codex.wordpress.org/Class_Reference/WP_Query">WP_Query Codex page</a>.</p>
<h3 id="example-category">Exclude Category from Blog</h3>
<div id="gist-1238202" 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;pre_get_posts&#39;</span><span class="p">,</span> <span class="s1">&#39;be_exclude_category_from_blog&#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"> * Exclude Category from Blog</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/customize-the-wordpress-query/</span></div><div class='line' id='LC9'><span class="sd"> * @param object $query data</span></div><div class='line' id='LC10'><span class="sd"> *</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_exclude_category_from_blog</span><span class="p">(</span> <span class="nv">$query</span> <span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC13'><br/></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_home</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;cat&#39;</span><span class="p">,</span> <span class="s1">&#39;-4&#39;</span> <span class="p">);</span></div><div class='line' id='LC16'>	<span class="p">}</span></div><div class='line' id='LC17'><br/></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/1238202/5b1f4760a0e1ce084b4550688a47e3db6775c81d/gistfile1.aw" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1238202#file_gistfile1.aw" style="float:right;margin-right:10px;color:#666">gistfile1.aw</a>
            <a href="https://gist.github.com/1238202">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>We&#8217;re checking to make sure the $query is the main query, and we&#8217;re making sure we&#8217;re on the blog homepage using <a href="http://codex.wordpress.org/Function_Reference/is_home">is_home()</a>. When those are true, we set &#8216;cat&#8217; equal to &#8216;-4&#8242;, which tells WordPress to exclude this category.</p>
<p>If we were using WordPress 3.2 or earlier, the code could look like this:</p>
<div id="gist-1238189" 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;pre_get_posts&#39;</span><span class="p">,</span> <span class="s1">&#39;be_exclude_category_from_blog&#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"> * Exclude Category from Blog</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/customize-the-wordpress-query/</span></div><div class='line' id='LC9'><span class="sd"> * @param object $query data</span></div><div class='line' id='LC10'><span class="sd"> *</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_exclude_category_from_blog</span><span class="p">(</span> <span class="nv">$query</span> <span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC13'><br/></div><div class='line' id='LC14'>	<span class="k">global</span> <span class="nv">$wp_the_query</span><span class="p">;</span></div><div class='line' id='LC15'>	<span class="k">if</span><span class="p">(</span> <span class="nv">$wp_the_query</span> <span class="o">===</span> <span class="nv">$query</span> <span class="o">&amp;&amp;</span> <span class="nv">$query</span><span class="o">-&gt;</span><span class="na">is_home</span><span class="p">()</span> <span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC16'>		<span class="nv">$query</span><span class="o">-&gt;</span><span class="na">set</span><span class="p">(</span> <span class="s1">&#39;cat&#39;</span><span class="p">,</span> <span class="s1">&#39;-4&#39;</span> <span class="p">);</span></div><div class='line' id='LC17'>	<span class="p">}</span></div><div class='line' id='LC18'><br/></div><div class='line' id='LC19'><span class="p">}</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1238189/c89126cd41e7b1505e8cddd1e53c5a18e95faa1e/gistfile1.aw" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1238189#file_gistfile1.aw" style="float:right;margin-right:10px;color:#666">gistfile1.aw</a>
            <a href="https://gist.github.com/1238189">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<h3 id="example-posts-per-page">Change Posts Per Page</h3>
<p>Let&#8217;s say you have a custom post type called Event. You&#8217;re displaying events in three columns, so instead of the default 10 posts per page you want 18. If you go to Settings > Reading and change the posts per page, it will affect your blog posts as well as your events. </p>
<p>We&#8217;ll use pre_get_posts to modify the posts_per_page only when the following conditions are met:</p>
<ul>
<li>On the main query</li>
<li>Not in the admin area (we only want this affecting the frontend display)</li>
<li>On the events post type archive page</li>
</ul>
<div id="gist-1238229" 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;pre_get_posts&#39;</span><span class="p">,</span> <span class="s1">&#39;be_change_event_posts_per_page&#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"> * Change Posts Per Page for Event Archive</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/customize-the-wordpress-query/</span></div><div class='line' id='LC9'><span class="sd"> * @param object $query data</span></div><div class='line' id='LC10'><span class="sd"> *</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_change_event_posts_per_page</span><span class="p">(</span> <span class="nv">$query</span> <span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC13'><br/></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="o">!</span><span class="nx">is_admin</span><span class="p">()</span> <span class="o">&amp;&amp;</span> <span class="nx">is_post_type_archive</span><span class="p">(</span> <span class="s1">&#39;event&#39;</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="s1">&#39;18&#39;</span> <span class="p">);</span></div><div class='line' id='LC16'>	<span class="p">}</span></div><div class='line' id='LC17'><br/></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/1238229/e8770b17126fcbd31a1c0a862bab4d7e09e3393e/gistfile1.aw" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1238229#file_gistfile1.aw" style="float:right;margin-right:10px;color:#666">gistfile1.aw</a>
            <a href="https://gist.github.com/1238229">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<h3 id="example-postmeta">Modify Query based on Post Meta</h3>
<p>This example is a little more complex. We want to make some more changes to our Event post type. In addition to changing the posts_per_page, we want to only show upcoming or active events (so not ones that have ended), and sort them by start date with the soonest first.</p>
<p>I&#8217;m storing Start Date and End Date in postmeta as UNIX timestamps. With UNIX timestamps, tomorrow will always be a larger number than today, so in our query we can simply make sure the end date is greater than right now.</p>
<p>Creating the metabox and the fields within it are beyond the scope of this tutorial, but take a look at my post on <a href="http://www.billerickson.net/wordpress-metaboxes/">Custom Metaboxes</a> and this <a href="http://wordpress.org/extend/plugins/interstrategy-events-manager/">Events Plugin</a> if you you want more informaton.</p>
<p>If all the conditions are met, here&#8217;s the modifications we&#8217;ll do to the query:</p>
<ul>
<li>Do a meta query to ensure the end date is greater than today</li>
<li>Order by meta_value_num (the value of a meta field)</li>
<li>Set the &#8216;meta_key&#8217; to the start date, so that&#8217;s the meta field that posts are sorted by</li>
<li>Put it in ascending order, so events starting sooner are before the later ones</li>
</ul>
<div id="gist-1238281" 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"> * Customize Event Query using Post Meta</span></div><div class='line' id='LC5'><span class="sd"> * </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/customize-the-wordpress-query/</span></div><div class='line' id='LC8'><span class="sd"> * @param object $query data</span></div><div class='line' id='LC9'><span class="sd"> *</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_event_query</span><span class="p">(</span> <span class="nv">$query</span> <span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC12'><br/></div><div class='line' id='LC13'>	<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="o">!</span><span class="nx">is_admin</span><span class="p">()</span> <span class="o">&amp;&amp;</span> <span class="nx">is_post_type_archive</span><span class="p">(</span> <span class="s1">&#39;event&#39;</span> <span class="p">)</span> <span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC14'>		<span class="nv">$meta_query</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span></div><div class='line' id='LC15'>			<span class="k">array</span><span class="p">(</span></div><div class='line' id='LC16'>				<span class="s1">&#39;key&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;be_events_manager_end_date&#39;</span><span class="p">,</span></div><div class='line' id='LC17'>				<span class="s1">&#39;value&#39;</span> <span class="o">=&gt;</span> <span class="nb">time</span><span class="p">(),</span></div><div class='line' id='LC18'>				<span class="s1">&#39;compare&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;&gt;&#39;</span></div><div class='line' id='LC19'>			<span class="p">)</span></div><div class='line' id='LC20'>		<span class="p">);</span></div><div class='line' id='LC21'>		<span class="nv">$query</span><span class="o">-&gt;</span><span class="na">set</span><span class="p">(</span> <span class="s1">&#39;meta_query&#39;</span><span class="p">,</span> <span class="nv">$meta_query</span> <span class="p">);</span></div><div class='line' id='LC22'>		<span class="nv">$query</span><span class="o">-&gt;</span><span class="na">set</span><span class="p">(</span> <span class="s1">&#39;orderby&#39;</span><span class="p">,</span> <span class="s1">&#39;meta_value_num&#39;</span> <span class="p">);</span></div><div class='line' id='LC23'>		<span class="nv">$query</span><span class="o">-&gt;</span><span class="na">set</span><span class="p">(</span> <span class="s1">&#39;meta_key&#39;</span><span class="p">,</span> <span class="s1">&#39;be_events_manager_start_date&#39;</span> <span class="p">);</span></div><div class='line' id='LC24'>		<span class="nv">$query</span><span class="o">-&gt;</span><span class="na">set</span><span class="p">(</span> <span class="s1">&#39;order&#39;</span><span class="p">,</span> <span class="s1">&#39;ASC&#39;</span> <span class="p">);</span></div><div class='line' id='LC25'>		<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="s1">&#39;4&#39;</span> <span class="p">);</span></div><div class='line' id='LC26'>	<span class="p">}</span></div><div class='line' id='LC27'><br/></div><div class='line' id='LC28'><span class="p">}</span></div><div class='line' id='LC29'><br/></div><div class='line' id='LC30'><span class="nx">add_action</span><span class="p">(</span> <span class="s1">&#39;pre_get_posts&#39;</span><span class="p">,</span> <span class="s1">&#39;be_event_query&#39;</span> <span class="p">);</span></div><div class='line' id='LC31'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1238281/928a06df1488442f54d5f6d3ab03024fc367c65c/gistfile1.aw" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1238281#file_gistfile1.aw" style="float:right;margin-right:10px;color:#666">gistfile1.aw</a>
            <a href="https://gist.github.com/1238281">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.billerickson.net/customize-the-wordpress-query/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Building a Genesis Child Theme</title>
		<link>http://www.billerickson.net/building-a-genesis-child-theme/</link>
		<comments>http://www.billerickson.net/building-a-genesis-child-theme/#comments</comments>
		<pubDate>Mon, 19 Sep 2011 15:11:41 +0000</pubDate>
		<dc:creator>Bill Erickson</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[genesis]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.billerickson.net/?p=3274</guid>
		<description><![CDATA[A question I hear all the time is "how do I build a child theme?" This is a tutorial that walks through my process, using an actual client site as an example.]]></description>
			<content:encoded><![CDATA[<p>I recently wrote a long and detailed post on Art of Blog covering <a href="http://www.artofblog.com/building-a-genesis-child-theme/">how to build a Genesis child theme</a>.</p>
<p>It&#8217;s a question I&#8217;m asked often and I think it&#8217;s a tutorial that&#8217;s been missing. </p>
<p>Here&#8217;s my general process:</p>
<ol>
<li>Create a subdirectory on my site for this project</li>
<li>Install WordPress and Genesis</li>
<li><strong>Build all the site’s functionality into a child theme</strong></li>
<li>Use CSS to make the outputted markup match the provided design</li>
<li>Send it to the client for review</li>
</ol>
<p>The tutorial covers creating the child theme that has all the site&#8217;s functionality (step #3). Please take a look and let me know what you think in the comments over there.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.billerickson.net/building-a-genesis-child-theme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

