You need to pass it at least 2 parameters, or it won’t know what to look for:
<?php
function custom_pagination($cat_id, $catnum) {
// Start of Pagination
$total_childs_query = get_categories( array( 'parent' => $cat_id, 'hide_empty' => '0' ));
$total_terms = count( $total_childs_query );
$pages = ceil($total_terms/$catnum);
$base_url = get_term_link( $cat_id, get_query_var( 'taxonomy' ) );
// if there's more than one page
if( $pages > 1 ):
echo '<div class="ft-paginate">';
echo '<nav class="navigation pagination" role="navigation">';
echo '<h2 class="screen-reader-text">Posts navigation</h2>';
echo '<div class="nav-links">';
// if we're not on the first page, print the previous-link
if ( $catpage > 1 ) {
$prevpage = $catpage - 1;
if ( $prevpage > 1 ) {
echo '<a class="prev page-numbers" href="' . $base_url . '/page/' . $prevpage . '"><i class="fa fa-angle-left"></i></a>';
} else {
echo '<a class="prev page-numbers" href="' . $base_url . '"><i class="fa fa-angle-left"></i></a>';
}
}
for ($pagecount=1; $pagecount <= $pages; $pagecount++):
//set class
$class = "page-numbers";
if ( $pagecount == $catpage ) {
$class .= " current";
}
if ( $pagecount == $catpage ) {
echo ' <span class="' . $class . '"><span class="screen-reader-text">Page</span>' . $pagecount . '</span>';
}
else if ( $pagecount == 1 ) {
echo ' <a class="' . $class . '" href="' . $base_url . '"><span class="screen-reader-text">Page</span>' . $pagecount . '</a>';
} else {
echo ' <a class="' . $class . '" href="' . $base_url . '/page/' . $pagecount . '"><span class="screen-reader-text">Page</span>' . $pagecount . '</a>';
}
endfor;
// if there is one more page after the current, print the next-link
if ( $catpage < $pages ) {
$nextpage = $catpage + 1;
echo ' <a class="next' . $class . '" href="' . $base_url . '/page/' . $nextpage . '"><i class="fa fa-angle-right"></i></a>';
}
echo '</div>';
echo '</nav>';
printf( '<span class="total-pages">' . esc_html__( 'Page %1$s of %2$s', 'codilight-lite' ) . '</span>', $catpage, $pages );
echo '</div>';
endif;
// End of Pagination
}
?>
Then, in your template you can use the function adding the values dynamically:
$cat_id = 3;
$cat_num = 5;
custom_pagination($cat_id, $catnum);