The PDb_Template helper class makes setting up a custom display for a Participants Database record much easier in situations where you don’t want to just loop through the values. Sometimes you don’t want to treat each value the same, you want to lay out each value in a way that fits the information better. This is demonstrated for a single record in the post Using the PDb_Template class in your custom templates.
You can also do something like that in the list template by instantiating the PDb_Template class for each record in the list.
First, make sure all the fields you want to display are configured to be included. You can do this either on the Manage Database Fields page (using the “display” column) or in the list shortcode with the “fields” or “groups” attributes. This is explained here…
How the List Template Works
The list template works by looping through each record in the list, whether it’s showing all the records or a search result. Normally, for each record, there is another loop that shows the field values of that record. This is very flexible and convenient, but it may not give you the look you want in your results because each value is treated the same visually.
In this post, I’ll demonstrate a simple application of the use of the PDb_Template class to lay out the record’s values in a different way. Let’s say you’re using Participants Database as a directory, a list of people who offer a service, for instance. For this, each record is going to be displayed as a set of contact information something like this:
Bernard Carmen
Chiropractic, Physical Therapy
Scottsdale, Arizona
Email: drcarmen@therapycenter.co
Phone: 002-332-2212
Doing something like that is simply a matter of figuring out the HTML you want to use to display the record, then use the template class to fill in the values. In our template, we will use HTML like this to show each record:
<h3>Bernard Carmen</h3>
<h5>Chiropractic, Physical Therapy</h5>
<p>Scottsdale, Arizona</p>
<p><em>Email: drcarmen@therapycenter.co</em><br />
<em>Phone: 002-332-2212</em></p>
In the template, using the helper class, that will look like this:
<?php
// instantiate the helper class
$record = new PDb_Template( $this );
?>
<h3><?php $record->print_value( 'first_name' ) ?> <?php $record->print_value( 'last_name' ) ?></h3>
<h5><?php $record->print_value( 'services_offered' ) ?></h5>
<p><?php $record->print_value( 'city' ) ?>, <?php $record->print_value( 'state' ) ?></p>
<p><em>Email: <?php $record->print_value( 'email' ) ?><br />
Phone: <?php $record->print_value( 'phone' ) ?></em></p>
The Custom List Template
Below, we show the complete list template so you can see how that fits in. We’re using the “responsive” list template for our stating point, since it’s already set up to show each record as a block of data instead of a row in a table. The individual record display code happens after line 80.
Excellent… used this logic to grasp the flow and it lead me to a simple solution for dynamically adding FlipBook html embedding in detail pages. Glad I spotted it.
Hey off topic but Have to ask… is your site email having issues today? I tried to send an email to support-at-xnau.dot-com and it bounced back. I had a question about RadioButton Validation seeming to make a unique indexing restriction that I wanted to ask you off-line but….
Great plug-in, by the way. You are saving us old RMDB web coders a lot of frustration with having to use wordpress.
I do have intermittent issues with the site, typically only lasts for a minute or two, suprising that it would affect email, though. Anyway, I’d encourage you to try again.
must be me. got your email but host not found for replying to webdesign@ and support@. I hope you can delete this and the previous from this page’s comments so it doesn’t get in other folks’ way… after you let me know the best page to add a comment about RadioButton field with Validation enabled causing what looks like an unique index (can only add one record for any of the radioButton types). Thanks (sorry to others for this sidetrack)
Best place to post questions about Participants Database is in the WordPress Support Forum
Have a question for the true coders here… I have limited experience and hoping someone can point me in the right direction. We are trying to use the database to store athletes data collected during testing events. The goal is to have the information spit out into our WordPress site similar to the NFL Combine layout (see here: https://www.nfl.com/prospects/zack-baun?id=32194241-5567-7316-c31c-c66079e71b79). I have imported a bunch of data, created the WordPress page layout I want to try, but can’t seem to figure out how to get it to pull the data from the database. Assume I would need to create a template? Or is there a simple Shortcode per field to add into the various sections that will display the data when a players name is clicked? Looking for some guidance if I didn’t confuse the life out of you with this.
James, I suggest you start by following the Setup Guide that is in the admin plugin menu. That will give you the basic setup, which includes the ability to list records and provides a link to the full details of each record. Once you have that in place, you’ll be ready to take it to the next step, customizing the display. For that, depending on how ambitious your plans are, need an understanding of php, CSS and HTML. This article explains how to set up a custom template:
Using Participants Database Custom Templates
Roland, first let me say i’m finally getting into this plugin and really loving it! Great job!
Okay, now, for my [pdb_list] i’m trying to do a rather customized php print…
For my building drop-down, my “Options” has something like this: Mitchell Physics Building::MPHY
So, in the database, it shows just “MPHY” but not the whole long text…
My question is do you have a helper class that can print the DB value instead of the selection value? Thank you, sir!
If you want the raw value, you can get it in the values property of the PDb_Template object:
values['building'] ?>
where ‘building’ is the name of the field.
Hello, this is very helpful. I was wondering if you had a list of the ways values could be printed? For instance, my “photos” and “website” column aren’t printing correctly when I use print_value. Are there different methods for those?
Thank you!
To be a bit more clear (I felt my question was lacking information)
https://xnau.com/work/wordpress-plugins/participants-database/participants-database-documentation/participants-database-api/the-template-helper-class/
Using any of the printing methods seems to just give a blank result, when the data is in the database. Other plain-text inputs are showing up properly
Make sure that all the fields you want to display are configured to appear in the list. I’m going to add a note to the article that explains this.
Ah, that makes sense. Got it – Thank you!
Roland,
This example is a great help. What if I still have more information shown on a single record basis (that I don’t want to show in the full listing)? How do you invoke the URL so that it makes the column you have chosen to be your link to the single record listing an actual link to take the browser to the page?
Very appreciative of this plugin and your educational posts!
Brian
The helper class has a method for that. For instance if from our example, you wanted to link the name to the detail page, you’d do it like this:
Aha!
Thanks Roland!
Brian