<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
	>
<channel>
	<title>Comments on: Fun with Wordpress categories</title>
	<atom:link href="http://tugbucket.net/wordpress/fun-with-wordpress-categories/feed/" rel="self" type="application/rss+xml" />
	<link>http://tugbucket.net/wordpress/fun-with-wordpress-categories/</link>
	<description></description>
	<pubDate>Fri, 12 Mar 2010 03:31:06 +0000</pubDate>
	
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Alan</title>
		<link>http://tugbucket.net/wordpress/fun-with-wordpress-categories/comment-page-1/#comment-206</link>
		<dc:creator>Alan</dc:creator>
		<pubDate>Thu, 04 Mar 2010 21:06:03 +0000</pubDate>
		<guid isPermaLink="false">http://tugbucket.net/?p=118#comment-206</guid>
		<description>@Virendar

You should be able to modify the function like so.

&lt;code&gt;function desc_cats(){
foreach (get_categories(array('hide_empty'=&gt;true)) as $category)
{
$catid = $category-&gt;cat_ID;
echo '&lt;div&gt;&lt;h3&gt;&lt;a href="' . get_bloginfo('wpurl') . '/category/' .  $category-&gt;category_nicename . '/"&gt;' .
	$category-&gt;cat_name . ' (' . $category-&gt;count.$numposts.')&lt;/a&gt;&lt;/h3&gt;' . category_description($catid) . '&lt;hr&gt;&lt;/div&gt;' . "\n";
}
};
&lt;!--formatted--&gt;&lt;/code&gt;

And call it like so:
&lt;code&gt;&lt;?php desc_cats(); ?&gt;&lt;!--formatted--&gt;&lt;/code&gt;

That will make each category in it's own div with a &lt;h3&gt; and a link for the title and ending with a horizontal rule.

As for paginating the results, not sure off hand. That really has nothign to do with the base of this function.</description>
		<content:encoded><![CDATA[<p>@Virendar</p>
<p>You should be able to modify the function like so.</p>
<p><code>function desc_cats(){<br />
foreach (get_categories(array('hide_empty'=>true)) as $category)<br />
{<br />
$catid = $category->cat_ID;<br />
echo '&lt;div>&lt;h3>&lt;a href="' . get_bloginfo('wpurl') . '/category/' .  $category->category_nicename . '/">' .<br />
	$category->cat_name . ' (' . $category->count.$numposts.')&lt;/a>&lt;/h3>' . category_description($catid) . '&lt;hr>&lt;/div>' . "\n";<br />
}<br />
};<br />
<!--formatted--></code></p>
<p>And call it like so:<br />
<code>&lt;?php desc_cats(); ?><!--formatted--></code></p>
<p>That will make each category in it&#8217;s own div with a &lt;h3> and a link for the title and ending with a horizontal rule.</p>
<p>As for paginating the results, not sure off hand. That really has nothign to do with the base of this function.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Virendar</title>
		<link>http://tugbucket.net/wordpress/fun-with-wordpress-categories/comment-page-1/#comment-204</link>
		<dc:creator>Virendar</dc:creator>
		<pubDate>Tue, 23 Feb 2010 15:25:05 +0000</pubDate>
		<guid isPermaLink="false">http://tugbucket.net/?p=118#comment-204</guid>
		<description>ah for number 2 my html isnt shown.  I said I want to add an  "hr'  tag &gt;&lt; in between</description>
		<content:encoded><![CDATA[<p>ah for number 2 my html isnt shown.  I said I want to add an  &#8220;hr&#8217;  tag &gt;&lt; in between</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Virendar</title>
		<link>http://tugbucket.net/wordpress/fun-with-wordpress-categories/comment-page-1/#comment-203</link>
		<dc:creator>Virendar</dc:creator>
		<pubDate>Tue, 23 Feb 2010 15:23:42 +0000</pubDate>
		<guid isPermaLink="false">http://tugbucket.net/?p=118#comment-203</guid>
		<description>Hey ! For the second code, the one with the descriptions, how can I do the following :

1) I want to add pagination. I have over 500 categories, and if all of them are listed WITH their descriptions, its a looooong and laggy page. So maybe only like..50 per page.

2) I want to add an  in between the listed categories to space them out a little and make it look nice.</description>
		<content:encoded><![CDATA[<p>Hey ! For the second code, the one with the descriptions, how can I do the following :</p>
<p>1) I want to add pagination. I have over 500 categories, and if all of them are listed WITH their descriptions, its a looooong and laggy page. So maybe only like..50 per page.</p>
<p>2) I want to add an  in between the listed categories to space them out a little and make it look nice.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alan</title>
		<link>http://tugbucket.net/wordpress/fun-with-wordpress-categories/comment-page-1/#comment-108</link>
		<dc:creator>Alan</dc:creator>
		<pubDate>Fri, 14 Aug 2009 14:47:52 +0000</pubDate>
		<guid isPermaLink="false">http://tugbucket.net/?p=118#comment-108</guid>
		<description>@zbrass,

I totally see what you mean. I think that would be best left for a manual setting like you are doing. My home page has a hack to only show 4 posts. My archive is using pagination set to 6 posts. So I would think it would be easier to set the category script to the max number you are showing and just send the link to page 2.

Since there is only a few areas that need modification, it's not too difficult.

Glad it worked for you.</description>
		<content:encoded><![CDATA[<p>@zbrass,</p>
<p>I totally see what you mean. I think that would be best left for a manual setting like you are doing. My home page has a hack to only show 4 posts. My archive is using pagination set to 6 posts. So I would think it would be easier to set the category script to the max number you are showing and just send the link to page 2.</p>
<p>Since there is only a few areas that need modification, it&#8217;s not too difficult.</p>
<p>Glad it worked for you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: zbrass</title>
		<link>http://tugbucket.net/wordpress/fun-with-wordpress-categories/comment-page-1/#comment-107</link>
		<dc:creator>zbrass</dc:creator>
		<pubDate>Thu, 13 Aug 2009 23:53:08 +0000</pubDate>
		<guid isPermaLink="false">http://tugbucket.net/?p=118#comment-107</guid>
		<description>Great Alan!
Thanks a lot.

But one thing to make it perfect would be that the link 'view more' would give an archive page that starts with post nr6 

I do that now like this

echo '&lt;a&gt;category_nicename . '/page/2/"&gt;View more&lt;/a&gt;' . "\n";

But if you have in your settings 10 posts on a page you have a problem there. You lose flexebility. cause page 2 would start with post 11.

You see what i mean? 

Again thanks a lot!</description>
		<content:encoded><![CDATA[<p>Great Alan!<br />
Thanks a lot.</p>
<p>But one thing to make it perfect would be that the link &#8216;view more&#8217; would give an archive page that starts with post nr6 </p>
<p>I do that now like this</p>
<p>echo &#8216;<a>category_nicename . &#8216;/page/2/&#8221;&gt;View more</a>&#8216; . &#8220;\n&#8221;;</p>
<p>But if you have in your settings 10 posts on a page you have a problem there. You lose flexebility. cause page 2 would start with post 11.</p>
<p>You see what i mean? </p>
<p>Again thanks a lot!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alan</title>
		<link>http://tugbucket.net/wordpress/fun-with-wordpress-categories/comment-page-1/#comment-106</link>
		<dc:creator>Alan</dc:creator>
		<pubDate>Thu, 13 Aug 2009 22:51:45 +0000</pubDate>
		<guid isPermaLink="false">http://tugbucket.net/?p=118#comment-106</guid>
		<description>@zbrass,
Thanks for bringing that to my attention. If you read my note above, I have modified the script a little. the 'numberposts' defaults at 5 so that's why it was stopping. I edited it to solve that issue.

Now to your real question.

&lt;code&gt;
function cat_and_posts(){
foreach (get_categories(array('hide_empty'=&gt;true)) as $category)
{
$catid = $category-&gt;cat_ID;
global $post;
$myposts = get_posts('numberposts=100&amp;category='.$catid);
echo '&lt;li&gt;' . $category-&gt;cat_name . "\n";
echo '&lt;ul&gt;' . "\n";
$count = 0;
foreach($myposts as $post) {
echo '&lt;li&gt;&lt;a href="' . get_permalink() . '"&gt;' . get_the_title() . '&lt;/a&gt;&lt;/li&gt;' . "\n";
$count++;
if ($count &gt;= 5){
echo '&lt;li&gt;&lt;a href="' . get_bloginfo('wpurl') . '/category/' .  $category-&gt;category_nicename . '/"&gt;View more&lt;/a&gt;&lt;/li&gt;' . "\n";
break;
}
}
echo '&lt;/ul&gt;' . "\n";
echo '&lt;/li&gt;' . "\n";
}
};   
&lt;!--formatted--&gt;&lt;/code&gt;

We're going to start a count of the posts. Once it reaches 5 it will add a link to the archives for that category and stop the script. 

Now this will not make a link for categories with less than 5 posts. 

Hope that works for you.


@submarine,

That looks like an interesting plug-in. I might play with it soon.</description>
		<content:encoded><![CDATA[<p>@zbrass,<br />
Thanks for bringing that to my attention. If you read my note above, I have modified the script a little. the &#8216;numberposts&#8217; defaults at 5 so that&#8217;s why it was stopping. I edited it to solve that issue.</p>
<p>Now to your real question.</p>
<p><code><br />
function cat_and_posts(){<br />
foreach (get_categories(array('hide_empty'=>true)) as $category)<br />
{<br />
$catid = $category->cat_ID;<br />
global $post;<br />
$myposts = get_posts('numberposts=100&#038;category='.$catid);<br />
echo '&lt;li>' . $category->cat_name . "\n";<br />
echo '&lt;ul>' . "\n";<br />
$count = 0;<br />
foreach($myposts as $post) {<br />
echo '&lt;li>&lt;a href="' . get_permalink() . '">' . get_the_title() . '&lt;/a>&lt;/li>' . "\n";<br />
$count++;<br />
if ($count >= 5){<br />
echo '&lt;li>&lt;a href="' . get_bloginfo('wpurl') . '/category/' .  $category->category_nicename . '/">View more&lt;/a>&lt;/li>' . "\n";<br />
break;<br />
}<br />
}<br />
echo '&lt;/ul>' . "\n";<br />
echo '&lt;/li>' . "\n";<br />
}<br />
};<br />
<!--formatted--></code></p>
<p>We&#8217;re going to start a count of the posts. Once it reaches 5 it will add a link to the archives for that category and stop the script. </p>
<p>Now this will not make a link for categories with less than 5 posts. </p>
<p>Hope that works for you.</p>
<p>@submarine,</p>
<p>That looks like an interesting plug-in. I might play with it soon.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Submarine</title>
		<link>http://tugbucket.net/wordpress/fun-with-wordpress-categories/comment-page-1/#comment-105</link>
		<dc:creator>Submarine</dc:creator>
		<pubDate>Thu, 13 Aug 2009 21:25:56 +0000</pubDate>
		<guid isPermaLink="false">http://tugbucket.net/?p=118#comment-105</guid>
		<description>You could also use the Category Icons plugin in order to display icons assigned to categories : use get_cat_icon("echo=false&amp;cat=".$catid); to display the icons in your foreach loop.</description>
		<content:encoded><![CDATA[<p>You could also use the Category Icons plugin in order to display icons assigned to categories : use get_cat_icon(&#8221;echo=false&amp;cat=&#8221;.$catid); to display the icons in your foreach loop.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: zbrass</title>
		<link>http://tugbucket.net/wordpress/fun-with-wordpress-categories/comment-page-1/#comment-104</link>
		<dc:creator>zbrass</dc:creator>
		<pubDate>Tue, 11 Aug 2009 14:06:21 +0000</pubDate>
		<guid isPermaLink="false">http://tugbucket.net/?p=118#comment-104</guid>
		<description>Hi,
Thanks for this!

I have a question for now your code shows only 5 post within the cat.
if there are more posts in the cat how can i ad a link to these posts?

I don't want to show more post but find out if there are more than '5' posts and if so a link to the archive page.

foreach($myposts as $post) {
echo '&lt;a href="' . get_permalink() . '" rel="nofollow"&gt;' . get_the_title() . '&lt;/a&gt;' . "\n";
}
 ----HERE THE if more than 5 echo and than a link to the previous posts 
echo '' . "\n";
echo '' . "\n";

I hope you can solve this , i looked everywhere for a solution.

Thanks!</description>
		<content:encoded><![CDATA[<p>Hi,<br />
Thanks for this!</p>
<p>I have a question for now your code shows only 5 post within the cat.<br />
if there are more posts in the cat how can i ad a link to these posts?</p>
<p>I don&#8217;t want to show more post but find out if there are more than &#8216;5&#8242; posts and if so a link to the archive page.</p>
<p>foreach($myposts as $post) {<br />
echo &#8216;<a href="' . get_permalink() . '" rel="nofollow">&#8216; . get_the_title() . &#8216;</a>&#8216; . &#8220;\n&#8221;;<br />
}<br />
 &#8212;-HERE THE if more than 5 echo and than a link to the previous posts<br />
echo &#8221; . &#8220;\n&#8221;;<br />
echo &#8221; . &#8220;\n&#8221;;</p>
<p>I hope you can solve this , i looked everywhere for a solution.</p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony Murphy</title>
		<link>http://tugbucket.net/wordpress/fun-with-wordpress-categories/comment-page-1/#comment-101</link>
		<dc:creator>Tony Murphy</dc:creator>
		<pubDate>Wed, 15 Jul 2009 21:52:31 +0000</pubDate>
		<guid isPermaLink="false">http://tugbucket.net/?p=118#comment-101</guid>
		<description>thanks for the very useful info. I have started using it on my web video site. I'm not finished customising it yet but you can see it here: &lt;a href="http://www.webvideobytes.com" rel="nofollow"&gt;Web Video Tips&lt;/a&gt;.

cheer
Tony</description>
		<content:encoded><![CDATA[<p>thanks for the very useful info. I have started using it on my web video site. I&#8217;m not finished customising it yet but you can see it here: <a href="http://www.webvideobytes.com" rel="nofollow">Web Video Tips</a>.</p>
<p>cheer<br />
Tony</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alan</title>
		<link>http://tugbucket.net/wordpress/fun-with-wordpress-categories/comment-page-1/#comment-83</link>
		<dc:creator>Alan</dc:creator>
		<pubDate>Mon, 04 May 2009 13:43:10 +0000</pubDate>
		<guid isPermaLink="false">http://tugbucket.net/?p=118#comment-83</guid>
		<description>John,

Instead of echoing out the list item, add it to a variable and then usu PHP strip_tags function to remove the break tag and then echo out the result like so:

&lt;code&gt;$catdesc = &#039;&lt;li&gt;&lt;a href=&#34;&#039; . get_bloginfo(&#039;wpurl&#039;) . &#039;/category/&#039; .  $category-&gt;category_nicename . &#039;/&#34;&gt;&#039; .
	$category-&gt;cat_name . &#039; (&#039; . $category-&gt;count.$numposts.&#039;)&lt;/a&gt;&#039; . category_description($catid) . &#039;&lt;/li&gt;&#039; . &#34;\n&#34;;	
$catty = strip_tags($catdesc, &#039;&lt;p&gt;&lt;a&gt;&lt;li&gt;&#039;);	
echo $catty;&lt;/code&gt;

</description>
		<content:encoded><![CDATA[<p>John,</p>
<p>Instead of echoing out the list item, add it to a variable and then usu PHP strip_tags function to remove the break tag and then echo out the result like so:</p>
<p><code>$catdesc = &#039;&lt;li&gt;&lt;a href=&quot;&#039; . get_bloginfo(&#039;wpurl&#039;) . &#039;/category/&#039; .  $category-&gt;category_nicename . &#039;/&quot;&gt;&#039; .<br />
	$category-&gt;cat_name . &#039; (&#039; . $category-&gt;count.$numposts.&#039;)&lt;/a&gt;&#039; . category_description($catid) . &#039;&lt;/li&gt;&#039; . &quot;\n&quot;;<br />
$catty = strip_tags($catdesc, &#039;&lt;p&gt;&lt;a&gt;&lt;li&gt;&#039;);<br />
echo $catty;</code></p>
]]></content:encoded>
	</item>
</channel>
</rss>
