Last active
December 20, 2015 04:49
-
-
Save siddhartanaranjo/6073854 to your computer and use it in GitHub Desktop.
List subcategories with loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* List categories of categories page */ | |
function list_my_subcategories(){ | |
$q_cat = get_query_var('cat'); | |
$cat = get_category($q_cat); | |
$catid = $cat->cat_name; | |
/*get the parent*/ | |
$q_parent = $cat->category_parent; | |
$parent = get_category($q_parent); | |
$parentid = $parent->cat_name; | |
$html .= ''; | |
if ($cat) { | |
$subcategories = get_categories('child_of='.$cat->cat_ID.''); | |
if ($subcategories) { | |
foreach ($subcategories as $q_subcat) { | |
$subcat = get_category($q_subcat); | |
$subcatname = $subcat->cat_name; | |
$subcatid = $subcat->cat_ID; | |
$subcatLink = get_permalink($subcat); | |
$html .= '<div class="span12 service_container">'; | |
$html .= '<div class="row">'; | |
$html .= '<div class="span12 blueBackground product_block">'; | |
$html .= '<h2 class="product_name_title">'.$subcatname; | |
$html .= '</h2>'; | |
$html .= '</div>'; | |
$html .= '<div class="span12 subCategoria">'; | |
$html .= '<div class="row subCategoriaFiltroCartucho">'; | |
global $post; | |
$args = array('category_name' => $subcatname, 'post_type' => 'producto'); | |
$posts = get_posts($args); | |
foreach ($posts as $post) : setup_postdata($post); | |
$link = get_permalink(); | |
$title = get_the_title(); | |
$html .= '<div class="span4 blueBackground service_name">'; | |
$html .= '<a href="'.$link.'">'; | |
$html .= '<h2 class="product_name_title">'.$title; | |
$html .= '</h2>'; | |
$html .= '</a>'; | |
$html .= '</div>'; | |
endforeach; | |
$html .= '</div>'; | |
$html .= '</div>'; | |
$html .= '</div></div>'; | |
} | |
} | |
} | |
$html .= ''; | |
return $html; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment