Skip to content

Instantly share code, notes, and snippets.

@flayder
Last active September 29, 2015 09:37
Show Gist options
  • Save flayder/71034bfb4b4cf306ea49 to your computer and use it in GitHub Desktop.
Save flayder/71034bfb4b4cf306ea49 to your computer and use it in GitHub Desktop.
Вывод подкатегорий и записей из родительской категории!
<?php
function productCart() {
?>
<div class="buy-with">
<h2><?php echo get_cat_name(46); ?></h2>
<ul>
<?php
$parent_id = 46;
$sub_cats = get_categories( array(
'child_of' => $parent_id
) );
if( $sub_cats ){
foreach( $sub_cats as $cat ){
$posts = get_posts( array(
'numberposts' => -1,
'category' => $cat->cat_ID
) );
global $post;
foreach($posts as $post){ setup_postdata($post); ?>
<div class="img"><?php the_post_thumbnail(); ?> </div>
<a href="<?php get_permalink();?>"><?php the_title();?></a>
<?php
}
wp_reset_postdata();
}
}
?>
</ul>
</div>
<?php
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment