Home » Topics » Pods 1.x » output pod at table using shortcode?
output pod at table using shortcode?
This topic contains 6 replies, has 3 voices, and was last updated by creativenadir 3 years, 8 months ago.
-
AuthorPosts
-
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 this
September 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>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
[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>
<td>{@name}</td>
<td>{@body}</td>
</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 #158175i will need to incorporate a loop into this somehow i believe because i want something more like this
<tr>
<td>[instructor1]</td>
<td>instructor 2}</td>
<td>[instructor 3</td>
</tr>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 #158176Ah, 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>
{@name,start_cell} {@body,end_cell}
</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:"start_cell":<pre><?php
(int)$_GET['cell_count']++;
$_GET['cell_modulus'] = $_GET['cell_count'] % 4;
if ($_GET['cell_modulus'] == 1)
{
echo "<tr>";
}
echo "<td>", $value;
?></pre>
"end_cell":<pre><?php
echo $value, "</td>";
if (($_GET['cell_modulus'] % 4) == 0)
{
echo "</tr>n";
}
else if ($Record->getTotalRows() == $_GET['cell_count'])
{
while (5 > ++$_GET['cell_modulus'])
{
echo "<td></td>";
}
echo "</tr>n";
}
?></pre>
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 #158171I 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
Thank
Ps – wondering why the site is so slow late at night?
September 4, 2009 at 5:06 am #158177Well, 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)
{
echo "</tr>n";
}
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
{
echo "<td></td>";
}
echo "</tr>n";
}
?></pre> -
AuthorPosts
You must be logged in to reply to this topic.