<?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>SDAC Inc &#124; Chicagoland Web Development &#187; get_cateogry_parents</title> <atom:link href="http://www.sandboxdev.com/tag/get_cateogry_parents/feed/" rel="self" type="application/rss+xml" /><link>http://www.sandboxdev.com</link> <description>Just another Sandbox Development and Consulting Inc. Sites site</description> <lastBuildDate>Wed, 25 Jan 2012 07:57:33 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>Get Top Parent Category (WordPress)</title><link>http://www.sandboxdev.com/2009/01/15/get-top-parent-category-wordpress/</link> <comments>http://www.sandboxdev.com/2009/01/15/get-top-parent-category-wordpress/#comments</comments> <pubDate>Thu, 15 Jan 2009 15:28:16 +0000</pubDate> <dc:creator>Jennifer Zelazny</dc:creator> <category><![CDATA[Clients]]></category> <category><![CDATA[HOWTOs]]></category> <category><![CDATA[SDAC Blog]]></category> <category><![CDATA[WordPress Logic]]></category> <category><![CDATA[get_cateogry_parents]]></category> <category><![CDATA[jappler.com]]></category> <category><![CDATA[WordPress]]></category> <guid
isPermaLink="false">http://www.sandboxdev.com/?p=518</guid> <description><![CDATA[There are many times when you need to show or get the top most (root) parent category in WordPress &#8211; regardless of how many subcategories you might be deep. I have used this logic for page navigation (highlight the top parent tab) &#8211; as well as within some custom loops/sidebar code. They way to do [...]]]></description> <content:encoded><![CDATA[<p>There are many times when you need to show or get the top most (root) parent category in WordPress &#8211; regardless of how many subcategories you might be deep.  I have used this logic for page navigation (highlight the top parent tab) &#8211; as well as within some custom loops/sidebar code.</p><p>They way to do this:</p><pre class="brush: php; title: Custom Code; notranslate">
// get parent category slug
$parentCatList = get_category_parents($cat,false,',');
$parentCatListArray = split(&quot;,&quot;,$parentCatList);
$topParentName = $parentCatListArray[0];
$sdacReplace = array(&quot; &quot; =&gt; &quot;-&quot;, &quot;(&quot; =&gt; &quot;&quot;, &quot;)&quot; =&gt; &quot;&quot;);
$topParent = strtolower(strtr($topParentName,$sdacReplace));
</pre><p>To test this you can simply put it in your header and echo out $topParent and you will see the &#8220;slug&#8221; of the category.<br
/> If you want to see the category name and not necessarily the slug &#8211; you can simply echo $topParentName.</p> <script type="text/javascript">sdac_post_slideshows.push({fx: 'fade', timeout: 0, speed: 1000, pause: 0,})</script>]]></content:encoded> <wfw:commentRss>http://www.sandboxdev.com/2009/01/15/get-top-parent-category-wordpress/feed/</wfw:commentRss> <slash:comments>44</slash:comments> </item> </channel> </rss>
