﻿<?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>Travis Miller &#187; Wordpress</title>
	<atom:link href="http://www.electrumdigital.com/tag/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.electrumdigital.com</link>
	<description>Web Developer for Hire</description>
	<lastBuildDate>Thu, 22 Jul 2010 14:17:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Hiding Wordpress page links</title>
		<link>http://www.electrumdigital.com/2010/01/hiding-wordpress-page-links/</link>
		<comments>http://www.electrumdigital.com/2010/01/hiding-wordpress-page-links/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 17:23:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.electrumdigital.com/?p=306</guid>
		<description><![CDATA[When developing a custom Wordpress theme, it's necessary to provide prev/next navigation wherever there might be more than one page of posts: the main index, search results pages, and archive pages, for example.
posts_nav_link() provides the simplest way to do this—it automatically displays either or both of the links, as needed. If you need more control [...]]]></description>
			<content:encoded><![CDATA[<p>When developing a custom Wordpress theme, it's necessary to provide prev/next navigation wherever there might be more than one page of posts: the main index, search results pages, and archive pages, for example.</p>
<p><a href="http://codex.wordpress.org/Template_Tags/posts_nav_link" class="external">posts_nav_link()</a> provides the simplest way to do this—it automatically displays either or both of the links, as needed. If you need more control over the markup, <a href="http://codex.wordpress.org/Template_Tags/next_posts_link" class="external">next_posts_link()</a> and <a href="http://codex.wordpress.org/Template_Tags/previous_posts_link" class="external">previous_posts_link()</a> let you display them independently.</p>
<p><span id="more-306"></span></p>
<p>Typical usage goes something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;pager&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;pager-prev&quot;</span>&gt;&lt;?php next_posts_link<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'&amp;laquo; Older Entries'</span><span style="color: #66cc66;">&#41;</span>; ?&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;pager-next&quot;</span>&gt;&lt;?php previous_posts_link<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Newer Entries &amp;raquo;'</span><span style="color: #66cc66;">&#41;</span>; ?&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>But there's a problem here. What if a single page of results is being displayed? Wordpress will render an empty pager:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;pager&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;pager-prev&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;pager-next&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>In my latest Wordpress theme (the one you're looking at right now), this was throwing off my layout in some browsers. Despite enormous progress in browser standardization, there are still inconsistencies in the way browsers handle empty elements. Some will reserve vertical space for the element; some won't. Some will respect any margins that have been specified for the element; some won't.</p>
<p>Ideally, we simply wouldn't render a pager at all if one isn't needed.</p>
<p>Surprisingly, Wordpress doesn't offer a simple way to determine whether the current query result spans multiple pages. There's <a href="http://codex.wordpress.org/Conditional_Tags#A_Paged_Page" class="external">is_paged()</a>, but it always returns false for the first page of results, so it won't work.</p>
<p>Fortunately, <a href="http://codex.wordpress.org/Function_Reference/WP_Query" class="external">$wp_query</a> provides the information we need:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$wp_query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">found_posts</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$wp_query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'posts_per_page'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// show pager</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This seems to work well so far!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.electrumdigital.com/2010/01/hiding-wordpress-page-links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
