开发者

Why is foreach loop outputting double sets of li tags?

开发者 https://www.devze.com 2023-03-26 21:20 出处:网络
Apologies for the noob question, but... In wordpress 3.2.1开发者_如何学Go, using wp-e-commerce: I\'m using the following code to output a field from an indexed array as an unordered list.

Apologies for the noob question, but...

In wordpress 3.2.1开发者_如何学Go, using wp-e-commerce:

I'm using the following code to output a field from an indexed array as an unordered list.

function tag_badges() {
  global $wpdb, $post;
  $tags = wp_get_product_tags($post->ID);
  foreach($tags as $key)
    // print_r ($key->name);
  echo "<li>$key->name<li/>";
}

This sort of works. But I'm getting an empty set of li tags for every tag that has a set.

e.g.

  • value1
  • value2
  • value3
  • When I output just the keys without markup, it just returns the three values that are in the array, e.g.

    Key: Value1 Key: Value2 Key: Value3

    so I'm fairly sure it's not because there are empty fields being output.


    You just did a minor error in your output, you didn't close the li tag but added a new one:

    echo "<li>$key->name<li/>";
    #                      ^
    

    To fix, move the / to the beginning of the second li tag to make it actually a closing tag:

    echo "<li>$key->name</li>";
    #                    ^
    
    0

    精彩评论

    暂无评论...
    验证码 换一张
    取 消