As far I’ve known get_template_part()
function does not work with foreach
loop. So we need to use locate_template()
function to this case. This is your customized category template code. Put it there –
<?php
/**
* Category Template: Custom
*/
get_header(); ?>
<div id="content" class="site-content container <?php echo codilight_lite_sidebar_position(); ?>">
<div class="content-inside">
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
$cat = get_category( get_query_var( 'cat' ) );
$cat_id = $cat->cat_ID;
$child_categories=get_categories(
array(
'parent' => $cat_id,
// Uncomment the below line if you want empty category to appear on the list.
// 'hide_empty' => 0
)
);
if (!empty($child_categories)) : $count = 0; ?>
<header class="page-header">
<?php
the_archive_title( '<h1 class="page-title">', '</h1>' );
the_archive_description( '<div class="taxonomy-description">', '</div>' );
?>
</header><!-- .page-header -->
<div class="block1 block1_grid">
<?php
foreach(array_chunk($child_categories, 2) as $item) {
echo '<div class="row">';
foreach ($item as $child) {
// get_template_part( 'template-parts/content-grid' );
include( locate_template( 'template-parts/content-grid.php' ) );
}
echo '</div>';
}
?>
</div>
<?php else : ?>
<?php get_template_part( 'template-parts/content', 'none' ); ?>
<?php endif; ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>