简体   繁体   中英

Adding <details></details> to one specific Buddypress Xprofile field (profile-loop.php)

If special xprofile field with id=10 has data then output following:

<tr<?php bp_field_css_class(); ?>>

    <td class="label"><?php bp_the_profile_field_name(); ?></td>

    <td class="data"><details><?php bp_the_profile_field_value(); ?></details></td>

</tr>

for all other xprofile fields with data the output should be:

<tr<?php bp_field_css_class(); ?>>

    <td class="label"><?php bp_the_profile_field_name(); ?></td>

    <td class="data"><?php bp_the_profile_field_value(); ?></td>

</tr>

How should I change the second while loop in the buddypress profile-loop.php?

<div class="bp-widget <?php bp_the_profile_group_slug(); ?>">

  <h2><?php bp_the_profile_group_name(); ?></h2>

  <table class="profile-fields">

    <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>

      <?php if ( bp_field_has_data() ) : ?>

        <tr<?php bp_field_css_class(); ?>>

          <td class="label"><?php bp_the_profile_field_name(); ?></td>

          <td class="data"><?php bp_the_profile_field_value(); ?></td>

        </tr>

      <?php endif; ?>

      <?php

      do_action( 'bp_profile_field_item' ); ?>

    <?php endwhile; ?>

  </table>
</div>

I just solved it using bp_get_the_profile_field_id() :

<div class="bp-widget <?php bp_the_profile_group_slug(); ?>">
  <h2><?php bp_the_profile_group_name(); ?></h2>
    <table class="profile-fields">
      <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>
      <?php if ( bp_get_the_profile_field_id() != '273' AND bp_field_has_data()) : ?>
      <tr<?php bp_field_css_class(); ?>>
        <td class="label"><?php bp_the_profile_field_name(); ?></td>
        <td class="data"><?php bp_the_profile_field_value(); ?></td>
      </tr>
      <?php else : ?>
      <tr<?php bp_field_css_class(); ?>>
        <td class="label"><?php bp_the_profile_field_name(); ?></td>
        <td class="data"><details><summary>Anzeigen</summary><?php bp_the_profile_field_value(); ?></details></td>
      </tr>
      <?php endif;?>
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM