I am trying to display list of all created categories, regardless they have a post or not. I found this function which get the categories list in category-template.php. I am not sure what edits should I do to this function to get my required results.
function get_the_category( $id = false ) {
$categories = get_the_terms( $id, 'category' );
if ( ! $categories || is_wp_error( $categories ) )
$categories = array();
$categories = array_values( $categories );
foreach ( array_keys( $categories ) as $key ) {
_make_cat_compat( $categories[$key] );
}
return apply_filters( 'get_the_categories', $categories );
}
Roaming here, I have seen a manual way here by Scott B. But unfortunately I can't fully understand it.
This works for me:
<ul>
<?php $args = array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories = get_categories($args);
foreach ( $categories as $category ) {?>
<li><?php echo '<a href="' . get_category_link( $category->term_id ) . '" >' . $category->name.'</a>'; ?></li>
<?php } ?>
</ul>