Jump to content

erikw46

New Members
  • Posts

    1
  • Joined

  • Last visited

    Never

Everything posted by erikw46

  1. 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
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.