在视觉作曲中显示wordpress分类法

时间:2013-03-07 09:23:08

标签: php wordpress function

i have a line in visual composer for wordpress which is as follows

$teasers .= '<li class="xyz">'; 

there is another piece of code :


foreach ( (array) get_object_taxonomies($post->post_type) as $taxonomy ) {
  $object_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'all'));
  if ($object_terms) {
    echo 'data-'. $taxonomy.'="';
    foreach ($object_terms as $term)
    {
         echo $term->name.' , ';         
    }

    echo '" ';
  }  
}

this code results some thing like this 

data-minimum_qualification="10+2 , " data-stream="Commerce , Humanities (Arts) , " data-minimum_qualification="Graduate , Graduate+ , "


Now what i want is, the result of second code to append inside the first code i.e. in the li tags which would result the following 

<li class="xyz" data-minimum_qualification="10+2 " data-stream="Commerce , Humanities (Arts)" data-minimum_qualification="Graduate , Graduate+" > 

Any kind of help would be great

1 个答案:

答案 0 :(得分:0)

试试这个:

$teasers .= '<li class="xyz" '; 

foreach ( (array) get_object_taxonomies($post->post_type) as $taxonomy ) {
  $object_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'all'));
  if ($object_terms) {
    $teasers .= 'data-'. $taxonomy.'="';
    foreach ($object_terms as $term)
    {
         $teasers .= $term->name.' , ';         
    }

    echo '" ';
  }  
}
$teasers .= '>';

没有对它进行测试,但它应该可行