Skip to content

Instantly share code, notes, and snippets.

@xnau
Last active May 20, 2017 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xnau/4f19d08b7e240d81df2f1c5e2681b227 to your computer and use it in GitHub Desktop.
Save xnau/4f19d08b7e240d81df2f1c5e2681b227 to your computer and use it in GitHub Desktop.
A single record template that shows a person's age.
<?php
/*
* default template for displaying a single record
*
* This one calculates a person's age from a field named "birthdate" and shows it in a field named "age"
*/
$record = new PDb_Template( $this );
$date_field = 'birthdate';
$age_field = 'age';
?>
<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 );
if ( $this->field->name === $age_field ) {
$this->field->value = date('y') - date( 'y', $record->get_value( $date_field ) );
}
?>
<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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment