0

我在 PHP 中有以下内容,使用 Wordpress + Buddypress 插件:

$blogusers = get_users('role=s2member_level1&number=5');
foreach ($blogusers as $user) {
  $username = str_replace('"', '',$user->user_nicename);
  $fullname = str_replace('"', '',bp_profile_field_data( array( 'user_id'=>$user->ID,'field'=>'name' ) ));
  $category = str_replace('"', '',bp_profile_field_data( array( 'user_id'=>$user->ID, 'field'=>'category' ) ));
  echo '<div style="float:left; width:100px; height:100px;">';
  echo '<h3><a href="members/' . $username . '">' . $fullname .  '</a></h3>';
  echo '<strong>Camp Type: </strong>' . $category . '<br />';
  echo '</div>';
}

$fullname 和 $category 变量在 float:left 元素之前被碰撞,但 $username 变量保持在原位,这是所有变量应该呈现的方式。

IE:

<div class="page" id="blog-latest" role="main">
<div style="width:500px;height:100px;position:relative;">
Frank GoreType 4<div style="float:left; width:100px; height:100px;"><h3><a href="members/fgore"></a></h3><strong>Camp Type: </strong><br /></div>
</div>

有什么线索可以解释为什么这两个变量被排除在 echo 语句之外?

4

2 回答 2

0

事实证明,它与 bp_profile_field_data 有关。它是核心用来检索数据的函数。对开发人员更友好的方法 get_bp_profile_field_data 使用起来要好得多。我正在正确格式化所有字符串。不过,我感谢您分享知识。谢谢!

于 2013-03-14T09:08:27.480 回答
0

它与 php 的 echo 构造如何处理连接有关。这对我来说绝对没有意义,但显然,当连接发生时,它会打开一个临时变量来执行组合,然后输出结果。

如果您要使用该语法,请将 echo 语句中的句点替换为逗号。Echo 将逗号分隔的值视为单独的语句,并按接收顺序回显它们。

另外,它的速度要快一点=但每百万个 echo 语句只有 1 秒左右。:)

我首选的方法是创建一个 html 字符串,然后每个逻辑块回显一次。

$echo = '<div style="float:left; width:100px; height:100px;">'
      . '<h3><a href="members/' . $username . '">' . $fullname .  '</a></h3>'
      . '<strong>Camp Type: </strong>' . $category . '<br />'
      . '</div>';
echo $echo;
于 2013-03-14T02:55:48.760 回答