• Ive been searching online and cant find an answer to this.

    we have our category structure as so

    ->state
    –>NY
    –>CA
    –>FL

    ->Destination
    –>Park
    –>Beach
    –>Movie

    we have about four more groups. so what we want (for this example) is that “state” and “Destination” should not be a link. only the children below it should be.

    is there a way to do this using wp_list_categories()?

    is there another way to do it without using wp_list_categories()?

Viewing 13 replies - 1 through 13 (of 13 total)
  • You could use get_categories and build your own custom category list.

    Thread Starter nozero

    (@nozero)

    in what way …

    Thread Starter nozero

    (@nozero)

    Thanks for your help!

    I wish i knew hoe to read that kind of code. all i know how to do is use the wordpress functions

    Thread Starter nozero

    (@nozero)

    ok i figured it out, thanks.

    so how do i do this that it should know which is the parent not to link it?

    Thread Starter nozero

    (@nozero)

    more clearly.

    i modified the code to this

    ‘ <?php
    ‘ $categories= get_categories(‘parent=0’);
    ‘ foreach ($categories as $cat) {
    ‘ $xyz = $cat->cat_name;
    ‘ $xyz .= ‘ (‘.$cat->category_count.’)’;
    ‘ $xyz .= ”;
    ‘ echo $xyz;
    ‘ }
    ‘ ?>

    the point is to get the top most cats then i will loop through each one to get their children. the problem is that parent=0 doesnt work

    $cat->parent will be equal to zero for a top level category. Otherwise it will be equal to it’s parent’s id.

    Thread Starter nozero

    (@nozero)

    i needed to add hide_empty=0
    because the top cats dont have anything.

    Thread Starter nozero

    (@nozero)

    is there anywhere a list of the information this funstion returns like

    category_count
    cat_name
    etc….

    Try using something like:

    <?php $cats = get_categories();
    echo '<pre>';
    print_r($cats);
    echo '</pre>';?>

    to see the raw data.

    Thread Starter nozero

    (@nozero)

    can you help me out with this code. i dont know php so im not sure whats goign on.

    <?php
    $categories= get_categories(‘parent=0&hide_empty=0’);
    foreach ($categories as $cat) {
    $categorieschild = get_categories(‘child_of=’$cat->cat_ID);
    foreach ($categorieschild as $catchild) {
    $xyz = $catchild->cat_name;
    $xyz .= ‘ (‘.$catchild->category_count.’)’;
    $xyz .= ‘
    ‘;
    echo $xyz;
    }
    }
    ?>

    Thread Starter nozero

    (@nozero)

    it works great the issue is that i was missing a “.” right before “$cat->cat_ID” it works great.

    $categorieschild = get_categories(‘child_of=’$cat->cat_ID);

    Something like:

    <?php
    $output = '';
    $categories = get_categories('hide_empty=0');
    if( $categories ) $output .= '<ul>';
    foreach ($categories as $cat) {
    	$child_cats = get_categories('child_of=' . $cat->cat_ID);
    	if( $child_cats) $output .= '<ul>';
    	foreach ($child_cats as $child) {
    		$output .= '<li><a href="' . get_category_link( $child->term_id ). '">' . $child->cat_name . '</a>';
    		$output .= ' ('.$child->category_count.')</li>';
    	}
    	$output .= '</ul>';
    }
    $output .= '</ul>';
    echo $output;
    ?>

    should output an unordered list of categories with only the child cats having links – but bear in mind that I haven’t tested this so it might contain syntax errors.

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘Parent category not a link’ is closed to new replies.