Last active
November 3, 2020 19:38
-
-
Save xnau/ed720d59254a927edb9296fe8fc20a83 to your computer and use it in GitHub Desktop.
Shows how to include a link to the single record in a Participants Database Participant Log global log list.
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 | |
/** | |
* @version 0.1 | |
* | |
* this template shows how to add a link to the single record in a global log list | |
* | |
*/ | |
/** | |
* provides the URL to the single record for the parent record of the log entry | |
* | |
* @global wpdb $wpdb | |
* @param int $entry_id | |
* @param \pbdlog\Log_List $log_list | |
* @return string URL | |
*/ | |
function xnau_get_entry_record_single_link( $entry_id, $log_list ) | |
{ | |
global $wpdb; | |
$record_id = $wpdb->get_var( 'SELECT `record_id` FROM ' . \pdblog\Plugin::log_table_name( $log_list->shortcode_atts['log_name'] ) . ' WHERE `id` = "' . $entry_id . '" LIMIT 1' ); | |
return Participants_Db::single_record_url( $record_id ); | |
} | |
// set this value to point to the field where you want the single record link placed | |
$link_field = 'automobiles_make'; | |
?> | |
<div class="wrap <?php echo $this->wrap_class ?>" id="<?php echo $this->list_anchor ?>"> | |
<?php | |
/* | |
* SEARCH/SORT FORM | |
* | |
* the search/sort form is only presented when enabled in the shortcode. | |
* | |
*/ | |
$this->show_search_sort_form(); | |
/* | |
* GLOBAL LOG DISPLAY | |
* | |
* NOTE: the container for the list itself (excluding search and pagination | |
* controls) must have a class of "list-container" for AJAX search/sort to | |
* function | |
*/ | |
?> | |
<table class="wp-list-table widefat fixed pages list-container" > | |
<?php if ( has_action( 'pdb-prepend_to_list_container_content' ) ) : ?> | |
<caption> | |
<?php do_action( 'pdb-prepend_to_list_container_content' ) ?> | |
<?php $this->print_list_count( '<div class="%s"><span class="list-display-count">' ) ?> | |
</caption> | |
<?php else : ?> | |
<?php | |
/* print the count if enabled in the shortcode | |
* | |
* the tag wrapping the count statment can be supplied in the function argument, example here | |
*/ | |
$this->print_list_count( '<caption class="%s" ><span class="list-display-count">' ); | |
?> | |
<?php endif ?> | |
<?php if ( $record_count > 0 ) : // print only if there are records to show ?> | |
<thead> | |
<tr> | |
<?php | |
/* | |
* this function prints headers for all the fields | |
* replacement codes: | |
* %2$s is the form element type identifier | |
* %1$s is the title of the field | |
*/ | |
$this->print_header_row( '<th class="%2$s" scope="col">%1$s</th>' ); | |
?> | |
</tr> | |
</thead> | |
<tbody> | |
<?php while ( $this->have_records() ) : $this->the_record(); // each record is one row ?> | |
<tr> | |
<?php while ( $this->have_fields() ) : $this->the_field(); // each field is one cell ?> | |
<?php | |
if ( $this->field->name === $link_field ) { | |
$this->field->link = xnau_get_entry_record_single_link( $this->record->record_id, $this ); | |
} | |
?> | |
<td class="<?php echo $this->field->name() ?>-field"> | |
<?php $this->field->print_value() ?> | |
</td> | |
<?php endwhile; // each field ?> | |
</tr> | |
<?php endwhile; // each record ?> | |
</tbody> | |
<?php else : // if there are no records ?> | |
<tbody> | |
<tr> | |
<td><?php if ( $this->is_search_result ) echo Participants_Db::plugin_setting( 'no_records_message' ) ?></td> | |
</tr> | |
</tbody> | |
<?php endif; // $record_count > 0 ?> | |
</table> | |
<?php | |
/* | |
* this shortcut function presents a pagination control with default layout | |
*/ | |
$this->show_pagination_control(); | |
?> | |
</div> |
Be sure to set the value of the $link_field variable to the name of the field where you want your link to the single record to appear.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use this template, dwonload it an upload it to your theme in the custom template location for your site.
Use the template with:
[pdb_log_list log_name=your_log template=single-link]
Read this article if you don't know where to upload the template:
Using Participants Database Custom Templates