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 Pakainfo.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!.

Read Also:  Apache Htaccess HTTP Server Tutorial

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;
}
?>

Example

Read Also:  PHP Magento Configure Product Attribute sets

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(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Simple Laravel Query Dumper Getquerylog
  2. Read Also:  Bootstrap carousel slider with thumbnail image gallery
  3. Read Also:  ng-blur Event using Angular Example
  4. Read Also:  Login and Registration Form in PHP using Mysqli
  5. Read Also:  How to export mysql data to pdf using php with demo?
  6. Read Also:  cPanel custom PHP.INI File Configuration
  7. Read Also:  Uppercase Filter using Angular Example
  8. Read Also:  wordpress Get Subcategories List custom PHP pages
  9. Read Also:  PHP - Paypal Payment Gateway Integration
  10. Read Also:  Apache Htaccess HTTP Server Tutorial