<?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>Digging into WordPress &#187; pages</title>
	<atom:link href="http://digwp.com/tag/pages/feed/" rel="self" type="application/rss+xml" />
	<link>http://digwp.com</link>
	<description>Take your WordPress skills to the next level.</description>
	<lastBuildDate>Thu, 09 Feb 2012 19:03:45 +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>Ajax Requested Page Return Only Content</title>
		<link>http://digwp.com/2011/02/ajax-requested-page-return-only-content/</link>
		<comments>http://digwp.com/2011/02/ajax-requested-page-return-only-content/#comments</comments>
		<pubDate>Wed, 02 Feb 2011 15:42:32 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[pages]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=3623</guid>
		<description><![CDATA[I posted a little tip on CSS-Tricks the other day about how you can load only parts of other pages on a site via Ajax, and how to do that without needing additional HTML wrapping elements to keep it clean. A common criticism of this is that the Ajax request still loads the entire page, [...]]]></description>
			<content:encoded><![CDATA[<p>I posted <a href="http://css-tricks.com/ajax-load-container-contents/">a little tip</a> on CSS-Tricks the other day about how you can load only parts of other pages on a site via Ajax, and how to do that without needing additional HTML wrapping elements to keep it clean. A common criticism of this is that the Ajax request still loads the entire page, using all that bandwidth, it&#8217;s just that it only places onto the page the part you specify via CSS selector.</p>
<p>Sometimes it&#8217;s hard to have discussions like this without looking at specific use case, but I see where they are coming from. Loading content you aren&#8217;t going to use is a waste of bandwidth. It does make progressive Ajax enhancements a lot easier though. And in fact, that&#8217;s how the ALL AJAX theme here on this site works. </p>
<p>This had me thinking though&#8230; if WordPress pages could be smart enough to know if they are being requested normally or via Ajax, they could return only the appropriate content. <span id="more-3623"></span> Turns out <a href="http://davidwalsh.name/detect-ajax">PHP can detect this</a>. So here is the basic idea:</p>
<pre><code>&lt;?php 

/* Page template, or single.php, or any other typical 
    theme file in charge of displaying a whole page */

the_post();

/* Ajax check  */
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) &amp;&amp; strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { ?&gt;

  /* This is Ajax: Return ONLY content */
  &lt;h1&gt;&lt;?php the_title(); ?&gt;&lt;/h1&gt;
  &lt;?php the_content(); ?&gt;

&lt;?php } else { ?&gt;

  /* Normal request: Return everything (header, sidebar, content, etc) */

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

  &lt;section id="main-content"&gt;
  	&lt;article class="post" id="post-&lt;?php the_ID(); ?&gt;"&gt;
  		&lt;h1&gt;&lt;?php the_title(); ?&gt;&lt;/h1&gt;
  		&lt;?php the_content(); ?&gt;
  	&lt;/article&gt;
  &lt;/section&gt;

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

&lt;?php } ?&gt;</code></pre>
<p>I haven&#8217;t tested this but it seems like a reasonable solution to me. Anyone have any experience trying something like this?</p>
<hr />
<p><small>© 2011 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2011/02/ajax-requested-page-return-only-content/">Permalink</a> | <a href="http://digwp.com/2011/02/ajax-requested-page-return-only-content/#comments">16 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2011/02/ajax-requested-page-return-only-content/&title=Ajax Requested Page Return Only Content">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/ajax/" rel="tag">ajax</a>, <a href="http://digwp.com/tag/pages/" rel="tag">pages</a>, <a href="http://digwp.com/tag/php/" rel="tag">PHP</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2011/02/ajax-requested-page-return-only-content/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Change Quick Action Button in Admin</title>
		<link>http://digwp.com/2010/03/change-quick-action-button/</link>
		<comments>http://digwp.com/2010/03/change-quick-action-button/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 15:12:20 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Admin]]></category>
		<category><![CDATA[pages]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1227</guid>
		<description><![CDATA[You know the &#8220;quick action&#8221; button in the WordPress admin? It&#8217;s a darn useful little UI touch. At the Dashboard, the default is &#8220;New Post&#8221;. But depending on where you are in the Admin, the default of it changes. In general it&#8217;s really helpful. For example when you are in the Plugins area, the default [...]]]></description>
			<content:encoded><![CDATA[<p>You know the &#8220;quick action&#8221; button in the WordPress admin? It&#8217;s a darn useful little UI touch. At the Dashboard, the default is &#8220;New Post&#8221;. But depending on where you are in the Admin, the default of it changes. In general it&#8217;s really helpful. For example when you are in the Plugins area, the default is Install Plugins:</p>
<div class="image-wrap">
<img src="http://digwp.com/wp-content/blog-images/installplugins.png" width="316" height="86" alt="" title="" /><br />
Default action being smart
</div>
<p><span id="more-1227"></span></p>
<p>A while ago I was moaning about one particular area where I didn&#8217;t find the default being so smart. When you publish a new Post, the default goes to New Post. To me it would make sense when you publish a new Page to have that button be New Page. If you have a WordPress site where you publish a lot of pages, you can feel me.</p>
<p>Reader <a href="http://ottodestruct.com">Otto</a> let me know there is a way you can change this. Here is Otto:</p>
<blockquote><p>Adding the New Page as default there is actually rather simple.</p>
<p>Look in wp-admin/includes/template.php. Down towards the bottom of the file, you&#8217;ll find the function favorite_actions().</p>
<p>In that function, it reads the wp-admin page name and sets a $default_action based on that. For example, when you&#8217;re looking at the edit-pages.php screen, the default action becomes &#8220;New Page&#8221;.</p>
<p>The Page editor screen is page.php. Note that it has no default action. To give it one, simply add a case &#8216;page.php&#8217;: in the correct place. You can add it directly before that case &#8216;edit-pages.php&#8217; if you want the default action to be the same New Page link.</p>
<p>If you want this change made to core, then I suggest making an Enhancement ticket to that effect on the WordPress trac. As always search first, somebody else might have already made that ticket request.</p></blockquote>
<p>So to fix my particular gripe, I just opened the file at the path mentioned above and found the <code>favorite_actions</code> function. It&#8217;s a pretty readable function, and adding a new bit to change the behavior is pretty easy. I just added this right above the one for <code>edit-pages.php</code></p>
<pre><code>case 'page.php':
   $default_action = array('page-new.php' =&gt; array(__('New Page'), 'edit_pages'));
   break;</code></pre>
<div class="image-wrap">
<img src="http://digwp.com/wp-content/blog-images/pagepublished.png" width="582" height="142" alt="" title="" /><br />
Fixed!
</div>
<h3>Important notes</h3>
<p>This is what you would call a &#8220;core hack&#8221;. Meaning that next time you upgrade WordPress, this code will be gone. It doesn&#8217;t mean &#8220;don&#8217;t do it&#8221; and it especially doesn&#8217;t mean &#8220;do it and don&#8217;t upgrade&#8221;. It means that you should make a note somewhere handy to yourself that when you do upgrade, you can see if it&#8217;s fixed and if it&#8217;s not, make the same alteration again. </p>
<p>Also as Otto suggested, there is an official channel for getting stuff done like this, the <a href="http://core.trac.wordpress.org/">WordPress trac</a>. I&#8217;ve never submitted anything there before, but to put my money where my mouth is I <a href="http://core.trac.wordpress.org/ticket/12430">opened a ticket</a>. </p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/03/change-quick-action-button/">Permalink</a> | <a href="http://digwp.com/2010/03/change-quick-action-button/#comments">6 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/03/change-quick-action-button/&title=Change Quick Action Button in Admin">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/admin/" rel="tag">Admin</a>, <a href="http://digwp.com/tag/pages/" rel="tag">pages</a>, <a href="http://digwp.com/tag/tricks/" rel="tag">tricks</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/03/change-quick-action-button/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Make an Infinite More-Posts Section</title>
		<link>http://digwp.com/2009/11/make-an-infinite-more-posts-section/</link>
		<comments>http://digwp.com/2009/11/make-an-infinite-more-posts-section/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 20:32:23 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[pages]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=949</guid>
		<description><![CDATA[The goal here is to make a list of posts in the sidebar that show a number of recent posts. There will be a button you can click which will replaces those links to recent posts with older posts, AJAX style. You can keep clicking the button and keep getting older and older posts. On [...]]]></description>
			<content:encoded><![CDATA[<p>The goal here is to make a list of posts in the sidebar that show a number of recent posts. There will be a button you can click which will replaces those links to recent posts with older posts, AJAX style. You can keep clicking the button and keep getting older and older posts. On this site, we currently show 5 recent posts. So this little section shows the 5 posts <em>after that</em>, then clicking the button once will show 5 more older than that, and so on. </p>
<p><span id="more-949"></span></p>
<h3>1. Create a Page Template for &#8220;Additional Posts&#8221;</h3>
<p>All this page template does is display a list of 5 posts. Totally raw and unstyled. No DOCTYPE, no footer, no nothing.</p>
<pre><code>&lt;?php
    /*
        Template Name: Additional Posts
    */
        
    $offset = htmlspecialchars(trim($_GET['offset']));
    if ($offset == '') {
        $offset = 5;
    }
   
    query_posts('showposts=5&amp;offset='.$offset); 
?&gt;

&lt;ul&gt;
    &lt;?php    
        if (have_posts()) : while (have_posts()) : the_post(); ?&gt;
            &lt;li&gt;&lt;a href='&lt;?php the_permalink(); ?&gt;'&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/li&gt;
    &lt;?php 
        endwhile; endif; 
    ?&gt;
&lt;/ul&gt;</code></pre>
<p>The only thing special about this template is that it pulls down the URL parameter &#8220;offset&#8221; and scrubs it. The query_posts function will use that offset number to return posts older than that number.</p>
<h3>2. Make sure jQuery is loaded.</h3>
<p>We&#8217;re going to use the powers of jQuery to do this, so make sure it&#8217;s loaded. Here is a simple way to get that done, make sure this is above the wp_head() function.</p>
<pre><code>&lt;?php wp_enqueue_script('jquery'); ?&gt;</code></pre>
<p>I often like to load it directly from Google. To do that, <a href="http://digwp.com/2009/06/use-google-hosted-javascript-libraries-still-the-right-way/">see here.</a></p>
<h3>3. Make a new script (or append to your already exisiting script)</h3>
<p>We&#8217;re going to write a little JavaScript here, so this is where we&#8217;ll do that. Call this AFTER the wp_head() call so it will surely run after jQuery is loaded.</p>
<pre><code>&lt;script type="text/javascript" src="&lt;?php bloginfo('template_url') ?&gt;/js/YOUR-SCRIPT.js"&gt;&lt;/script&gt;</code></pre>
<h3>4. Make a home for the list of posts</h3>
<p>On our site, we are putting this in our sidebar (sidebar.php file). </p>
<pre><code>&lt;h4&gt;More Posts&lt;/h4&gt;
&lt;div id="postContainer"&gt;... loading ...&lt;/div&gt;
&lt;p&gt;&lt;a href="#" id="another"&gt;Get more!&lt;/a&gt;&lt;/p&gt;</code></pre>
<p>The #postContainer div will be the target for loading up the new list of articles. The #another link will have a click handler tied to it which will trigger the AJAX load.</p>
<h3>5. Create a new page with your new page template</h3>
<p>Go ahead and publish a new page. It doesn&#8217;t matter what the title is, just select your new page template from the page template dropdown menu. Click the View button to make sure it loads up a list of posts OK. Note the URL of this page.</p>
<h3>6. Write JavaScript to do AJAX load</h3>
<p>We&#8217;ll put jQuery in noConflict mode here just to be super safe.</p>
<pre><code>var $j = jQuery.noConflict(); 

$j(function(){

    var offset = 5;

    $j("#postContainer").load("/additional-posts/?offset="+offset);
    $j("#another").click(function(){
        
        offset = offset+5;
    
        $j("#postContainer")
            .slideUp()
            .load("/additional-posts/?offset="+offset, function() {
                $j(this).slideDown();
            });
            
        return false;
    });

});</code></pre>
<p>In plain English:</p>
<ol>
<li>When the DOM is ready&#8230;</li>
<li>Set variable offset to 5</li>
<li>Load the contents of the URL /additional-posts/?offset=5 into the element with ID postContainer</li>
<li>When the &#8220;more&#8221; button is clicked&#8230;</li>
<li>Increment the offset variable by 5</li>
<li>Slide up the container</li>
<li>Load the URL again, with a new offset parameter</li>
<li>When done, slide the container back down</li>
</ol>
<h3>That&#8217;s it!</h3>
<p>For a demo, check out our current sidebar on <a href="http://digwp.com">Digging Into WordPress</a>. Thanks to Erik Lundmark for the idea.</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/11/make-an-infinite-more-posts-section/">Permalink</a> | <a href="http://digwp.com/2009/11/make-an-infinite-more-posts-section/#comments">9 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/11/make-an-infinite-more-posts-section/&title=Make an Infinite More-Posts Section">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/jquery/" rel="tag">jquery</a>, <a href="http://digwp.com/tag/pages/" rel="tag">pages</a>, <a href="http://digwp.com/tag/php/" rel="tag">PHP</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/11/make-an-infinite-more-posts-section/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Integrating Fading Button Navigation</title>
		<link>http://digwp.com/2009/09/integrating-fading-button-navigation/</link>
		<comments>http://digwp.com/2009/09/integrating-fading-button-navigation/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 12:32:58 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[button]]></category>
		<category><![CDATA[pages]]></category>
		<category><![CDATA[Theme]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=760</guid>
		<description><![CDATA[I was talking with Darren Hoyt recently about building a better interactive button. The goal of the button was to provide three states: regular, hover, and active (pressed). That is standard of any good button, but we were going to integrate some fading effects into it to really making the button satisfying to interact with. [...]]]></description>
			<content:encoded><![CDATA[<p>I was talking with Darren Hoyt recently about <a href="http://www.darrenhoyt.com/2009/09/20/better-button-and-nav-interactions/">building a better interactive button</a>. The goal of the button was to provide three states: regular, hover, and active (pressed). That is standard of any good button, but we were going to integrate some fading effects into it to really making the button satisfying to interact with. <a href="http://digwp.com/examples/FadingButtonNav/">Here is a demo</a>, and now we are going to show you how to integrate it into WordPress.</p>
<p><span id="more-760"></span></p>
<p>I&#8217;ve said (loudly) before, that <a href="http://digwp.com/2009/08/will-this-work-with-wordpress/">yes, this will work with WordPress</a>. I wasn&#8217;t referring to anything in particular, but just any old technique. WordPress doesn&#8217;t care what you use within it. Any ol&#8217; jQuery plugin you can find will work just fine. This time, I&#8217;m going to walk through the process. It will be specific to this technique, but this series of steps can be applied to incorporating just about any other JavaScript &#8220;thingy&#8221; you find and want to use on the web.</p>
<h3>What do we have here?</h3>
<ol>
<li><strong>Markup</strong> &#8211; we have some HTML that needs to be in place for the menu to work.</li>
<li><strong>CSS</strong> &#8211; we have some CSS in place that the markup needs</li>
<li><strong>Images</strong> &#8211; where should they go?</li>
<li><strong>jQuery dependency</strong> &#8211; this technique is going to rely on jQuery, so we need to ensure that is available</li>
<li><strong>jQuery plugin</strong> &#8211; we need a particular plugin loaded that our buttons will use</li>
<li><strong>Script</strong> &#8211; we have our own JavaScript we need to run</li>
</ol>
<p>We&#8217;d better just take this bit by bit.</p>
<h3>1. Markup</h3>
<p>Like any good semantic navigation markup, we&#8217;re shooting for markup like this:</p>
<pre><code>&lt;ul id="nav"&gt;
   &lt;li&gt;&lt;a href="#"&gt;Take a Tour&lt;/a&gt;&lt;/li&gt;
   &lt;li&gt;&lt;a href="#"&gt;Contact Us&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>
<p>That is hard-coded though, and that&#8217;s no good. With WordPress, we can have this navigation be dynamic easily, by using a function to create it instead. Assuming this navigation is going to be a list of pages, we&#8217;ll use the appropriate function:</p>
<pre><code>&lt;ul id="nav"&gt;
   &lt;?php wp_list_pages("title_li=");
&lt;/ul&gt;</code></pre>
<p>This function can be customized a ton, so check the Codex if you need to add pages, exclude pages, only go one level deep, etc. </p>
<h3>2. CSS</h3>
<p>We have some CSS that makes this menu look the way it does:</p>
<pre><code>#nav {
    list-style: none;
}

#nav li  {
    display: inline; 
}

#nav li a {
	display: block;
	padding: 10px 0;
	text-decoration: none;
	width: 200px;
	text-align: center;
	text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.8);
	font-weight: bold;
	text-transform: uppercase;
	color: #FFF;
	font: bold .8em 'Lucida Grande',Arial;
	background:	#90b339 url(../images/button-bg.png) 0 -183px repeat-x;
	-moz-border-radius: 5px;  
 	-webkit-border-radius: 5px;
 	border: 1px solid #608925;
	float: left;
	margin: 0 10px 10px 0;
}</code></pre>
<p>Now we need to consider where this CSS is needed. Is this going to be shown on every page of the site? If yes, then it should go into the main CSS that your theme <em>already uses</em>. Loading an additional CSS file just for this is probably overkill. If this is special navigation only being used on one (or very few) pages on the site, then you probably should <em>not</em> put it in the main stylesheet, but leave it seperate and load that CSS file with <a href="http://codex.wordpress.org/Conditional_Tags">conditional tags</a> in your header.</p>
<h3>3. Images</h3>
<p>We need images for our button. Obviously in WordPress we have &#8220;themes&#8221;. Navigation is definitely a part of a theme, so the images belong there. If you are blogging, and you use photos in your articles, I&#8217;d argue those images don&#8217;t belong in your theme images folder but in an images folder in the root. Those aren&#8217;t dependent on the current theme of your blog, whereas something like navigation is. </p>
<p>There is probably already an images folder in your theme folder, so put the images in there. If not, make one and put them in that. In the previous step, we referenced a background image on our anchor links. Notice the URL began with &#8220;../&#8221;. That is the relative path <em>from the CSS file to the image file</em>. If the CSS for your theme is also in a subdirectory in your theme (e.g. a &#8220;css&#8221; folder), then starting with the dot-dot-slash to back up one directory first makes sense. If your CSS is laying straight in your theme folder, just start the reference to that image with &#8220;images/&#8221;.</p>
<p>In this demo, we use a single image with a gradient. This is an efficient way to go about the technique, as all we do is shift the image up and down to accomplish the different states of the button. </p>
<p><img src="http://digwp.com/wp-content/blog-images/button-bg.png" width="50" height="400" alt="" title="" /></p>
<h3>4. jQuery Dependency</h3>
<p>All we need to do here is <a href="http://digwp.com/2009/06/including-jquery-in-wordpress-the-right-way/">make sure that jQuery is loaded</a>. Do not hard-code a new direct link to jQuery. As the article linked to above goes into, you need to let WordPress know you are using a JavaScript library so that other stuff that also intends to use it doesn&#8217;t go and load their own copy too and cause conflicts. In short: do this before your wp_head(); hook:</p>
<pre><code>&lt;?php wp_enqueue_script("jquery"); ?&gt;</code></pre>
<h3>5. jQuery Plugin</h3>
<p>Now we need to link up a plugin file that isn&#8217;t bundled with WordPress. Technically you can use <a href="http://codex.wordpress.org/Function_Reference/wp_enqueue_script">wp_enqueue_script</a> here as well, but the benefits to doing so this time are pretty minimal since no naming convention exists for every obscure plugin out there. In this case, just toss the plugin file in a &#8220;js&#8221; folder inside your theme and link it up like this:</p>
<pre><code>&lt;script type='text/javascript' src='&lt;?php bloginfo('stylesheet_directory'); ?&gt;/js/plugin.js'&gt;&lt;/script&gt;</code></pre>
<p>In our case, we&#8217;ll be using the <a href="http://plugins.jquery.com/project/backgroundPosition-Effect">background position plugin for jQuery</a> to accomplish part of the effect.</p>
<h3>6. Custom Script</h3>
<p>Now we are in a position just like we were with the CSS. Is there some script file that is already running on every page of the site? And is this menu going to be running on every page of the site? If yes, then you can drop the JavaScript into <em>that file</em>, to keep things clean and not load up another file. If there isn&#8217;t any JavaScript yet, you can link up your script just like we loaded the plugin:</p>
<pre><code>&lt;script type='text/javascript' src='&lt;?php bloginfo('stylesheet_directory'); ?&gt;/js/script.js'&gt;&lt;/script&gt;</code></pre>
<p>For our button, we are doing some pretty simple stuff. We are going to shift the background position of the gradient image a bit, to give it a subtle rollover effect. Then we&#8217;ll use the mousedown event to simulate the &#8220;active&#8221; state:</p>
<pre><code>$(function(){
	
	$("#nav li a")
		.hover(function(){
			$(this).animate({
				backgroundPosition: "0 -140px"
			}, 100)
		}, function() {
			$(this).animate({
				backgroundPosition: "0 -183px"
			}, 100)
		})
		.mousedown(function(){
			$(this).css({
				backgroundPosition: "0 -220px"
			})	
		});
	
});</code></pre>
<h3>We Made It!</h3>
<p>So that covers the theory of installing an already-existing demo into a WordPress site. In short, you need to break apart what is provided and figure out the best place to put or recreate all the parts in the smartest way. And again, check out Darren Hoyt&#8217;s blog for the origin of this <a href="http://www.darrenhoyt.com/2009/09/20/better-button-and-nav-interactions/">button technique</a>.</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/09/integrating-fading-button-navigation/">Permalink</a> | <a href="http://digwp.com/2009/09/integrating-fading-button-navigation/#comments">19 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/09/integrating-fading-button-navigation/&title=Integrating Fading Button Navigation">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/button/" rel="tag">button</a>, <a href="http://digwp.com/tag/pages/" rel="tag">pages</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/09/integrating-fading-button-navigation/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Delicious Recipes for WordPress Page Menus and Page Listings</title>
		<link>http://digwp.com/2009/07/delicious-recipes-wordpress-page-menus/</link>
		<comments>http://digwp.com/2009/07/delicious-recipes-wordpress-page-menus/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 15:01:50 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[pages]]></category>
		<category><![CDATA[tags]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://diggingintowordpress.com/?p=248</guid>
		<description><![CDATA[There are so many awesome ways to display your WordPress pages. Out of the box, WordPress provides two different template tags for displaying lists of your site&#8217;s pages. The first, most-commonly used tag is wp_list_pages(), and the second, lesser-known tag is wp_page_menu(). First we&#8217;ll explore the highly flexible wp_list_pages() template tag, and then we&#8217;ll dig [...]]]></description>
			<content:encoded><![CDATA[<p>There are so many awesome ways to display your WordPress pages. Out of the box, WordPress provides two different template tags for displaying lists of your site&rsquo;s pages. The first, most-commonly used tag is <code>wp_list_pages()</code>, and the second, lesser-known tag is <code>wp_page_menu()</code>. First we&rsquo;ll explore the highly flexible <code>wp_list_pages()</code> template tag, and then we&rsquo;ll dig into the new <code>wp_page_menu()</code> tag. Along the way, we&rsquo;ll check out some delicious recipes, tips and tricks for creating the perfect WordPress Page Menu.</p>
<p><span id="more-248"></span></p>
<h3>Digging into the wp_list_pages() template tag</h3>
<p>Almost everyone is familiar with the <code>wp_list_pages()</code> template tag, and it has served us well since WordPress version 1.5. Using this tag is easy, just add the following code to your sidebar or other choice location:</p>
<pre><code>&lt;?php wp_list_pages(); ?&gt;</code></pre>
<p>And then you can customize that in many ways using the fine menu of arguments provided at its <a href="http://codex.wordpress.org/Template_Tags/wp_list_pages" title="WordPress Codex: Template Tags/wp_list_pages">Codex Reference Page</a>. Some of the highlights include:</p>
<h3>Extreme Sorting Power</h3>
<p>You can sort your pages by the descriptor of any field in the <code>wp_post</code> table of the WordPress database. By default, you get alphabetical by page title, but there are some other great options as well. Here are some delicious copy-&amp;-paste recipes for your next project:</p>
<pre><code>&lt;?php wp_list_pages('sort_column=menu_order'); // sort by admin-specified order ?&gt;
&lt;?php wp_list_pages('sort_column=post_date'); // sort by time of page creation ?&gt;
&lt;?php wp_list_pages('sort_column=post_name'); // sort by name of the page slug ?&gt;
&lt;?php wp_list_pages('sort_column=id&amp;sort_order=asc'); // page id in ascending order ?&gt;
&lt;?php wp_list_pages('sort_column=id&amp;sort_order=desc'); // page id in descending order ?&gt;</code></pre>
<p>That first one there is a little wonky, but can prove very helpful for getting your pages to display in <em>any</em> order imaginable. To configure custom Page order to display via the <code>menu_order</code> parameter, you simply assign each Page a numerical value in its Write/Edit Admin screen. You can see a full list of available descriptors <a href="http://codex.wordpress.org/Database_Description#Table:_wp_posts" title="WordPress Codex: Description of the wp_posts Table">here</a>.</p>
<h3>Include and Exclude Anything</h3>
<p>WordPress makes it easy to include and exclude any pages to create the perfect page menu. By default, the <code>wp_list_pages</code> displays all pages, but this is easily customized with three useful arguments:</p>
<pre><code>&lt;?php wp_list_pages('exclude=1,2,3'); // exclude only these three page ids ?&gt;
&lt;?php wp_list_pages('include=1,2,3'); // include only these three page ids ?&gt;
&lt;?php wp_list_pages('exclude_tree=1,2,3'); // exclude these parent pages and all children ?&gt;</code></pre>
<p>The <code>exclude_tree</code> parameter is new as of WordPress version 2.7. It makes it super-easy to omit an entire branch of pages (the parent page and all descendant pages) from your page listings.</p>
<h3>Control the Depth of Pages</h3>
<p>There are two parameters designed to control the depth of pages displayed by the <code>wp_list_pages()</code> tag. The first is the <code>depth</code> parameter, which by default displays all subpages, regardless of depth. There is also the <code>child_of</code> parameter, which defaults to a value of <code>0</code> to display all pages and subpages. Here are some recipes to customize these default values:</p>
<pre><code>&lt;?php wp_list_pages('depth=0'); // display all pages and subpages via indented lists ?&gt;
&lt;?php wp_list_pages('depth=-1'); // display all pages and subpages without indentation ?&gt;
&lt;?php wp_list_pages('depth=1'); // display only top-level pages ?&gt;
&lt;?php wp_list_pages('depth=2'); // display all pages and first level subpages ?&gt;
&lt;?php wp_list_pages('depth=n'); // display all pages and subpages to the nth level ?&gt;

&lt;?php wp_list_pages('child_of=0'); // displays all pages and subpages ?&gt;
&lt;?php wp_list_pages('child_of=3'); // displays all subpages of page with id 3 ?&gt;</code></pre>
<p>The <code>child_of</code> parameter is a great way to display sub-menus of specific pages, for example for implementation of drop-down menus and so forth. Note that multiple instances of <code>wp_list_pages()</code> may be used on any given web page.</p>
<h3>Use with Custom Fields</h3>
<p>Here is an extremely powerful way to customize your page menus using custom-field values. Using <code>meta_key</code> and <code>meta_value</code> parameters, you can tell WordPress to display only those pages that contain specific custom-field key/value pairs. Here are some examples:</p>
<pre><code>&lt;?php wp_list_pages('meta_key=menu&amp;meta_value=page'); // display pages with menu/page custom field ?&gt;
&lt;?php wp_list_pages('meta_key=icon&amp;meta_value=true'); // display pages with icon/true custom field ?&gt;</code></pre>
<p>This parameter also gives you the flexibility of modifying page listings without having to touch any source code. Great for clients and family members who may not feel comfortable &ldquo;digging in&rdquo;&nbsp;;)</p>
<h3>Even more functionality (new in WordPress 2.7 &amp; 2.8)</h3>
<p>WordPress recently rolled out some new tricks for the <code>wp_list_pages()</code> tag. Namely, we now have the ability to wrap the anchor text of our page listings with any <acronym title="Hypertext Markup Language">HTML</acronym> or text. Other new features include the number of pages to display as well the number of pages to pass over when displaying page listings. Let&rsquo;s have a look:</p>
<pre><code>&lt;?php wp_list_pages('link_before=&lt;span&gt;&amp;link_after=&lt;/span&gt;'); // wrap anchor text with a span tag ?&gt;
&lt;?php wp_list_pages('number=7'); // display only the first seven pages ?&gt;
&lt;?php wp_list_pages('offset=7'); // skip the first seven pages ?&gt;</code></pre>
<h3>A complete copy/paste recipe for wp_list_pages()</h3>
<p>There are several more useful parameters for the <code>wp_list_pages()</code> tag, but rather than explaining each one, I will refer you to the <a href="http://codex.wordpress.org/Template_Tags/wp_list_pages" title="WordPress Codex: Template Tags/wp_list_pages">Codex</a> for all the boring details. So now, before digging into the juicy stuff, here is a &ldquo;super-delicious&rdquo; tag recipe equipped with <em>every</em> possible parameter, especially designed for easy customization:</p>
<pre><code>&lt;?php wp_list_pages('sort_column=post_title&amp;sort_order=asc&amp;exclude=0&amp;exclude_tree=0&amp;include=0&amp;depth=0&amp;child_of=0&amp;show_date=&amp;date_format=&amp;title_li=&amp;echo=1&amp;meta_key=menu&amp;meta_value=page&amp;link_before=&lt;span&gt;&amp;link_after=&lt;/span&gt;&amp;authors=0&amp;number=0&amp;offset=0'); // contains all parameters as of version 2.8 ?&gt;</code></pre>
<p>Alright, enough of the basics, let&rsquo;s explore some truly delicious page-listing recipes.</p>
<h3>List all subpages of current page</h3>
<p>Here is a way to simplify your sidebars and overall page designs. Instead of listing <em>every</em> subpage on all of your site&rsquo;s web pages, you can dynamically display subpages only when the visitor is viewing the parent page. So for example, your homepage sidebar would list all of your parent pages, and then each of the parent pages would display a list containing all of its subpages. Here&rsquo;s one way to do it, as demonstrated in the Codex:</p>
<pre><code>&lt;?php 
$children = wp_list_pages('title_li=&amp;child_of='.$post-&gt;ID.'&amp;echo=0');
if ($children) { ?&gt;
	&lt;ul&gt;
		&lt;?php echo $children; ?&gt;
	&lt;/ul&gt;
&lt;?php } ?&gt;</code></pre>
<p>Placed in your theme template file, this code will generate a list of all subpages for the current parent page. If there are no subpages, nothing will be displayed.</p>
<p>As is, this method will only display the subpages when visiting the parent page, but we can modify the code so that all subpages are displayed when visiting either the parent page or any of the subpages:</p>
<pre><code>&lt;?php
if($post-&gt;post_parent)
	$children = wp_list_pages("title_li=&amp;child_of=".$post-&gt;post_parent."&amp;echo=0");
else
	$children = wp_list_pages("title_li=&amp;child_of=".$post-&gt;ID."&amp;echo=0");
if ($children) { ?&gt;
	&lt;ul&gt;
		&lt;?php echo $children; ?&gt;
	&lt;/ul&gt;
&lt;?php } ?&gt;</code></pre>
<p>And you can do even better than that. With this next method, your page listings will be displayed as follows:</p>
<ul>
<li>When visiting main page, all top level pages are listed in the sidebar.</li>
<li>When visiting a top level page with no children, all top level pages are listed.</li>
<li>When visiting a top level page with children, just the children pages, and descendant pages, are listed.</li>
<li>When visiting a child page, just the children, and descendant pages, of that parent, are listed.</li>
</ul>
<pre><code>&lt;?php
$output = wp_list_pages('echo=0&amp;depth=1&amp;title_li=&lt;h2&gt;Top Level Pages&lt;/h2&gt;' );
if (is_page( )) {
	$page = $post-&gt;ID;
	if ($post-&gt;post_parent) {
		$page = $post-&gt;post_parent;
	}
	$children=wp_list_pages( 'echo=0&amp;child_of=' . $page . '&amp;title_li=' );
	if ($children) {
		$output = wp_list_pages ('echo=0&amp;child_of=' . $page . '&amp;title_li=&lt;h2&gt;Child Pages&lt;/h2&gt;');
	}
}
echo $output;
?&gt;</code></pre>
<p>All this is great, but it&rsquo;s also helpful to know how to style the markup generated by the <code>wp_list_pages()</code> template tag. Let&rsquo;s look at that next..</p>
<h3>Styling wp_list_pages() markup</h3>
<p>Here is the default markup generated by the <code>wp_list_pages()</code> template tag (assuming a total of five pages with the current page having an ID of &ldquo;<code>1</code>&rdquo;):</p>
<pre><code>&lt;li class="pagenav"&gt;Pages
	&lt;ul&gt;
		&lt;li class="page-item-1 page_item current_page_item"&gt;Page ID 1&lt;/li&gt;
		&lt;li class="page-item-2 page_item"&gt;Page ID 2&lt;/li&gt;
		&lt;li class="page-item-3 page_item"&gt;Page ID 3&lt;/li&gt;
		&lt;li class="page-item-4 page_item"&gt;Page ID 4&lt;/li&gt;
		&lt;li class="page-item-5 page_item"&gt;Page ID 5&lt;/li&gt;
	&lt;/ul&gt;
&lt;/li&gt;</code></pre>
<p>You can strip the outer <code>&lt;li class="pagenav"&gt;</code> and the enclosing <code>&lt;ul&gt;&lt;/ul&gt;</code> tags by including &ldquo;<code>title_li=</code>&rdquo; (empty string) as a parameter in the <code>wp_list_pages()</code> template tag. You may also keep these outer tags and customize the &ldquo;Pages&rdquo; text with whatever markup and/or text you need. Instead of an empty string, use something like &ldquo;<code>title_li=&lt;h2&gt;Pages&lt;/h2&gt;</code>&rdquo; instead. Note also that specific class attributes will be applied to both parents and ancestors of the current page (see next section).</p>
<h3>Styling page menus generated by wp_list_pages()</h3>
<p>Here is a list of the selectors available for styling your page menus:</p>
<pre><code>.pagenav {}               /* li tag containing page menu */
.page_item {}             /* inlcuded on every page item */
.page-item-n {}           /* specifies page with id of n */
.current_page_item {}     /* specifies the current page */
.current_page_parent {}   /* any parent of current page */
.current_page_ancestor {} /* any child of current page */</code></pre>
<p>Now, ready for some new stuff? Brace yourself..</p>
<h3>Digging into the wp_page_menu() template tag</h3>
<p>So what about this new <code>wp_page_menu()</code> template tag? With all of the flexibility of <code>wp_list_pages()</code>, why is it necessary? In a nutshell, <code>wp_page_menu()</code> is a simplified version of <code>wp_list_pages()</code>. In addition to accepting a few of the same parameters, this new tag brings one new trick to the table: <strong>it provides the ability to add your site&rsquo;s Home page to the list of Pages displayed</strong>. This tag was introduced in WordPress version 2.7, and, in my opinion, should have been integrated into the existing Page-listing template tag. In any case, for those looking for an easy way to include your Home page into the list of Pages, here you go:</p>
<pre><code>&lt;?php wp_page_menu(); ?&gt;</code></pre>
<p>As mentioned, most of the parameters are the same as before. Here is a list of common parameters:</p>
<ul>
<li><code>sort_column</code></li>
<li><code>include</code></li>
<li><code>echo</code></li>
<li><code>link_before</code></li>
<li><code>link_after</code></li>
</ul>
<p>And &#8212; drum roll please &#8212; here are the new parameters: <code>menu_class</code> and <code>show_home</code>! Let&rsquo;s check &lsquo;em out..</p>
<p><strong><code>menu_class</code></strong></p>
<p>This is a no-brainer. It simply specifies the <code>class</code> attribute for the surrounding <code>&lt;div&gt;</code>. Yes, the list is wrapped in a division. Any string may be used, here is an example:</p>
<pre><code>&lt;?php wp_page_menu('menu_class=pages'); // wrap list in div with class="pages" ?&gt;</code></pre>
<p><strong><code>show_home</code></strong></p>
<p>Ahh, the long-awaited &ldquo;include-the-home-page&rdquo; functionality. Now, instead of hacking your client&rsquo;s <code>functions.php</code> file to include the Home Page in the main menu, you can simply do this instead:</p>
<pre><code>&lt;?php wp_page_menu('show_home=1'); // include the home page in the list ?&gt;
&lt;?php wp_page_menu('show_home=0'); // exclude the home page in the list ?&gt;</code></pre>
<p>By default, this parameter returns false and no Home Page is displayed. When set to <code>true</code>, the Home Page will be displayed as the first item in the page list. The <acronym title="Uniform Resource Locator">URL</acronym> for the Home Page is taken from the value for your site&rsquo;s &ldquo;Blog address&rdquo;, as specified in the WordPress Admin under <code>Settings</code> &gt; <code>General</code>. </p>
<p>When the Home Page is displayed, the default anchor text is simply &ldquo;Home&rdquo;, but you can customize that to whatever you want by specifying such for the parameter value:</p>
<pre><code>&lt;?php wp_page_menu('show_home=Digging%20into%20WordPress'); // include the home page ?&gt;
&lt;?php wp_page_menu(array('show_home'=&gt;'Digging into WordPress', 'sort_column'=&gt;'menu_order')); // include the home page ?&gt;</code></pre>
<p>For more information on this new tag, check it out at the <a href="http://codex.wordpress.org/Template_Tags/wp_page_menu" title="WordPress Codex: Template Tags/wp_page_menu">WordPress Codex</a></p>
<h3>Take-home message</h3>
<p>WordPress provides two different ways to list your pages: <code>wp_page_menu()</code> and <code>wp_list_pages()</code>. The <code>wp_list_pages()</code> tag is powerful, flexible and fully functional. So, unless you need to include your Home Page, your best bet is always <code>wp_list_pages()</code>. For page menus that include the Home Page, you will need to use <code>wp_page_menu()</code> instead. Beyond listing your Home Page, the <code>wp_page_menu()</code> can do a <em>few</em> things, but nothing that <code>wp_list_pages()</code> can&rsquo;t already handle. </p>
<p>My question for the day is: Why wasn&rsquo;t the home-page functionality integrated into the existing tag? Why complicate things with an otherwise redundant tag? Share your thoughts!</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/07/delicious-recipes-wordpress-page-menus/">Permalink</a> | <a href="http://digwp.com/2009/07/delicious-recipes-wordpress-page-menus/#comments">59 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/07/delicious-recipes-wordpress-page-menus/&title=Delicious Recipes for WordPress Page Menus and Page Listings">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/pages/" rel="tag">pages</a>, <a href="http://digwp.com/tag/tags/" rel="tag">tags</a>, <a href="http://digwp.com/tag/template/" rel="tag">template</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/07/delicious-recipes-wordpress-page-menus/feed/</wfw:commentRss>
		<slash:comments>59</slash:comments>
		</item>
	</channel>
</rss>

