List Categories Without Links & With Custom Links

An alternative to wp_list_categories() – using get_categories() with a loop can prove to be quite useful in terms of customizing category displays.

Without links:

$args = array(
	'type'                     => 'post',
	'child_of'                 => 7, // set parent category
	'parent'                   => '',
	'orderby'                  => 'name',
	'order'                    => 'ASC',
	'hide_empty'               => 1, // true to hide empty categories
	'hierarchical'             => 1,
	'exclude'                  => '',
	'include'                  => '',
	'number'                   => '',
	'taxonomy'                 => 'category', // category you want to display
	'pad_counts'               => false 

); 


foreach((get_categories($args)) as $category) {
	?><li><?php echo $category->name; ?></li><?php
}

With Custom Links:

$args = array(
	'type'                     => 'post',
	'child_of'                 => 7, // set parent category
	'parent'                   => '',
	'orderby'                  => 'name',
	'order'                    => 'ASC',
	'hide_empty'               => 0, // false to show all categories
	'hierarchical'             => 1,
	'exclude'                  => '',
	'include'                  => '',
	'number'                   => '',
	'taxonomy'                 => 'category', // category you want to display
	'pad_counts'               => false 

); 


foreach((get_categories($args)) as $category) {
	?><li><a href="<?php echo get_permalink(16); ?>"><?php echo $category->name; ?></a></li><?php
}

Modified from source.

Leave a Reply

Posted in php
katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.