Syntax help

Hi there,

Can anyone tell me if this line is correct:

                    $output .= '<ul>';
                            foreach ($chunk as $subterms) {
                                $output .= '<li class="'. $category_name .'"><a href="' . get_term_link( $subterms ) . '">' . $subterms->name;
                                if($jobs_counter=='yes'){
                                   $output .= '<span>' . $subterms->count . '</span>';
                                }
                                $output .= '</a></li>';
                            }
                        $output .= '</ul>';

It is outputting the following HTML for the li as a blank class:

<li class="">

Thanks

That suggests that $category_name isn’t what you think it is.
What does var_dump($category_name) tell you?

1 Like

Thanks for the reply.

That outputs:

string(0) "" string(12) "cat-freebies"

which is one of my category names

yeah but it spat 2 things out. an empty string and then cat-freebies.

What is populating $category_name? I suspect we need a little wider view on your code.

Try adding this line to see what is being passed:

echo '<pre>'; print_r($chunk); echo '</pre>'; // pre adds line feeds
foreach ($chunk as $subterms) {
                        

For the benefit of users trying to help, copy and paste the output here.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.