<?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>Lateral Code &#187; wordpress</title>
	<atom:link href="http://www.lateralcode.com/tag/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lateralcode.com</link>
	<description>A Web Development Blog Focused on Code and Technology</description>
	<lastBuildDate>Fri, 15 Jul 2011 03:00:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Under the Hood: Custom WordPress Pagination System</title>
		<link>http://www.lateralcode.com/wordpress-pagination/</link>
		<comments>http://www.lateralcode.com/wordpress-pagination/#comments</comments>
		<pubDate>Sun, 07 Nov 2010 19:07:36 +0000</pubDate>
		<dc:creator>Karthik Viswanathan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=1641</guid>
		<description><![CDATA[If you use WordPress, you know that after a few months of blogging, there are far too many posts to display simultaneously. To reduce the loading time of your website, you could consider a pagination system, in which you display only a certain number of posts per page. By giving the user the ability to [...]]]></description>
			<content:encoded><![CDATA[<p>If you use WordPress, you know that after a few months of blogging, there are far too many posts to display simultaneously. To reduce the loading time of your website, you could consider a pagination system, in which you display only a certain number of posts per page. By giving the user the ability to navigate through pages, your posts will all be available and left intact.</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads2/wordpress-pagination/1.jpg" alt="Pagination" class="list-post-img"/></p>
<h2>Pagination? How?</h2>
<p>Unfortunately, changing the posts per page option under your WordPress reading settings does not automatically create pagination; rather, you have two options:</p>
<ol>
<li>Use WordPress&#8217; in-built functions (<code>posts_nav_link</code>, <code>previous_posts_link</code> and/or <code>next_posts_link</code>) to allow the user to navigate between pages.</li>
<li>Create your own pagination system.</li>
</ol>
<p>The main problem with the first option is that WordPress only allows the user to go to the next or previous page; there is no way to jump a set of pages without having to visit everything in-between. Consequently, the bottleneck is in the user-experience.</p>
<p>With the second option, the burden is on the developer. Even though it requires more coding, the user experience is not compromised. As a result, today&#8217;s article will focus on how to write your own <strong>custom WordPress pagination system</strong>. To view a demo, see <a href="/#pagination">Lateral Code&#8217;s pagination</a>.</p>
<p><span id="more-1641"></span></p>
<h2>Specifications</h2>
<p>Before we begin coding, let&#8217;s lay out our specifications. Our pagination system will ensure that the user can visit the first and last page. It will also provide links to pages within a certain range of the current page. We will call this the scope.</p>
<p>For example, if we have twenty pages, our scope is set to two, and the user is currently on page 5, our pagination would look like this:</p>
<pre><code>1	...	3	4	5	6	7	...	20</code></pre>
<p>Note that the ellipses (&#8230;) are just used as visual indicators of a jump in page number.</p>
<p>Since three, four, six, and seven are two of less numbers away from five, they are displayed. In like manner, if we had our scope to set to one, the pagination would be:</p>
<pre><code>1	...	4	5	6	...	20</code></pre>
<p>In this example, three and seven are removed because their range from our current page number, five, is two. This is greater than the scope of one.</p>
<p>Although this system seems to work, what if the scope is two and the current page number is one? No previous page exists to link to. As a result, we can just add more pages to the other side:</p>
<pre><code>1	2	3	4	5	...	20</code></pre>
<p>Since we missed two pages to the left of one, we added them to the right. That&#8217;s why pages four and five are visible. Using the same principal, if our current page is twenty, the pagination would be:</p>
<pre><code>1	...	16	17	18	19	20</code></pre>
<p>In this case, the pages are added to the left since they can&#8217;t be placed to the right.</p>
<h2>Code</h2>
<p>Now that our specification is complete, let&#8217;s begin coding. We will create a pagination function in functions.php which will be later used in our index.php template. The scope, or range, will have a default value of two:</p>
<pre><code>function pagination( $scope = 2 )</code></pre>
<p>Our first task is to find the number of pages and the current page:</p>
<pre><code>global $wp, $posts_per_page;

$numPages = (int) ( wp_count_posts()->publish / $posts_per_page );
if( $numPages < = 1 )
	return; // no need for pagination with one page

$queryVars = $wp->query_vars;
$curPage = isset( $queryVars[ 'paged' ] ) ? (int) $queryVars[ 'paged' ] : 1;</code></pre>
<p><code>wp_count_posts()->publish</code> represents the total number of published posts. <code>$posts_per_page</code> is the posts per page setting under the reading area of the WordPress dashboard. Dividing the former by the latter will give us the number of pages.</p>
<p>To find the current page, we can use the <code>$wp->query_vars</code> array. If the <code>paged</code> key exists, its value will be the page. Otherwise, the user is on page one.</p>
<p>After finding the statistics, we need to create the pagination. Although we know that the first and last page will be included, the middle has yet to be found:</p>
<pre><code>// page bounds
$start = $curPage - $scope;
$end = $curPage + $scope;

// if we can't satisfy the scope (add enough pages) on one side,
// add pages to the other side
if( $start < = 1 ) {
	$end += ( 1 - $start );
	$start = 2;
}
else if( $end >= $numPages ) {
	$start -= ( $end - $numPages );
	$end = $numPages - 1;
}

// limit the start and end to their extreme values
$start = max( $start, 2 );
$end = min( $end, $numPages - 1 );</code></pre>
<p><code>$start</code> and <code>$end</code> correspond the left-most and right-most page value, respectively. The <code>if</code> block is used to display more pages on one side if they cannot be added to the other, as per the last two examples of the specification. Finally, <code>$start</code> and <code>$end</code> are capped at their boundary values to ensure they are within range.</p>
<p>Now that we have the pages, we can aggregate them into an array:</p>
<pre><code>$pagesToLinkTo = array( 1 );
for( $page = $start; $page < = $end; $page++ )
	$pagesToLinkTo[] = $page;
$pagesToLinkTo[] = $numPages;</pre>
<p></code></p>
<p>Finally, we have to process the array and output list elements corresponding to each page number:
</pre>
<pre><code>$prevPage = $pagesToLinkTo[0];
foreach( $pagesToLinkTo as $page ) {
	if( $page - $prevPage > 1 ) // skipped a few pages
		echo '&lt;li&gt;...&lt;/li&gt;'; // add a spacer

	// echo the link
	echo '&lt;li&gt;&lt;a href="' . get_bloginfo( 'home' ) . '/page/' . $page . '"&gt;' . $page . '&lt;/a&gt;&lt;/li&gt;';
	$prevPage = $page;
}</code></pre>
<p>The URL of each page is http://example.com/page/number, where http://example.com is the home of the WordPress site and number is the page number. We link to this URL for each page that we output.</p>
<p>To determine whether we need to add ellipses, we compare the current page with the previous page. If the difference is greater than one, we skipped a few pages and have to add the spacer.</p>
<p>Here is the pagination function as a whole:</p>
<pre><code>function pagination( $scope = 2 ) {
   	global $wp, $posts_per_page;

	$numPages = (int) ( wp_count_posts()->publish / $posts_per_page );
	if( $numPages < = 1 )
		return; // no need for pagination

	$queryVars = $wp->query_vars;
	$curPage = isset( $queryVars[ 'paged' ] ) ? (int) $queryVars[ 'paged' ] : 1;

	// page bounds
	$start = $curPage - $scope;
	$end = $curPage + $scope;

	// if we can't satisfy the scope (add enough pages) on one side,
	// add pages to the other side
	if( $start < = 1 ) {
		$end += ( 1 - $start );
		$start = 2;
	}
	else if( $end >= $numPages ) {
		$start -= ( $end - $numPages );
		$end = $numPages - 1;
	}

	// limit the start and end to their extreme values
	$start = max( $start, 2 );
	$end = min( $end, $numPages - 1 );

	$pagesToLinkTo = array( 1 );
	for( $page = $start; $page < = $end; $page++ )
		$pagesToLinkTo[] = $page;
	$pagesToLinkTo[] = $numPages;

	$prevPage = $pagesToLinkTo[0];
	foreach( $pagesToLinkTo as $page ) {
		if( $page - $prevPage > 1 ) // skipped a few pages
		echo '&lt;li&gt;...&lt;/li&gt;'; // add a spacer

		// echo the link
		echo '&lt;li&gt;&lt;a href="' . get_bloginfo( 'home' ) . '/page/' . $page . '"&gt;' . $page . '&lt;/a&gt;&lt;/li&gt;';
		$prevPage = $page;
	}
}</code></pre>
<h2>Wrapping Up</h2>
<p>To finalize our system, we&#8217;ll have to call this function in our index.php template:</p>
<pre>&lt;ul id="pagination"&gt;
	&lt;?php pagination(); ?&gt;
&lt;/ul&gt;</pre>
<p>Well, that was easy, eh? Remember to style the pagination in accordance to your site&#8217;s design. To view a demo, see the <a href="/#pagination">bottom of Lateral Code&#8217;s home page</a>.</p>
<p>Thanks for reading!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/wordpress-pagination/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Faster Page Generation in WordPress</title>
		<link>http://www.lateralcode.com/bottleneck-page-generation/</link>
		<comments>http://www.lateralcode.com/bottleneck-page-generation/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 13:00:51 +0000</pubDate>
		<dc:creator>Patrick Lin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=1427</guid>
		<description><![CDATA[In the modern age of the web, speed is key. Gone are the days when you opened a web page, and went outside for twenty minutes before coming back to find that the web page is almost finished loading. Even if there are still people on dial-up connections, the modern world demands speed. In the [...]]]></description>
			<content:encoded><![CDATA[<p>In the modern age of the web, speed is key. Gone are the days when you opened a web page, and went outside for twenty minutes before coming back to find that the web page is almost finished loading. Even if there are still people on dial-up connections, the modern world demands speed.</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads2/256328_8783.jpg" alt="stopwatch" class="list-post-img" /></p>
<p>In the past, one of the best ways to improve speed was to reduce the size and amount of the components of the webpage. More specifics of this are outlined in an older LC article about <a href="http://www.lateralcode.com/4-ways-to-decrease-page-loading-time/">decreasing page load time</a>.</p>
<p><span id="more-1427"></span></p>
<p>But when we&#8217;ve done all we can to reduce page loading time, we can still optimize further by locating and removing/optimizing bottlenecks in the code.</p>
<p>WordPress pages are all dynamically generated, meaning that they are recreated every time someone opens a page. Dynamically generated pages have many pros and a few cons. One of these cons is that it takes time to generate the page before sending it to the user, whereas static pages are immediately sent.</p>
<p>While many dynamic pages are coded in a way that allows them to be generated very quickly, sometimes blocks of code can take more time than intended or thought. This can lead to webpages taking a very long time to generate. Fortunately, there is a way to identify these blocks by adding small bits of code into WordPress.</p>
<p>WordPress has a function called <code>timer_stop()</code>. What this function does is that it returns the amount of time, in seconds, that has passed between when the server started generating the page to the time that the function was called.</p>
<p>For example, the following code:</p>
<pre><code>&lt;!-- &lt;?php echo timer_stop(); ?&gt; seconds passed. --&gt;
</code></pre>
<p>would produce the number of seconds passed in an HTML comment.</p>
<p><code>timer_stop()</code> can be called as many times as you want in WordPress&#8217;s code, which becomes useful for doing the following:</p>
<pre><code>&lt;!-- &lt;?php echo timer_stop(); ?&gt; seconds passed. --&gt;
// Fast block of code
&lt;!-- &lt;?php echo timer_stop(); ?&gt; seconds passed. --&gt;
// Slow block of code
&lt;!-- &lt;?php echo timer_stop(); ?&gt; seconds passed. --&gt;
</code></pre>
<p>Let&#8217;s say this produced the following numbers: 0.01, 0.05, 0.32.<br />
By matching up the numbers to the positions of the code, I could then determine that the slow block of code took .27 seconds to generate, while the fast block of code took only .04 seconds.</p>
<p>By using this method, you can identify bottlenecks in your WordPress code and remove or optimize them to make page generation faster.</p>
<p>Hope this helps you make your WordPress installation faster. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/bottleneck-page-generation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>10 Great Minimalist WordPress Themes</title>
		<link>http://www.lateralcode.com/10-great-minimalist-wordpress-themes/</link>
		<comments>http://www.lateralcode.com/10-great-minimalist-wordpress-themes/#comments</comments>
		<pubDate>Sat, 09 May 2009 23:35:12 +0000</pubDate>
		<dc:creator>Karthik Viswanathan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=951</guid>
		<description><![CDATA[WordPress is one of the preferred choices for bloggers today due to its simplicity and features. Users may customize their site up to the last pixel. They can choose themes, add plugins, create polls, organize posts, and so much more. It is no wonder why WordPress is the most used blog software. In this article, [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress is one of the preferred choices for bloggers today due to its simplicity and features. Users may customize their site up to the last pixel. They can choose themes, add plugins, create polls, organize posts, and so much more. It is no wonder why WordPress is <strong>the most used blog software</strong>.</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads/wrdp-imgs/wrdp.jpg"  alt="WordPress" class="list-post-img"/></p>
<p>In this article, we will present <strong>10 great minimalist WordPress themes</strong>. Minimalistic designs not only look pleasing, but they also provide visitors with short download times. Because these themes use few distracting images, users can really focus on the content itself.</p>
<p><span id="more-951"></span></p>
<h3>1. <a href="http://wordpress.org/extend/themes/tlight">Tlight</a></h3>
<p><a href="http://wordpress.org/extend/themes/tlight"><img src="http://www.lateralcode.com/wp-content/uploads/wrdp-imgs/theme-1.jpg"  alt="Tlight WordPress Theme" class="list-post-img"/></a></p>
<h3>2. <a href="http://wordpress.org/extend/themes/omegax">OmegaX</a></h3>
<p><a href="http://wordpress.org/extend/themes/omegax"><img src="http://www.lateralcode.com/wp-content/uploads/wrdp-imgs/theme-2.jpg"  alt="OmegaX WordPress Theme" class="list-post-img"/></a></p>
<h3>3. <a href="http://wordpress.org/extend/themes/the-buffet-framework">The Buffet Framework</a></h3>
<p><a href="http://wordpress.org/extend/themes/the-buffet-framework"><img src="http://www.lateralcode.com/wp-content/uploads/wrdp-imgs/theme-3.jpg"  alt="The Buffet Framework WordPress Theme" class="list-post-img"/></a></p>
<h3>4. <a href="http://wordpress.org/extend/themes/karappo-style">Karappo Style</a></h3>
<p><a href="http://wordpress.org/extend/themes/karappo-style"><img src="http://www.lateralcode.com/wp-content/uploads/wrdp-imgs/theme-4.jpg"  alt="Karappo Style WordPress Theme" class="list-post-img"/></a></p>
<h3>5. <a href="http://wordpress.org/extend/themes/magatheme">MagaTheme</a></h3>
<p><a href="http://wordpress.org/extend/themes/magatheme"><img src="http://www.lateralcode.com/wp-content/uploads/wrdp-imgs/theme-5.jpg"  alt="MagaTheme WordPress Theme" class="list-post-img"/></a></p>
<h3>6. <a href="http://wordpress.org/extend/themes/zeeb">Zeeb</a></h3>
<p><a href="http://wordpress.org/extend/themes/zeeb"><img src="http://www.lateralcode.com/wp-content/uploads/wrdp-imgs/theme-6.jpg"  alt="Zeeb WordPress Theme" class="list-post-img"/></a></p>
<h3>7. <a href="http://wordpress.org/extend/themes/openark-blog">OpenArk Blog</a></h3>
<p><a href="http://wordpress.org/extend/themes/openark-blog"><img src="http://www.lateralcode.com/wp-content/uploads/wrdp-imgs/theme-7.jpg"  alt="OpenArk Blog WordPress Theme" class="list-post-img"/></a></p>
<h3>8. <a href="http://wordpress.org/extend/themes/love-the-orange">Love The Orange</a></h3>
<p><a href="http://wordpress.org/extend/themes/love-the-orange"><img src="http://www.lateralcode.com/wp-content/uploads/wrdp-imgs/theme-8.jpg"  alt="Love The Orange WordPress Theme" class="list-post-img"/></a></p>
<h3>9. <a href="http://wordpress.org/extend/themes/wp-framework">WP Framework</a></h3>
<p><a href="http://wordpress.org/extend/themes/wp-framework"><img src="http://www.lateralcode.com/wp-content/uploads/wrdp-imgs/theme-9.jpg"  alt="WP Framework WordPress Theme" class="list-post-img"/></a></p>
<h3>10. <a href="http://wordpress.org/extend/themes/js-o3-lite">JS O3 Lite</a></h3>
<p><a href="http://wordpress.org/extend/themes/js-o3-lite"><img src="http://www.lateralcode.com/wp-content/uploads/wrdp-imgs/theme-10.jpg"  alt="JS O3 Lite WordPress Theme" class="list-post-img"/></a></p>
<p>Do you know any other great minimalist themes? Post them as a comment below!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/10-great-minimalist-wordpress-themes/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>5 Free PSD To WordPress (or HTML) Conversion</title>
		<link>http://www.lateralcode.com/5-free-psd-to-wordpress-or-html-conversion/</link>
		<comments>http://www.lateralcode.com/5-free-psd-to-wordpress-or-html-conversion/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 01:41:51 +0000</pubDate>
		<dc:creator>Karthik Viswanathan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=896</guid>
		<description><![CDATA[Due to a few problems with our previous post, we have created a new one with a much better offer. Lateral Code is willing to provide 5 lucky people with a royalty free PSD (Photoshop Display File) to WordPress (or HTML) conversion. All you need to do is send us an e-mail at mail@lateralcode.com OR [...]]]></description>
			<content:encoded><![CDATA[<p>Due to a few problems with our previous post, we have created a new one with a much better offer. Lateral Code is willing to provide 5 lucky people with a royalty free PSD (Photoshop Display File) to WordPress (or HTML) conversion. <strong>All you need to do is send us an e-mail at <a href="mailto:mail@lateralcode.com">mail@lateralcode.com</a> OR leave a comment here so we can get in touch.</strong></p>
<p>If you do not yet have your PSD file 100% completed, that&#8217;s no problem. We are willing to wait <img src='http://www.lateralcode.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Just remember to add a comment or e-mail us as soon as possible. Return back to this post for updates on how many free conversions are left.</p>
<p><span id="more-896"></span></p>
<p><em>There are no free conversions still available.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/5-free-psd-to-wordpress-or-html-conversion/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>WordPress Categories</title>
		<link>http://www.lateralcode.com/wordpress-categories/</link>
		<comments>http://www.lateralcode.com/wordpress-categories/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 12:00:39 +0000</pubDate>
		<dc:creator>Patrick Lin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=845</guid>
		<description><![CDATA[Recently, I worked on a WordPress-powered site that required the category pages to show links to the first level of subcategories and the posts filed in the category but not the subcategories themselves. I couldn&#8217;t find any adequate documentation, so I&#8217;m putting this here for posterity: For listing the Subcategories, WordPress has a function wp_list_categories. [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I worked on a WordPress-powered site that required the category pages to show links to the first level of subcategories and the posts filed in the category but not the subcategories themselves.</p>
<p>I couldn&#8217;t find any adequate documentation, so I&#8217;m putting this here for posterity:</p>
<p><span id="more-845"></span></p>
<p>For listing the Subcategories, WordPress has a function <code><a href="http://codex.wordpress.org/Template_Tags/wp_list_categories">wp_list_categories</a></code>.</p>
<p>This code gets the first-level children of the current Category:</p>
<pre><code>
wp_list_categories(array(
		'depth' => 1,
		'child_of' => get_category($cat)->cat_ID);
	));
</code></pre>
<p>The function <code>get_posts</code> is curious: if a category is specified, it gets all posts that are filed under that category and all subcategories.</p>
<pre><code>
$posts = get_posts(array( 'cat' => get_category($cat)->cat_ID );
</code></pre>
<p>To get around this problem, a simple <code>if</code> case can be put into the loop:</p>
<pre><code>
foreach( $posts as $post ) {
	$cats = get_the_category($post->ID);
	<strong>if ( $cats[0].term_id == get_category($cat)->cat_ID ) {</strong>
		echo "&lt;a href=\";" the_permalink(); echo "\"&gt;"; the_title(); echo "&lt;/a&gt;";
	}
}
</code></pre>
<p>Of course, if you have more than one category, you can use a nested foreach:</p>
<pre><code>
foreach( $posts as $post ) {
	$in_cat = false;
	$cats = get_the_category($post->ID);
	foreach ( $cats as $cat ) {
		if ( $cat->term_id == get_category($cat)->cat_ID ) {
			$in_cat = true;
			break;
		}
	}
	if ( $in_cat ) {
		echo "&lt;a href=\";" the_permalink(); echo "\"&gt;"; the_title(); echo "&lt;/a&gt;";
	}
}
</code></pre>
<p>And that&#8217;s all there is to it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/wordpress-categories/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Adsense With WordPress</title>
		<link>http://www.lateralcode.com/google-adsense-with-wordpress/</link>
		<comments>http://www.lateralcode.com/google-adsense-with-wordpress/#comments</comments>
		<pubDate>Sun, 12 Apr 2009 23:05:18 +0000</pubDate>
		<dc:creator>Karthik Viswanathan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=819</guid>
		<description><![CDATA[Throughout my website career, I&#8217;ve found google adsense to be a very effective method to earn income. Even though it may not be the best for every site, it certainly has an ingenious method of displaying ads. Unfortunately, WordPress users may have a tough time implementing google adsense without a plugin. For those of you [...]]]></description>
			<content:encoded><![CDATA[<p><big>Throughout my website career, I&#8217;ve found <a href="http://google.com/adsense">google adsense</a> to be a very effective method to earn income. Even though it may not be the best for every site, it certainly has an ingenious method of displaying ads.</big></p>
<p>Unfortunately, WordPress users may have a tough time implementing google adsense without a plugin. For those of you who love to do it yourself, here is a simple way to place adsense on your own WordPress blog.</p>
<p><img src="http://www.lateralcode.com/wp-content/uploads/adsense.png" alt="Google Adsense" class="aligncenter clear" width="426"/></p>
<p><span id="more-819"></span></p>
<p>To accomplish this task easily, we will use <a href="http://simplehtmldom.sourceforge.net/">PHP Simple HTML DOM Parser</a>. This PHP script enables an easy way of accessing HTML tags and modifying them.</p>
<p>I suggest placing the code created in this tutorial inside the <code>functions.php</code> file of your WordPress theme. It will then be available for use in all of your other WordPress documents.</p>
<p>First, include the parser:</p>
<pre><code>include_once("simple_html_dom.php");</code></pre>
<p>Now we can move on to creating the function <code>add_ga( $content )</code> which will add Google Adsense code to the given <code>$content</code> variable and return the new string.</p>
<p>The parser requires HTML to work with. Thus, it is necessary to obtain this from the given string:</p>
<pre class="clear">$content = str_get_html( $content );</code></pre>
<p>Next, let&#8217;s find all the paragraph elements inside the given content:</p>
<pre ">$p = $content->find('p');</code></pre>
<p>For every fifth element, we can append Google Adsense code. Feel free to customize this number, as it all depends on the average length of your paragraphs!</p>
<pre><code>$paragraph_offset = 5; # Customize this for your own needs!
for( $i = 1; $i < = $paragraph_offset * 2 + 1; $i += $paragraph_offset ) {
	if ( isset( $p[$i] ) ) {
		$p[$i]->outertext = $p[$i]->outertext."&lt;div class="adsense"&gt;Your Google Adsense Code&lt;/div&gt;";
	}
}</code></pre>
<p>Remember to replace <code>Your Google Adsense Code</code> with the code you generate from your own profile. You may style the position of the ads (floated left, right, or center) using the surrounding <code>div</code> element. Furthermore, please take note on how this only displays a max of three ad units, as stated by the <a href="https://www.google.com/adsense/support/bin/answer.py?hl=en&#038;answer=48182">Google Adsense Program Policies</a>.</p>
<p>To wrap it all up, don&#8217;t forget to return the new content:</p>
<pre><code>return $content;</code></pre>
<p>And that&#8217;s it! Here is the final code:</p>
<pre><code>include_once("simple_html_dom.php");

function add_ga( $content ) {
	$content = str_get_html( $content );
	$p = $content->find('p');

	$paragraph_offset = 5; # Customize this for your own needs!
	for( $i = 1; $i < = $paragraph_offset * 2 + 1; $i += $paragraph_offset ) {
		if ( isset( $p[$i] ) ) {
			$p[$i]->outertext = $p[$i]->outertext."&lt;div class="adsense"&gt;Your Google Adsense Code&lt;/div&gt;";
		}
	}

	return $content;
}</code></pre>
<p>Place the following code in your <code>single.php</code> to use this function:</p>
<pre><code>$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]&gt;', ']]&gt;', $content);
echo add_ga( $content );</code></pre>
<p>Thank you for reading!<!--noadsense--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/google-adsense-with-wordpress/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Flipping your text in WordPress</title>
		<link>http://www.lateralcode.com/flipping-your-text-in-wordpress/</link>
		<comments>http://www.lateralcode.com/flipping-your-text-in-wordpress/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 13:15:19 +0000</pubDate>
		<dc:creator>Patrick Lin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=785</guid>
		<description><![CDATA[Youtube&#8217;s April Fool&#8217;s 2009 prank was to flip everything on their featured videos upside-down. In this post I will show you how to flip the contents of your posts in WordPress. While not nearly as cool as flipping the entire page, it&#8217;s still something you can keep ready for next year&#8217;s April Fool&#8217;s. First, let&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p><big>Youtube&#8217;s April Fool&#8217;s 2009 prank was to flip everything on their featured videos upside-down. In this post I will show you how to flip the contents of your posts in WordPress. While not nearly as cool as flipping the entire page, it&#8217;s still something you can keep ready for next year&#8217;s April Fool&#8217;s.</big></p>
<p><img src="http://www.lateralcode.com/wp-content/uploads/youtubeflip.png" alt="Youtube Flipped" title="Youtube Flipped" width="381" height="144" class="aligncenter size-full wp-image-790 noborder" style="border:0" /></p>
<p><span id="more-785"></span></p>
<p>First, let&#8217;s start with a method, <code>flip($content)</code>.</p>
<pre><code>
function flip($content) {

}
</code></pre>
<p>Before we do anything else, we need a look-up table. To save you the trouble of creating one yourself, I have created one for you based on the mappings found <a href="http://www.fileformat.info/convert/text/upside-down-map.htm">at this resource</a>.</p>
<pre><code>
$table = array ( '!' => '&amp;#x00A1;', '"' => '&amp;#x201E;', '&amp;amp;' => '&amp;#x214B;', '\'' => ',', ',' => '\'', '.' => '&amp;#x02D9;', '3' => '&amp;#x0190;', '4' => '&amp;#x152D;', '6' => '&amp;#x0039;', '7' => '&amp;#x2C62;', ';' => '&amp;#x061B;', '&amp;lt;' => '&amp;gt;', '&amp;gt;' => '&amp;lt;', '?' => '&amp;#x00BF;', 'A' => '&amp;#x2200;', 'B' => '&amp;#x10412;', 'C' => '&amp;#x2183;', 'D' => '&amp;#x25D6;', 'E' => '&amp;#x018E;', 'F' => '&amp;#x2132;', 'G' => '&amp;#x2141;', 'J' => '&amp;#x017F;', 'K' => '&amp;#x22CA;', 'L' => '&amp;#x2142;', 'M' => 'W', 'N' => '&amp;#x1D0E;', 'P' => '&amp;#x0500;', 'Q' => '&amp;#x038C;', 'R' => '&amp;#x1D1A;', 'T' => '&amp;#x22A5;', 'U' => '&amp;#x2229;', 'V' => '&amp;#x1D27;', 'W' => 'M', 'Y' => '&amp;#x2144;', '_' => '&amp;#x203E;', 'a' => '&amp;#x0250;', 'b' => 'q', 'c' => '&amp;#x0254;', 'd' => 'p', 'e' => '&amp;#x01DD;', 'f' => '&amp;#x025F;', 'g' => '&amp;#x0183;', 'h' => '&amp;#x0265;', 'i' => '&amp;#x0131;', 'j' => '&amp;#x027E;', 'k' => '&amp;#x029E;', 'l' => '&amp;#x0283;', 'm' => '&amp;#x026F;', 'n' => 'u', 'p' => 'd', 'q' => 'b', 'r' => '&amp;#x0279;', 't' => '&amp;#x0287;', 'u' => 'n', 'v' => '&amp;#x028C;', 'w' => '&amp;#x028D;', 'y' => '&amp;#x028E;', );
</code></pre>
<p>Please note that this table is not exhaustive, but it should suffice for most sites.</p>
<p>Now that we have the lookup table, we simply need to code the replacement algorithm. The simplest way, of course, would be as follows: 1) Create a new string; 2) Loop through the original string; 3) If a replacement exists, append the replacement to the new string, and if not, append the original. Here it is:</p>
<pre class="clear">
function flip($content) {
	# Lookup table goes here, omitted because of length

	$new = '';

	$len = strlen($content);
	for ( $i = 0; $i &lt; $len; $i++ ) {
		if ( $table[$content[$i]] != '' )
			$new .= $table[$content[$i]];
		else
			$new .= $content[$i];
	}
}
</code></pre>
<p>However, there are two cases we would want to check for: escaped symbols, like <code>&amp;amp;</code>, and tags, like <code>&lt;p&gt;</code>. Two sub-cases of the tag case are <code>&lt;script&gt;</code> and <code>&lt;style&gt;</code> tags. While it is fine to flip the contents of other tags, flipping the contents of these two tags can bring about undesired results.</p>
<p>To do this, we would add a simple (nested) <code>if/else</code>.</p>
<p>You can replace the existing for-loop with this one:</p>
<pre class="clear">
for ( $i = 0; $i &lt; $len; $i++ ) {
	// Tag case
	if ( $content[$i] == '&lt;' ) {
		$start = $i;
		// &lt;script&gt; subcase
		if ( substr($content, $i + 1, 6 ) == 'script' ) {
			while ( substr($content, $i, 9 ) != '&lt;/script&gt;' )
				$i++;
			$i += 8;
		}
		// &lt;style&gt; subcase
		else if ( substr($content, $i + 1, 5 ) == 'style' ) {
			while ( substr($content, $i, 8 ) != '&lt;/style&gt;' )
				$i++;
			$i += 7;
		}
		// Base subcase
		else {
			while ( $content[$i] != '&gt;' )
				$i++;
		}
		$new .= substr($content, $start, $i - $start + 1);
	}
	// Escaped char case
	else if ( $content[$i] == '&#038;' ) {
		$start = $i;
		while ( $content[$i] != ';' )
			$i++;
		$substr = substr($content, $start, $i - $start + 1);
		if ( $table[$substr] != '' )
			$new .= $table[$substr];
		else
			$new .= $substr;
	}
	// Base case
	else {
		if ( $table[$content[$i]] != '' )
			$new .= $table[$content[$i]];
		else
			$new .= $content[$i];
	}
}
</code></pre>
<p>To make the magic happen in WordPress, you&#8217;ll need to modify your theme files. Find your <code>functions.php</code> file and place the <code>flip($content)</code> function into it.</p>
<p>After the function, add this line:</p>
<pre><code>
add_filter( 'the_content', 'flip' );
</code></pre>
<p>or, if you want to keep this to April 1st only, just put a check:</p>
<pre><code>
if ( date('md') == '0401' )
	add_filter( 'the_content, 'flip' );
</code></pre>
<p>And that&#8217;s it. Have fun flipping your text.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/flipping-your-text-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>5 WordPress Installation Tips</title>
		<link>http://www.lateralcode.com/5-wordpress-installation-tips/</link>
		<comments>http://www.lateralcode.com/5-wordpress-installation-tips/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 01:19:45 +0000</pubDate>
		<dc:creator>Karthik Viswanathan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=470</guid>
		<description><![CDATA[After downloading and installing WordPress on any one of my blogs, I always follow a set pattern of events. These ensure that the website is search engine and user-friendly. To help all of those who are beginning their own blog, here are 5 WordPress Installation Tips that I always use. Set your blog title and [...]]]></description>
			<content:encoded><![CDATA[<p>After downloading and installing WordPress on any one of my blogs, I always follow a set pattern of events. These ensure that the website is search engine and user-friendly.</p>
<p>To help all of those who are beginning their own blog, here are <strong>5 WordPress Installation Tips</strong> that I always use.</p>
<ol>
<li><strong>Set your blog title and tagline</strong>
<p>This is one of the most important things to do straight off the bat. Without giving your blog a fitting title and description, users will be unable to understand your site&#8217;s content. For example, Lateral Code uses:</p>
<p>Blog Title: Lateral Code<br />
Tagline: A Blog Focused on Code and Technology</p>
<p><span id="more-470"></span></p>
<p>To set these two features, go to the Administration Panel and click on Settings in the sidebar.</p>
<p>Choose wisely!</li>
<li><strong>Find a fitting theme for your blog</strong></li>
<p>If you have a site with a design that you hate, will you really want to blog on it? A beautiful site that portray&#8217;s your site&#8217;s content in a professional manner is imperative for a successful blog. </p>
<p>Look through the <a href="http://www.wordpress.org/extend/themes/">wordpress themes database</a> for some pre-created themes or make one yourself. A fully created, original theme will have an inherent satisfaction factor. Set a new theme by uploading it to your server and going to Appearance under the Administration Panel.</p>
<p>When picking a theme, remember some basic rules:</p>
<ul>
<li>Your blog title should be clearly displayed.</li>
<li>The content should be easily readable. Do not resort to a small font. Not everyone has perfect eyesight.</li>
<li>Links should be easily distinguishable from content</li>
<li>Have some breathing space. Not many people love to view a cluttered website.</li>
<li>The latest post should be clearly visible when the theme loads.</li>
<li>Make sure the RSS subscription button can be easily accessed and found. RSS is a key way to keep visitors devoted to your site.</li>
</ul>
<p>If a theme you really love lacks one of these guidelines, don&#8217;t be discouraged. You can customize the theme to meet your needs. By changing the CSS or adding a few elements, most of the guidelines can easily be met. Don&#8217;t be afraid to ask for help. If you don&#8217;t have anyone to go to, you can ask us through our <a href="/contact/">contact page</a>.</p>
<li><strong>Customize your permalink and user settings</strong>
<p>The default WordPress permalink structure is not very friendly. Would you rather have a link that like this:</p>
<p>http://www.lateralcode.com/?p=31</p>
<p>or:</p>
<p>http://www.lateralcode.com/2009/03/5-wordpress-installation-tips</p>
<p>The latter version benefits both the user and search-engine. It is very simple for the user to remember such a link. Search engines also like this form: containing your title inside the URL is known as a &#8216;friendly&#8217; URL. You can change the permalink structure by going to the Settings &rarr; Permalinks.</p>
<p>User options are a nice way to express yourself as the author of a post and set contact info to obtain the latest updates to your blog.</p>
<p>You may set name, contact information, color scheme, and more at Users &rarr; Your Profile.</li>
<li><strong>Change the default sidebar</strong>
<p>A regular WordPress sidebar contains a blogroll with 7 links to wordpress.org. As much as you and I love this blogging system, doesn&#8217;t this seem like overkill?</p>
<p>Take time to add and remove widgets from your sidebar. Make it nice for the user and search engine. Provide links to archives, and tags. Navigation defines what posts users can find.</p>
<p>Many people love to place a calendar on their blog&#8217;s sidebar. I feel that this is completely unnecessary. Search engines will see this calendar on every single page of your site. When their spiders look through your content, much of the resulting info will be numbers. </p>
<p>Some argue that calendars are great for users. Let&#8217;s think about this logically. The user is at a computer. Most or all computers have a time and date setting build in. He/she already knows this information. Thus, I recommend staying away from this widget.</p>
<p>To customize the sidebar, navigate to Appearance &rarr; Widgets.</li>
<li><strong>Use the wide range of plugins available</strong>
<p>Before writing an article for a new blog, I add in some of the most popular <a href="http://www.wordpress.org/extend/plugins/">WordPress plugins</a>.</p>
<p>I love the All In One SEO Pack. It gives my pages nice titles and provides default descriptions. These titles are displayed on search results. Those that clearly express the content in articles and leave out the unnecessary items are perfect for search engines.</p>
<p>You may find more of my recommended plugins in my previous article: <a href="http://www.lateralcode.com/2009/01/5-great-wordpress-plugins/">5 Great WordPress Plugins</a>.</p>
<p>Please remember that most plugins are absolutely free. Do not hesitate to use them. They can really help provide everyone a better experience while viewing your site!</p>
<p>To install a plugin, upload it and visit the Plugins section of your Administration Panel.</li>
</ol>
<p>Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/5-wordpress-installation-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Free WordPress Theme: Easy View</title>
		<link>http://www.lateralcode.com/free-wordpress-theme-easy-view/</link>
		<comments>http://www.lateralcode.com/free-wordpress-theme-easy-view/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 19:12:22 +0000</pubDate>
		<dc:creator>Karthik Viswanathan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=282</guid>
		<description><![CDATA[Lateral Code would like to wish you a Happy Valentine&#8217;s Day! As a gift to you, we are releasing a free wordpress theme. It&#8217;s called Easy View. Here is a quick screenshot: You may view a demo of the theme or download the files. Enjoy!]]></description>
			<content:encoded><![CDATA[<p>Lateral Code would like to wish you a Happy Valentine&#8217;s Day! As a gift to you, we are releasing a <strong>free wordpress theme</strong>. It&#8217;s called Easy View. Here is a quick screenshot:</p>
<p><span id="more-282"></span></p>
<div id="attachment_283" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.lateralcode.com/wp-content/uploads/screenshot-big.jpg"><img src="http://www.lateralcode.com/wp-content/uploads/screenshot.png" alt="Easy View - A Free WordPress Theme" title="Easy View" width="300" height="225" class="size-full wp-image-283" /></a><p class="wp-caption-text">Easy View - A Free WordPress Theme</p></div>
<p>You may view a <a href="http://demo.lateralcode.com/easy-view/">demo of the theme</a> or <a href="http://wordpress.org/extend/themes/easy-view">download the files</a>.</p>
<p>Enjoy!<br />
<!--noadsense--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/free-wordpress-theme-easy-view/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>5 Great WordPress Plugins</title>
		<link>http://www.lateralcode.com/5-great-wordpress-plugins/</link>
		<comments>http://www.lateralcode.com/5-great-wordpress-plugins/#comments</comments>
		<pubDate>Mon, 19 Jan 2009 07:56:16 +0000</pubDate>
		<dc:creator>Karthik Viswanathan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.lateralcode.com/?p=232</guid>
		<description><![CDATA[A simple and easy way to start blogging is by using WordPress. Many themes and plugins are available to meet most every need. In this post, we will present 5 unique plugins that are great additions to any site. Google XML Sitemaps Search Engines play a large role in the amount of traffic your site [...]]]></description>
			<content:encoded><![CDATA[<p>A simple and easy way to start blogging is by using WordPress. Many themes and plugins are available to meet most every need. In this post, we will present 5 unique plugins that are great additions to any site.</p>
<ol>
<li><a href="http://wordpress.org/extend/plugins/google-sitemap-generator/">Google XML Sitemaps</a>
<p>Search Engines play a large role in the amount of traffic your site obtains. Google, one of the main search engines, enables the use of Sitemaps, or a list of links that pertain to a site. There are many benefits for using Sitemaps:</p>
<ul>
<li>Faster crawling/indexing of your site in Google</li>
<li>Ability to index pages that are never linked to internally/externally. Google can only find pages on your site by following links. If you provide a Sitemap, their crawler is able to find pages that are not linked to, but are listed in your sitemap.</li>
<li>Prioritizing content becomes possible. If some of your pages are very important to your site, it would be preferable for Google to visit/update them more often. This is where priority becomes important.</li>
</ul>
<p>Google XML Sitemaps automates this whole process for you. All you need to do is provide some information about your prioritizing needs and other options. We personally love this plugin and use it on our site.</li>
<p><span id="more-232"></span></p>
<li><a href="http://wordpress.org/extend/plugins/google-analytics-for-wordpress/">Google Analytics for WordPress</a>
<p>Getting information about visitors is always vital. Whether it is the number of visits, what pages are visited, or incoming links, webmasters should have easy access to this information.</p>
<p>Google Analytics is one of the best systems used for tracking this information. Most everything you could ask for is clearly available when using this system.</p>
<p>In order to use this plugin, you must sign up for a <a href="http://www.google.com/analytics/">Google Analytics account</a> (which is free) and then type the given account number under &#8216;Settings&#8217; of the admin panel.</li>
<li><a href="http://wordpress.org/extend/plugins/wp-pagenavi/">WP-PageNavi</a>
<p>Having too many posts on your home page can be a pain for your visitors. The large loading time and excess content can scare away potential viewers. In order to counter this problem, many webmasters use pagination.</p>
<p>Pagination is the splitting of content into multiple pages to enable fast loading times and easy access. This plugin automates the process of paginating your home page depending on given preferences.</p>
<p>In order to use this plugin, please refer to the usage information found <a href="http://lesterchan.net/wordpress/readme/wp-pagenavi.html">here</a>. You can see an example of this pagination by scrolling to the bottom of the Lateral Code homepage.</li>
<li><a href="http://wordpress.org/extend/plugins/akismet/">Akismet</a>
<p>Akismet is one of the most useful plugins you will ever find. Have you ever obtained comments on your blog that seem to be spam? Your admin panel may even be filled with these types of comments.</p>
<p>Luckily, Akismet resolves all of this with ease. It finds these spam comments and eliminates them. If you ever want to override the decision of this plugin, you can go into the &#8216;spam&#8217; area of your comments list.</p>
<p>We highly recommend using this plugin as soon as you start blogging. In order to enable Akismet, you must sign up for a <a href="http://wordpress.com/signup/">WordPress.com account</a> and enter in the API key given.</li>
<li><a href="http://wordpress.org/extend/plugins/wp-recaptcha/">WP-reCAPTCHA</a>
<p>Here is another anti-spam plugin for extra protection. WP-reCAPTCHA uses an ingenious method to produce CAPTCHA images that are hard to bypass.</p>
<p>CAPTCHA images are those distorted words that users must type in so that a site knows that a human is using it&#8217;s services. This plugin is mainly used as an anti-spam mechanism and works wonders.</p>
<p>In order to use this, you must sign up for a <a href="https://admin.recaptcha.net/accounts/signup/?next=/recaptcha/createsite/">reCAPTCHA account</a> and enter the given key in designated area under the admin panel.</li>
</ol>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lateralcode.com/5-great-wordpress-plugins/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

