Rjfec
May 10, 2012, 9:18pm
1
Right now, the current code causes this affect *notice the <li> wrapping all the <a>. I would like to be able to wrap each <a> in its own <li>
<ul>
<li>
<a href='http://test>Test/a>
<a href='http://test>Test/a>
<a href='http://test>Test/a>
</li>
</ul>
here is the php code
$a[] = "<a href='$tag_link' class='tag-link-$tag_id'>$tag</a>";
}
switch ( $format ) :
case 'array' :
$return =& $a;
break;
case 'list' :
$return = "<ul class='wp-tag-cloud'>\
\ <li>";
$return .= join("<li>\
\ </li>", $a);
$return .= "</li>\
</ul>\
";
break;
default :
$return = join("\
", $a);
break;
endswitch;
Thanks for any help.
Rjfec
May 11, 2012, 12:53pm
2
Any suggestions on how I can get the <li> to wrap around each <a> link instead of all of them?
I would actually need to see a little more of the code (I’m not sure what $format does, or if it’s already in a loop), but you basically need to use a foreach…loop on $a, and wrap it that way. Something like:
case 'list':
$return .= '<ul class="wp-tag-cloud">';
//Add each list element
foreach($a as $link){
$return .= '<li>'.$link.'</li>';
}
$return .= '</ul>';
break;
Rjfec
May 11, 2012, 1:29pm
4
Thanks Carlos, here is the other part of the code. Im not sure what the $format does. Can I have two foreach since there is already one?
$a = array();
$rel = ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) ? ' rel="tag"' : '';
foreach ( $counts as $tag => $count ) {
$tag_id = $tag_ids[$tag];
$tag_link = esc_url($tag_links[$tag]);
$tag = str_replace(' ', ' ', esc_html( $tag ));
$a[] = "<a href='$tag_link' class='tag-link-$tag_id'>$tag</a>";
}
switch ( $format ) :
case 'array' :
$return =& $a;
break;
case 'list' :
$return = "<ul class='wp-tag-cloud'>\
\ <li>";
$return .= join("<li>\
\ </li>", $a);
$return .= "</li>\
</ul>\
";
break;
default :
$return = join("\
", $a);
break;
endswitch;
Yep, you can even have a foreach inside a foreach! I was just curious with the $format in there…
That code I gave you above should work. Try replacing:
case 'list' :
$return = "<ul class='wp-tag-cloud'>\
\ <li>";
$return .= join("<li>\
\ </li>", $a);
$return .= "</li>\
</ul>\
";
break;
with
case 'list':
$return .= '<ul class="wp-tag-cloud">';
//Add each list element
foreach($a as $link){
$return .= '<li>'.$link.'</li>';
}
$return .= '</ul>';
break;
Rjfec
May 11, 2012, 1:45pm
6
Oddly enough, it is still wrapping all of them :(.
Strange, I’m sure it has something to do with $format. Can you try something for me, try replacing:
All this:
switch ( $format ) :
case 'array' :
$return =& $a;
break;
case 'list' :
$return = "<ul class='wp-tag-cloud'>\
\ <li>";
$return .= join("<li>\
\ </li>", $a);
$return .= "</li>\
</ul>\
";
break;
default :
$return = join("\
", $a);
break;
endswitch;
with:
$return .= '<ul class="wp-tag-cloud">';
//Add each list element
foreach($a as $link){
$return .= '<li>'.$link.'</li>';
}
$return .= '</ul>';
If it works, then it’s definitely the $format variable not selecting “list”. It’s not a permanent fix, but it would help us know where to go next.
Rjfec
May 11, 2012, 2:00pm
8
That got me an undefined variable for this line
$return .= '<ul class="wp-tag-cloud">';
. I searched the entire document for any other $format and could not come up with one.
Oops, remove the period next to the equal sign in that line. Only in that line though.
Rjfec
May 11, 2012, 2:43pm
10
that did the trick Maybe $format is a variable defined in the wp_tag_cloud. I found the post where someone is doing something similar, but $format is not defined.