I have customized my theme's category template to display the current category's child categories instead of posts.
Everything is working correctly except for the following error: Fatal error: Call to undefined function codilight_lite_custom_paginate() in...
I could remove the function from the template but if possible I would like to keep it so I have the option to paginate the results for categories with a large number of child categories.
Is there any way I can modify the function so it works with the customized template?
Here is the function:
if ( ! function_exists( 'codilight_lite_custom_paginate' ) ) :
/**
* Retrieve paginated link for archive post pages.
*/
function codilight_lite_custom_paginate() {
global $wp_query;
$total_pages = $wp_query->max_num_pages;
$big = 999999999;
$translated = __( 'Page', 'codilight-lite' );
if ($total_pages > 1){
$current_page = max(1, get_query_var('paged'));
echo '<div class="ft-paginate">';
echo paginate_links(array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'prev_next' => True,
'prev_text' => '<i class="fa fa-angle-left"></i>',
'next_text' => '<i class="fa fa-angle-right"></i>',
'current' => $current_page,
'total' => $total_pages,
'before_page_number' => '<span class="screen-reader-text">'.$translated.' </span>'
));
//echo '<span class="total-pages">Page '. $current_page .' of '. $total_pages .'</span>';
printf( '<span class="total-pages">'. esc_html__( 'Page %1$s of %2$s', 'codilight-lite' ) .'</span>', $current_page, $total_pages );
echo '</div>';
}
}
endif;
...and here is my customized category template:
<?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 -->
<?php
echo '<div class="block1 block1_grid">';
echo '<div class="row">';
foreach ( $child_categories as $child ){ $count++;
include( locate_template( 'template-parts/content-grid.php' ) );
if ( $count % 2 == 0 ) {
echo '</div>';
echo '<div class="row">';
}
}
echo '</div>';
echo '</div>';
?>
<?php else : ?>
<?php get_template_part( 'template-parts/content', 'none' ); ?>
<?php endif; ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>