wordpress Get Subcategories List custom PHP pages

wordpress Get Subcategories List custom PHP pages

In this Post We Will Explain About is wordpress Get Subcategories List custom PHP pages 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 List only child categories a post is in, of a specific parent categoryExample

In this post we will show you Best way to implement Putting Categories Into a Foreach Loop And manipulating, hear for How to Display Only Child Category in your WordPress Post Loopwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

To display the only simple sub or Child Category list in the post loop it is used to (mostly PHP custom single.php), all we have to do is replace the following code:

Example 1 : get subcategories of a category in wordpress


cat_ID).'">';
	 echo $sub_category->cat_name . '';
	}
}
?>
Javascript
	Angularjs 1
	Vuejs 2
	etc.
PHP
	Laravel 1
	Magento 2
	etc.
CSS
	Bootsrep 1
	Matrialize 2
	etc.

Example 2 : display subcategories on category pages in wordpress

$main_parents = get_terms( 'category', array( 'parent' => 0 ) );
$list_catgory = get_the_terms( $post->ID, 'category' );
foreach( $main_parents as $get_parent ):
echo '' . $get_parent->name . ': ';
$data_links = array();
foreach( $list_catgory as $get_cat ):
    if( $get_parent->term_id == $get_cat->parent ):
       
        $data_links[] = '' . $get_cat->name .      '';
    endif;
endforeach;
echo join( ', ', $data_links );
endforeach;

Example 3 : wordpress get child categories of current category

$all_category_list = array();
 $get_allCat = get_categories(); // Get the list of Categories
    foreach ($get_allCat as $main_catobj) {
        $term_id = $main_catobj->term_id;
        $posts_cat = get_posts(array('category'=>$term_id));
        $authors_arr = array();
        foreach ($posts_cat as $post_obj) {
            $author_id = $post_obj->post_author;
			$get_cat[$author_id][] = strtolower($main_catobj->name);
			$all_category_list[] = strtolower($main_catobj->name);
			
       
            if (!function_exists('get_userdata')) {
                include '/wp-includes/pluggable.php';
            }

            $main_user_obj = get_userdata($author_id);
               
            if (!in_array($main_user_obj->user_login, $authors_arr)) {
                $authors_arr[] = $main_user_obj->user_login; 
            }
        }
       echo implode(', ', $authors_arr) . '
'; } $all_category_list = array_unique($all_category_list); sort($all_category_list); echo implode(', ', $all_category_list) . '
';

Example

I hope you have Got What is List only child categories a post is in, of a specific parent category 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.

Leave a Comment