Blog

PodsCast #004: Pods’ify My Theme! Displaying Data in Pods Pt 2

We’ll continue where we left off from the prior PodsCast by digging deeper into the Pods class functions within your theme to show your Pods Data. Using live code examples, we’ll also show how to do common things with your Pods data like Pagination, Image & Media handling, Relationships and Taxonomy.

This is a live event, which will be held on Tuesday April 21st at 2PM eastern (6PM UTC), so you can join in and ask the Pods team any questions you have about how to get your Pods data into your WordPress Themes. Future PodsCast’s in this series will include handling of Shortcodes and Widgets, Pods Templates & Frontier and the Pods JSON API. There will be live music and live coding!

If you are watching live, you can ask questions in the #podscast channel of our Slack or by tweeting them at us. All episodes of the Podscast can be viewed at any time on our Youtube channel.

Show Notes

Archive Video (archive-video.php) Example Archive using Pods API [direct link to Gist]:


<?php
/*
Template Name: Video Archive
*/
?>
<?php get_header(); ?>
<!– Row for main content area –>
<div class="small-12 large-8 columns" id="content" role="main">
<h1>All Videos</h1>
<?php /* Start the Pods Loop */
// Pulling PODS Loop instead of WP Loop
$mypod = pods('video');
$params = array(
/* 'limit' => -1, /* Change to Posts per page */
/* 'limit' => get_option('posts_per_page',15), /* Change to Posts per page */
'limit' => 2,
);
$mypod->find($params);
?>
<?php while ( $mypod->fetch() ) : ?>
<?php
// set our variables
$video = $mypod->id();
$title = $mypod->display('title');
$permalink = $mypod->display('permalink');
$actors = $mypod->field('related_actors');
$imagehtml = get_the_post_thumbnail( $video, 'full', array( 'class' => 'thumbnail' ));
?>
<article>
<header>
<a href="<?php echo esc_url($permalink); ?>" title="<?php echo esc_attr($title); ?>">
<?php echo $imagehtml; ?>
<h2 class="entry-title"><?php echo $title; ?></h2>
</a>
</header>
</article>
<?php endwhile; ?>
<?php echo $mypod->pagination(); ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Single Video Detail (single-video.php) using Pods API [direct link to Gist]


<?php
/*
Template Name: Video Detail
*/
?>
<?php get_header(); ?>
<!– Row for main content area –>
<div class="small-12 large-8 columns" id="content" role="main">
<?php /* Initiate the Pods Object */
// get the current slug
global $post;
// get pods object
// $post->post_type can be used instead of the pod name, ie 'video'
$mypod = pods( $post->post_type, $post->ID );
$video = $mypod->id();
$title = $mypod->display('title');
$permalink = $mypod->display('permalink');
$imagehtml = get_the_post_thumbnail( $video, 'thumb', array( 'class' => 'thumbnail' ));
?>
<article>
<header>
<h1 class="entry-title">
<a href="<?php echo esc_url($permalink); ?>" title="<?php echo esc_attr($title); ?>"><?php echo $title; ?></a>
</h1>
<div class="entry-thumb"><?php echo $imagehtml; ?></div>
<?php
/* Add Taxonomy */
$genres = get_the_term_list($post->ID,'genre',"Categories: ", " / ","");
?>
<p class="categories"><?php echo $genres; ?></p>
</header>
<div class="entry-content">
<?php
/* Output the Actors */
/* not sorted */
/* $actors = $mypod->field('related_actors'); */
/* This is is an array, so must be field;
if you're doing local, print_r will let you see the keys of the array
*/
/* Build Param for sorting Actors */
$param = array( 'orderby' => 't.post_title ASC' );
$actors = $mypod->field('related_actors', $param);
if (! empty( $actors )) { ?>
<h3>Actors in Movie:</h3>
<ul id="actor-list">
<?php
foreach ( $actors as $actor ) {
$id = $actor[ 'ID' ];
$title = $actor[ 'post_title' ];
echo '<li><a href="' .esc_url(get_permalink( $id )). '">' .get_the_title( $id ). '</a></li>';
}
echo '</ul>';
}
?>
</div>
<footer>
</footer>
</article>
<?php comments_template(); ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Single Actor Detail (single-actor.php) Example using Pods API [Direct link to Gist]


<?php
/*
Template Name: Actor Detail
*/
?>
<?php get_header(); ?>
<!– Row for main content area –>
<div class="small-12 large-8 columns" id="content" role="main">
<?php /* Initiate the Pods Object */
// get the current slug
/* $slug = pods_v( 'last', 'url' ); */
global $post;
// get pods object
$mypod = pods( $post->post_type, $post->ID );
$actor = $mypod->id();
$title = $mypod->display('title');
$permalink = $mypod->display('permalink');
$videos = $mypod->field('related_videos');
?>
<article>
<header>
<h1 class="entry-title">
<a href="<?php echo $permalink; ?>"><?php echo $title; ?></a>
</h1>
</header>
<div class="entry-content">
<?php /* Output the Movies */
if (! empty( $videos )) { ?>
<h3>Movies:</h3>
<ul id="movie-list">
<?php
foreach ( $videos as $video ) {
$id = $video[ 'ID' ];
echo '<li><a href="' .get_permalink( $id ). '">' .get_the_title( $id ). '</a></li>';
}
}
?>
</div>
<footer>
</footer>
</article>
<?php comments_template(); ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>