Created
March 17, 2021 18:20
-
-
Save xnau/d5c5750b42061f8d1dd0dda9f26fd7c3 to your computer and use it in GitHub Desktop.
Shows how to display a timestamp as a public field in a Participants Database single record display.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @name pdb single template show timestamp | |
* @version 2.0 | |
* | |
* template for displaying a single record | |
* | |
*/ | |
if ( $this->participant_id > 0 ) : | |
?> | |
<div class="wrap <?php echo $this->wrap_class ?>"> | |
<?php while ( $this->have_groups() ) : $this->the_group(); ?> | |
<div class="section <?php $this->group->print_class() ?>" id="<?php echo Participants_Db::$prefix.$this->group->name ?>"> | |
<?php $this->group->print_title( '<h2 class="pdb-group-title">', '</h2>' ) ?> | |
<?php $this->group->print_description() ?> | |
<?php while ( $this->have_fields() ) : $this->the_field(); | |
// CSS class for empty fields | |
$empty_class = $this->get_empty_class( $this->field ); | |
// the public field for showing the timestamp is named "updated_timestamp" | |
if ( $this->field->name() === 'updated_timestamp' ) { | |
$this->field->set_value( $this->participant_values['date_updated'] ); | |
} | |
?> | |
<dl class="<?php echo Participants_Db::$prefix.$this->field->name.' '.$this->field->form_element.' '.$empty_class?>"> | |
<dt class="<?php echo $this->field->name.' '.$empty_class?>"><?php $this->field->print_label() ?></dt> | |
<dd class="<?php echo $this->field->name.' '.$empty_class?>"><?php $this->field->print_value() ?></dd> | |
</dl> | |
<?php endwhile; // end of the fields loop ?> | |
</div> | |
<?php endwhile; // end of the groups loop ?> | |
</div> | |
<?php else : // content to show if no record is found ?> | |
<?php $error_message = Participants_Db::plugin_setting( 'no_record_error_message', '' ); | |
if ( ! empty( $error_message ) ) : ?> | |
<p class="alert alert-error"><?php echo $error_message ?></p> | |
<?php endif ?> | |
<?php endif ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This demonstrates the use of a custom template for showing a value from the record data as a public field.
The template should be called with a shortcode like this: [pdb_single template=show-timestamp]
If you're unfamiliar with the use of Participants Database custom templates read this article:
Using Participants Database Custom Templates