October 31, 2011

Here is code I usually use to find ancestor or parent of a category [php] function getCategoryAncestor($cat,$index=0){ $parentCatList = get_category_parents($cat,false,’,’); $parentCatListArray = @split(",",$parentCatList); $topParentName = $parentCatListArray[$index]; $charReplace = array(" " => "-", "(" => "", ")" => ""); $topParentSlug = strtolower(strtr($topParentName,$charReplace)); $catAncestor[‘ancestor’] = $topParentName; $catAncestor[‘ancestor_slug’] = $topParentSlug; return $catAncestor; } // How to use :…

Read More WordPress : How to get category ancestor