wordpress Get All Parent Categories from Child Categories

wordpress Get All Parent Categories from Child Categories

In this Post We Will Explain About is wordpress Get All Parent Categories from Child Categories With Example and Demo.Welcome on Live24u.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to How to Add Categories and Subcategories to WordPressExample

In this post we will show you Best way to implement wordpress get subcategories of current category, hear for get child category from parent category in wordpresswith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Also Read :   jQuery Add and Remove Multiple Div Dynamically using PHP

You can download source code and Demo from below link.




In wordpress get all the parent list and child list, sometimes we can have many get all the subcategories for a different data parent categories. here By default wordpress all the lists all sub-categories.

if i have category structure like

Main Categories 1
– 1.sub-categories
– 2.sub-categories
– 3.sub-categories
– 4.sub-categories

Main Categories 2

– 1.sub-categories
– 2.sub-categories
– 3.sub-categories
– 4.sub-categories

get all parent categories in wordpress

//display HTML View get Categories
<ul class="list-items categories"> 
 <?php $category_ids = get_all_category_ids(); 
 //list of categories args
 $args = array( 'orderby' => 'slug', 'parent' => 0 ); 
 $categories = get_categories( $args ); 
 //for each loop to get all sub_categoylist
 foreach ( $categories as $List_category ) { 

 echo '<li><a href="?catgory=' . $List_category->name . '" rel="bookmark">' . $List_category->name . '</a>  
 </li>'; } ?> 
</ul>   

get parent category from child category wordpress

<?php
//check condition for categories
  if (is_category()) {
    $this_category = get_category($cat);
  }
?>
<?php
//check condition for categories
  if($this_category->category_parent)
    $this_category = wp_list_categories('orderby=id&show_count=0&title_li=&use_desc_for_title=1&child_of='.$this_category->category_parent."&echo=0"); else $this_category = wp_list_categories('orderby=id&show_count=0&title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID."&echo=0");
	//check condition for categories
 if ($this_category) { ?>
 //display HTML View get Categories
   <ul>
     <?php echo $this_category; ?>
   </ul>
<?php } 
?>

<?php
$List_category = get_the_category();
//display HTML View get Categories
$parent_list = get_cat_name($List_category[0]->category_parent);
//check condition for categories
if (!empty($parent_list)) {
//print_ parent_list
echo '» ' . $parent_list;
} else {
echo '» ' . $List_category[0]->cat_name;
}
?>

You can download source code and Demo from below link.





Example

Also Read :   PHP Highlight search matching text Results with Mysql

I hope you have Got What is display subcategories on category pages in wordpress And how it works.I would Like to have FeadBack From My Blog(live24u.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(live24u.com) Are Most Always Welcome.

   

Add a Comment

Your email address will not be published.