<?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>Blogsessive &#187; tutorial</title>
	<atom:link href="http://blogsessive.com/tag/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogsessive.com</link>
	<description>Visit Blogsessive for daily WordPress blogging tips.</description>
	<lastBuildDate>Fri, 16 Dec 2011 08:05:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>WordPress How To: Latest Posts by Category Archive</title>
		<link>http://blogsessive.com/blogging-tools/latest-posts-by-category-archive/</link>
		<comments>http://blogsessive.com/blogging-tools/latest-posts-by-category-archive/#comments</comments>
		<pubDate>Sat, 14 Feb 2009 02:47:30 +0000</pubDate>
		<dc:creator>Alex, Blogsessive</dc:creator>
				<category><![CDATA[Blog Design]]></category>
		<category><![CDATA[Blogging Tools]]></category>
		<category><![CDATA[Coding Tips]]></category>
		<category><![CDATA[archive]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://blogsessive.com/?p=1047</guid>
		<description><![CDATA[Looking for really affordable premium WordPress themes?One technique that is most common with WordPress magazine or news style themes is the display of an archive of the latest posts by category, as simple titles or with post excerpts. This is useful for the previously mentioned theme styles, but not only. It can be used to [...]]]></description>
			<content:encoded><![CDATA[<p>Blogsessive recommends WP WebHost for <a href="http://blogsessive.com/go-wpwebhost/" title="WordPress Hosting" target="_blank"><strong>quality WordPress blog hosting</strong></a>!</p><p><a title="WordPress - Latest posts by category" href="http://blogsessive.com/wp-content/uploads/2009/02/latest-posts-by-category-archive.gif" target="_blank"><img style="float: right; margin-left: 20px; border: 1px solid #ebe6dc; padding: 5px;" title="Latest posts by category archive" src="http://blogsessive.com/wp-content/uploads/2009/02/latest-posts-by-category-archive-150x150.gif" alt="WordPress - Latest posts by category" width="150" height="150" /></a>One technique that is most common with WordPress magazine or news style themes is the display of an archive of the latest posts by category, as simple titles or with post excerpts. This is useful for the previously mentioned theme styles, but not only. It can be used to set up custom blog homepages, 404 pages, landing pages or even a special archive page.</p>
<p>This tutorial will help you build a &#8216;<strong>Latest Posts by Category Archive</strong>&#8216; in a very easy way. The widths in the CSS styling presented below have been calculated based on the default WordPress theme, assuming that is the most common theme available to anyone.</p>
<p>If you are looking for a plugin to generate such an archive, please check out: <a href="http://blogsessive.com/blogging-tools/wp-plugin-latest-posts-by-category-archive/" target="_blank" title="WordPress Plugin: Latest Posts by Category Archive"><strong>WP Plugin: Latest Posts by Category Archive</strong></a>.</p>
<h3>Setting up the page template</h3>
<p>Open up you favorite code editor and create a blank document. Save the document as &#8216;category-archive.php&#8217; (or any other name you&#8217;d prefer) in the default WordPress theme directory (wp-content/themes/default).</p>
<p>The first step is to asign our new template a name and a page-like structure, so based on the default theme&#8217;s page template, the code you should paste in your new document is:</p>
<pre class="brush: php">
&lt;?php
/*
Template Name: Category Archive
*/
?&gt;

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

&lt;div id=&quot;content&quot; class=&quot;narrowcolumn&quot;&gt;

	&lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt;
	&lt;div class=&quot;post&quot; id=&quot;post-&lt;?php the_ID(); ?&gt;&quot;&gt;
	&lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt;
		&lt;div class=&quot;entry&quot;&gt;
			&lt;?php the_content(&#039;&lt;p class=&quot;serif&quot;&gt;Read the rest of this page &amp;raquo;&lt;/p&gt;&#039;); ?&gt;

			&lt;?php wp_link_pages(array(&#039;before&#039; =&gt; &#039;&lt;p&gt;&lt;strong&gt;Pages:&lt;/strong&gt; &#039;, &#039;after&#039; =&gt; &#039;&lt;/p&gt;&#039;, &#039;next_or_number&#039; =&gt; &#039;number&#039;)); ?&gt;

		&lt;/div&gt;
	&lt;/div&gt;
	&lt;?php endwhile; endif; ?&gt;

	&lt;!-- Category Archive Start --&gt;
	&lt;!-- Category Archive End --&gt;

&lt;/div&gt;

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

&lt;?php get_footer(); ?&gt;
</pre>
<p>The template above will make sure to display the page name you set up, and also, any additional content you might want to add <em>before the archive</em>, from you WordPress page editor. We will be adding our &#8216;latest posts by category&#8217; code between the &#8216;Category Archive Start&#8217; and &#8216;Category Archive End&#8217; comments.<span id="more-1047"></span></p>
<h3>Adding the archive&#8217;s PHP code</h3>
<p>Simply put, the code below will cycle through the first-level categories of your blog (parent categories), check for the ones that are not empty and if this condition is met, return an unordered list of the latest 5 post from each category. Empty categories will not be displayed.</p>
<pre class="brush: php">
&lt;?php
/*
Template Name: Category Archive
*/
?&gt;

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

&lt;div id=&quot;content&quot; class=&quot;narrowcolumn&quot;&gt;

	&lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt;
	&lt;div class=&quot;post&quot; id=&quot;post-&lt;?php the_ID(); ?&gt;&quot;&gt;
	&lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt;
		&lt;div class=&quot;entry&quot;&gt;
			&lt;?php the_content(&#039;&lt;p class=&quot;serif&quot;&gt;Read the rest of this page &amp;raquo;&lt;/p&gt;&#039;); ?&gt;

			&lt;?php wp_link_pages(array(&#039;before&#039; =&gt; &#039;&lt;p&gt;&lt;strong&gt;Pages:&lt;/strong&gt; &#039;, &#039;after&#039; =&gt; &#039;&lt;/p&gt;&#039;, &#039;next_or_number&#039; =&gt; &#039;number&#039;)); ?&gt;

		&lt;/div&gt;
	&lt;/div&gt;
	&lt;?php endwhile; endif; ?&gt;

	&lt;!-- Category Archive Start --&gt;
	&lt;ul class=&quot;catArchive&quot;&gt;
	&lt;?php
	$catQuery = $wpdb-&gt;get_results(&quot;SELECT * FROM $wpdb-&gt;terms AS wterms INNER JOIN $wpdb-&gt;term_taxonomy AS wtaxonomy ON ( wterms.term_id = wtaxonomy.term_id ) WHERE wtaxonomy.taxonomy = &#039;category&#039; AND wtaxonomy.parent = 0 AND wtaxonomy.count &gt; 0&quot;);

	$catCounter = 0;

	foreach ($catQuery as $category) {

		$catCounter++;

		$catStyle = &#039;&#039;;
		if (is_int($catCounter / 2)) $catStyle = &#039; class=&quot;catAlt&quot;&#039;;

		$catLink = get_category_link($category-&gt;term_id);

		echo &#039;&lt;li&#039;.$catStyle.&#039;&gt;&lt;h3&gt;&lt;a href=&quot;&#039;.$catLink.&#039;&quot; title=&quot;&#039;.$category-&gt;name.&#039;&quot;&gt;&#039;.$category-&gt;name.&#039;&lt;/a&gt;&lt;/h3&gt;&#039;;
			echo &#039;&lt;ul&gt;&#039;;

			query_posts(&#039;cat=&#039;.$category-&gt;term_id.&#039;&amp;showposts=5&#039;);?&gt;

			&lt;?php while (have_posts()) : the_post(); ?&gt;
				&lt;li&gt;&lt;a href=&quot;&lt;?php the_permalink() ?&gt;&quot; rel=&quot;bookmark&quot; title=&quot;&lt;?php the_title(); ?&gt;&quot;&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/li&gt;
			&lt;?php endwhile; ?&gt;

				&lt;li&gt;&lt;a href=&quot;&lt;?php echo $catLink; ?&gt;&quot; title=&quot;&lt;?php echo $category-&gt;name; ?&gt;&quot;&gt;More &lt;strong&gt;&lt;?php echo $category-&gt;name; ?&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
			&lt;/ul&gt;
		&lt;/li&gt;
		&lt;?php }	?&gt;
	&lt;/ul&gt;
	&lt;!-- Category Archive End --&gt;

&lt;/div&gt;

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

&lt;?php get_footer(); ?&gt;
</pre>
<p>You should now save your file, because <strong>we&#8217;re done editing it</strong>. As you can see, the archive code has been added between the &#8216;Start&#8217; and &#8216;End&#8217; comments. Now let&#8217;s go through the code and dissect it.</p>
<h3>The PHP code explained</h3>
<p>The first thing we do is to set up a database query to cycle through the non-empty parent categories:</p>
<pre class="brush: php">
$catQuery = $wpdb-&gt;get_results(&quot;SELECT * FROM $wpdb-&gt;terms AS wterms INNER JOIN $wpdb-&gt;term_taxonomy AS wtaxonomy ON ( wterms.term_id = wtaxonomy.term_id ) WHERE wtaxonomy.taxonomy = &#039;category&#039; AND wtaxonomy.parent = 0 AND wtaxonomy.count &gt; 0&quot;);
</pre>
<p>You can further tweak this query to exclude categories or specify categories to be listed based on their ID, with the use of the MySQL comparison functions NOT IN or IN.</p>
<p>Let&#8217;s say that you&#8217;d like the archive to exclude the categories with IDs 2, 5 and 6. Your query would become:</p>
<pre class="brush: php">
$catQuery = $wpdb-&gt;get_results(&quot;SELECT * FROM $wpdb-&gt;terms AS wterms INNER JOIN $wpdb-&gt;term_taxonomy AS wtaxonomy ON ( wterms.term_id = wtaxonomy.term_id ) WHERE wtaxonomy.taxonomy = &#039;category&#039; AND wtaxonomy.parent = 0 AND wtaxonomy.count &gt; 0 AND wterms.term_id NOT IN (2,5,6)&quot;);
</pre>
<p>Similarly, if you want to display only the categories with IDs 2,5 and 6, you&#8217;d have:</p>
<pre class="brush: php">
$catQuery = $wpdb-&gt;get_results(&quot;SELECT * FROM $wpdb-&gt;terms AS wterms INNER JOIN $wpdb-&gt;term_taxonomy AS wtaxonomy ON ( wterms.term_id = wtaxonomy.term_id ) WHERE wtaxonomy.taxonomy = &#039;category&#039; AND wtaxonomy.parent = 0 AND wtaxonomy.count &gt; 0 AND wterms.term_id IN (2,5,6)&quot;);
</pre>
<p>For further help with comparison operators and functions, you can check out the <a href="http://dev.mysql.com/doc/refman/5.1/en/comparison-operators.html" target="_blank" title="MySQL Comparison Operators and Functions">MySQL manual</a>.</p>
<p>Next, we set up a category counter which will be incremented each time a category will be displayed. Based on this counter, the code adds a &#8216;<strong>catAlt</strong>&#8216; class that you can use to style differently consecutive categories. In our case, we&#8217;ll use it to shift the categories into two columns. This is were the alternate classes are assigned:</p>
<pre class="brush: php">
$catCounter++;

$catStyle = &#039;&#039;;
if (is_int($catCounter / 2)) $catStyle = &#039; class=&quot;catAlt&quot;&#039;;
</pre>
<p>The category list is built by the use of <strong>foreach</strong> and it helps retrieve vital information about the categories, such as name and permalink:</p>
<pre class="brush: php">
foreach ($catQuery as $category) {
	/* Code used to retrieve and display the latest posts */
}
</pre>
<p>After we display the category title and link through this line of code</p>
<pre class="brush: php">
echo &#039;&lt;li&#039;.$catStyle.&#039;&gt;&lt;h3&gt;&lt;a href=&quot;&#039;.get_category_link($category-&gt;term_id).&#039;&quot; title=&quot;&#039;.$category-&gt;name.&#039;&quot;&gt;&#039;.$category-&gt;name.&#039;&lt;/a&gt;&lt;/h3&gt;&#039;;
</pre>
<p>we continue by using a custom query to retrieve the latest 5 posts from the current category in the cycle, followed by a link to the complete category archive:</p>
<pre class="brush: php">
query_posts(&#039;cat=&#039;.$category-&gt;term_id.&#039;&amp;showposts=5&#039;);?&gt;

&lt;?php while (have_posts()) : the_post(); ?&gt;
	&lt;li&gt;&lt;a href=&quot;&lt;?php the_permalink() ?&gt;&quot; rel=&quot;bookmark&quot; title=&quot;&lt;?php the_title(); ?&gt;&quot;&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/li&gt;
&lt;?php endwhile; ?&gt;
	&lt;li&gt;&lt;a href=&quot;&lt;?php echo $catLink; ?&gt;&quot; title=&quot;&lt;?php echo $category-&gt;name; ?&gt;&quot;&gt;More &lt;strong&gt;&lt;?php echo $category-&gt;name; ?&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
</pre>
<p>And that&#8217;s about everything in terms of coding! Now, onto the CSS styling.</p>
<h3>Styling the archive</h3>
<p>Find the <strong>style.css</strong> file in your default theme&#8217;s directory, open it and scroll down to the end of the file. Now copy the code below and paste it in your file.</p>
<pre class="brush: css">
/* Latest posts by category styles */

.catArchive {
	width: 450px;
	overflow: hidden;
	margin: 20px 0 0 0;
	padding: 0;
	list-style-type: none;
}

.catArchive h3 {
	font: normal bold 18px sans-serif;
	border-bottom: 1px solid #666;
	margin: 0;
	padding: 0 0 3px 0;
	display: block;
}

.catArchive li {
	display: block;
	float: left;
	width: 210px;
	margin: 0 30px 30px 0;
}

.catArchive ul {
	margin: 0;
	padding: 0;
}

.catArchive li li {
	border-bottom: 1px solid #ddd;
	margin: 0;
	padding: 4px 0;
}

.catAlt {
	margin-right: 0 !important;
}
</pre>
<p>Now, save the file. We&#8217;re done!</p>
<p><strong>Note:</strong> Keep in mind that column sizes have been calculated based on the available space (450 pixels) in the default theme&#8217;s content area. So, our columns should each be 210 pixels wide, with a 30 pixels spacing between them.</p>
<p>Since the column shifting is done with the help of <strong>float</strong>, I&#8217;ve set the overflow to hidden to stretch the list full height. This can only work with a fixed given container width, which in our case is 450px set on <strong>.catArchive</strong>.</p>
<p>If your new to &#8220;floating&#8221;, Sarah has posted a fairly easy to understand article about <a href="http://www.bloggingtips.com/2009/02/12/understanding-the-float-property/" target="_blank" title="The CSS float property">the float property</a> on BloggingTips.com.</p>
<p>You can download an archive containing both source files: <a href="http://blogsessive.com/wp-content/plugins/download-monitor/download.php?id=4" title="Download Latest Posts by Category source files"><strong>Download</strong></a>.</p>
<hr /><h3>Free PDF eBook: Corporate Blogging Guide by Blogsessive</h3>As a subscribe reader of Blogsessive, this is my gift to you: a guide to corporate blogging (but not only) that will help you in your blogging adventures! <a href="http://blogsessive.com/wp-content/plugins/download-monitor/download.php?id=8" target="_blank">Download now, for FREE!</a><br /><br /><hr/><div style="background: #eeeeee;">Advertise on Blogsessive! <a href="http://buysellads.com/buy/detail/310/" title="Advertise on Blogsessive">125x125 banners</a> for <strong>$50 per month</strong>!</div>&copy;2008-2010 Copyright by <a href="http://blogsessive.com" title="Blogging tips">Blogsessive - Blogging Tips</a>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please <a href="http://blogsessive.com/contact" title="Contact Blogsessive">contact us</a>, so that we can take legal action immediately.<img src="http://blogsessive.com/?ak_action=api_record_view&id=1047&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blogsessive.com/blogging-tools/latest-posts-by-category-archive/feed/</wfw:commentRss>
		<slash:comments>53</slash:comments>
		</item>
		<item>
		<title>How To Remove the White Space in wp_list_pages()</title>
		<link>http://blogsessive.com/blogging-tools/how-to-remove-the-white-space-in-wp_list_pages/</link>
		<comments>http://blogsessive.com/blogging-tools/how-to-remove-the-white-space-in-wp_list_pages/#comments</comments>
		<pubDate>Tue, 15 Apr 2008 19:57:06 +0000</pubDate>
		<dc:creator>Alex, Blogsessive</dc:creator>
				<category><![CDATA[Blogging Tools]]></category>
		<category><![CDATA[Coding Tips]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[template tags]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[white space]]></category>
		<category><![CDATA[wp_list_pages]]></category>

		<guid isPermaLink="false">http://blogsessive.com/?p=39</guid>
		<description><![CDATA[The white space generated by wp_list_pages() has been a nightmare for many WordPress themes designers. It doesn't have to be one for you!]]></description>
			<content:encoded><![CDATA[<p>With the StudioPress WordPress themes you can really <a href="http://blogsessive.com/go-studiopress/" title="Take Your Blog to a Higher Level" target="ejejcsingle"><strong>take your blog to a higher level</strong></a>!<p><strong>wp_list_pages()</strong> is one of the most common WordPress template tags. Sometimes, the little white space that some browsers add to the output of this function can create a big mess in your theme&#8217;s template, making it hard to style, especially when trying to create a horizontal list. The fix for this is quite simple and requires minimum coding knowledge, if none at all.</p>
<h3>The Problem</h3>
<p>The wp_list_pages() generates either a series of &lt;li&gt; elements containing links to all of you blog&#8217;s pages, or a full unordered list with a heading at the beginning.<br />
The output of this list looks like this:<span id="more-39"></span></p>
<pre>&lt;ul&gt;
&lt;li&gt;&lt;a href="#"&gt;Page name&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#"&gt;Page name&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</pre>
<p>While some browsers don&#8217;t have a problem with elements being generated on new lines, in some, this method causes a white space to show up in front of each list item. This space becomes visible and annoying when trying to create a horizontal menu with background colors and equal horizontal spacing.</p>
<h3>The Fix</h3>
<p>To get rid of the white space, your output would need to look like this:</p>
<pre>&lt;ul&gt;&lt;li&gt;&lt;a href="#"&gt;Page name&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="#"&gt;Page name&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;</pre>
<p>This can be achieved by using a small PHP function that will take the code generated by wp_list_pages() and turn it into something similar to the example above. To make this function available for use in your templates you need to edit the &#8220;functions.php&#8221; file, found in you theme&#8217;s directory. If you don&#8217;t have such a file, create an empty one and name it &#8220;functions.php&#8221;.</p>
<p>In functions.php add the following code at the beginning or at the end of the file. Just be careful not to paste it inside another function and cause the script to break.</p>
<pre>function qbkl_nospace($input) {
$output = str_replace(array("\n", "\r", "\t"), "", $input);
echo $output;
}</pre>
<p><img class="alignnone size-full wp-image-40" title="whitespace-fix" src="http://blogsessive.com/wp-content/uploads/2008/04/whitespace-fix.gif" alt="White space fix" width="500" height="60" /></p>
<h3>Usage</h3>
<p>To apply the fix, simply find the wp_list_pages() in your theme&#8217;s template (usually header.php or sidebar.php) and edit the code according to the following example:</p>
<p>Find:</p>
<pre>&lt;?php wp_list_pages(); ?&gt;</pre>
<p>Replace with:</p>
<pre>&lt;?php qbkl_nospace(wp_list_pages()); ?&gt;</pre>
<p>This fix works with any function or template tag that generates the same problem.</p>
<p>The white space generated by wp_list_pages() has been a nightmare for many WordPress themes designers. It doesn&#8217;t have to be one for you!</p>
<h3>Where is wp_list_pages() located?</h3>
<p>Although it&#8217;s not recommended that you alter the base code of WordPress, advanced users might feel like taking such a job.</p>
<p>If you need to alter the output, <strong>wp_list_pages</strong> is defined in the <em>post-template.php</em> file, in the &#8220;<em>wp-includes</em>&#8221; folder of your WordPress blog.</p>
<p>For further tweaking, you might also need to adjust the <strong>walk_page_tree</strong> function, located in the same file, which makes use of the class <strong>Walker_Page</strong>, extending the <strong>Walker</strong> class, both located in <em>wp-includes/classes.php</em>.</p>
<p>* The above file names and locations are confirmed for WordPress 2.5 to 2.6.3.</p>
<p>If you&#8217;re having any questions or need further assistance, please use <strong><a title="Add your comment" href="http://blogsessive.com/blogging-tools/how-to-remove-the-white-space-in-wp_list_pages/#respond" target="_self">this post&#8217;s comment form</a></strong>.</p>
<hr /><h3>Free PDF eBook: Corporate Blogging Guide by Blogsessive</h3>As a subscribe reader of Blogsessive, this is my gift to you: a guide to corporate blogging (but not only) that will help you in your blogging adventures! <a href="http://blogsessive.com/wp-content/plugins/download-monitor/download.php?id=8" target="_blank">Download now, for FREE!</a><br /><br /><hr/><div style="background: #eeeeee;">Advertise on Blogsessive! <a href="http://buysellads.com/buy/detail/310/" title="Advertise on Blogsessive">125x125 banners</a> for <strong>$50 per month</strong>!</div>&copy;2008-2010 Copyright by <a href="http://blogsessive.com" title="Blogging tips">Blogsessive - Blogging Tips</a>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please <a href="http://blogsessive.com/contact" title="Contact Blogsessive">contact us</a>, so that we can take legal action immediately.<img src="http://blogsessive.com/?ak_action=api_record_view&id=39&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blogsessive.com/blogging-tools/how-to-remove-the-white-space-in-wp_list_pages/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>

