This function creates <li> tags and im trying to give each li tag a unique CSS class name,
I’ve tried to create a for loop to generate numbers but this is producing the number 7 rather than counting down to the number 7 in <li> tag.
any help greatly appreciated!
function the_meta() {
if ( $keys = get_post_custom_keys() ) {
echo "<ul class='post-meta'>\n";
//tried to add this counter here to generate incremental numbers in the foreach loop
for ($i = 0; $i <= 6; $i++) { }
foreach ( (array) $keys as $key ) {
$keyt = trim($key);
if ( is_protected_meta( $keyt, 'post' ) )
continue;
$values = array_map('trim', get_post_custom_values($key));
$value = implode($values,', ');
echo apply_filters('the_meta_key', "<li class='$i'><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value);
}
echo "</ul>\n";
}
}
This line of code:
Will just increase $i until it get to 6,
So when you’re getting to the “main loop” the variable
$iwill have the same value.Why having another loop to count?
You can implement the counter inside your current loop: