output pod at table using shortcode?
September 2, 2009 at 1:09 pm #158172
i want to break up the table into 4 items per row so i have to loop through the list of instructors to do thisSeptember 2, 2009 at 6:41 pm #158173
@kemcadams – In order to format shortcode results as a table you’ll need to wrap them in the appropriate tags whenever you call them in a WP page or post, like:<pre><table>
[pods name="event" order="id DESC" limit="10" template="event_list"]
</table></pre>(I’ve included a header row for completeness)
Then you’ll use your template ("event_list", for example) to format the output of each pod entry’s columns as individual rows, like:<pre><tr>
</tr></pre>September 3, 2009 at 9:37 am #158174
@kemcadams – FYI: the site should load a lot faster now.September 4, 2009 at 2:27 am #158175
i will need to incorporate a loop into this somehow i believe because i want something more like this
I want to print out 4 instructors per row – rather than one row per instructor.
How would I do this with templates and shortcode??
ThankSeptember 4, 2009 at 4:17 am #158176
Ah, ok; buckle your seatbelt, cause this might get a bit tricky…
We can’t put any loop logic into the body of your page or post (at least, not without the Exec-PHP plugin – http://wordpress.org/extend/plugins/exec-php/), nor can we put it in the template. But we CAN put it in Display Helpers; so let’s do that.
Continuing my example above, leave the page/post shortcode the same, but change the "event_list" template to include some display helpers:<pre>
We’ll let our display helpers handle the output our row tags. Since the template gets called for each item, we’ve essentially got some loop logic built in. We just need to save its state across successive calls in a global variable. I’m a fan of using $_GET in this instance since it’s destroyed between successive page calls:
$_GET['cell_modulus'] = $_GET['cell_count'] % 4;
if ($_GET['cell_modulus'] == 1)
echo "<td>", $value;
echo $value, "</td>";
if (($_GET['cell_modulus'] % 4) == 0)
else if ($Record->getTotalRows() == $_GET['cell_count'])
while (5 > ++$_GET['cell_modulus'])
DISCLAIMER: this is totally untested psuedocode, so YMMV. I /believe/ that Pods shortcode uses a variable called $Record as its internal reference and that it’s publicly available in this context, but this may take some tweaking.September 4, 2009 at 5:06 am #158171
I want to output my instructor pod as a table. It has over 30 entries and I want to use templates, shortcode and helpers to do this. This is my second project with pods and I am wondering if this is possible or not. I want to add several fields to the table cell content and want to avoid another pod page to do so if possible
Ps – wondering why the site is so slow late at night?September 4, 2009 at 5:06 am #158177
Well, shoot. I just tested this a bit, and it looks like $Record goes out of scope during the execution of Display Helpers.
So let’s flip the script a little: we already know the total number of items we’re going to retrieve, because we set it in the "limit = 10" statement of our shortcode. So just replace the "end_cell" Display Helper above with this one which (unfortunately) hard-codes the total number of records into the loop and fixes a couple mistakes:<pre><?php
echo $value, "</td>";
if ($_GET['cell_modulus'] == 0)
else if (10 == $_GET['cell_count']) // Set to the total number of items
while (5 > ++$_GET['cell_modulus']) // Set to the number of items per row + 1
You must be logged in to reply to this topic.