Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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