Hello everyone,
I have run into a bit of a snag while developing a wordpress site. What I have a is a function that lists all the subcategories of a parent. Each of the categories is displayed as a list item and when clicked they go to that categories page.
However some of the categories that have been created have no posts in them yet so we dont wan't users to go to a category page that has no posts. So we would like for each empty category to not have an anchor around it.
Here is the code that I have been modifying, it is in the functions.php file my custom theme. I feel like it is close but I just cant seem to get it to work.
function servicesList(){
$args = array(
'orderby' => 'id',
'order' => 'ASC',
'child_of' => 8,
'hide_empty' => 0
);
$categories = get_categories($args);
foreach($categories as $category) {
if( empty( $category ) )
echo '<li>' . $category->name.'</li> ';
else
echo '<li><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </li> ';}
}
Any help would be greatly appreciated!
Thanks,
Erik