为了账号安全,请及时绑定邮箱和手机立即绑定

如何显示多个连续的html元素

如何显示多个连续的html元素

PHP
梵蒂冈之花 2021-05-05 21:34:09
我在我的wordpress网站上使用ACF在搜索栏中显示HTML文本,该文本位于基于该posts数组值的帖子标题旁边。现在,脚本最多只能显示html值之一,但是我希望它包括所有存在的html值。add_filter( 'asp_results', 'asp_custom_field_to_results', 10, 1 ); function asp_custom_field_to_results( $results ) {  $custom_field = 'trade_status';   foreach ($results as $k=>&$r) {    if ($r->content_type != 'pagepost') continue;    if ( function_exists('get_field') )        $trade_status  = get_field( $custom_field, $r->id, true ); // ACF support    else        $trade_status  = get_post_meta( $r->id, $custom_field, true );    // Modify the post title to add the meta value    if ( !empty($trade_status) ) {      if ( in_array('30', $trade_status) ) {        $html = '<span class="new">New</span>';      } else if ( in_array('20', $trade_status) ) {        $html = '<span class="active">Active</span>';      } else if ( in_array('10', $trade_status) ) {        $html = '<span class="closed">Closed</span>';      } else {        $html = '';      }      $r->title = $html . $r->title;    }  }  return $results;}
查看完整描述

1 回答

?
慕后森

TA贡献1802条经验 获得超5个赞

因此,看起来现在您正在为循环中的每个匹配迭代覆盖$ html的值。我的猜测是,在执行此操作时,您想连接(。=)而不是覆盖(=)。


查看完整回答
反对 回复 2021-05-21
  • 1 回答
  • 0 关注
  • 205 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信