Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Last active April 4, 2020 21:25
Show Gist options
  • Save Shelob9/8049233 to your computer and use it in GitHub Desktop.
Save Shelob9/8049233 to your computer and use it in GitHub Desktop.
Example code for my Pods Screencast: Using Pods Pages With Advanced Content Types -- http://youtu.be/iUDPYid0bUU
<?php
/**
* Template Name: Ships
*/
get_header(); ?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php
//set find parameters
$params = array( 'limit' => 4 );
//get pods object
$pods = pods( 'spaceship', $params );
//loop through records
if ( $pods->total() > 0 ) {
while ( $pods->fetch() ) {
//Put field values into variables
$title = $pods->display('name');
$permalink = site_url( 'spaceship/' . $pods->field('permalink' ) );
$picture = $pods->field('picture');
$make = $pods->display('make');
$model = $pods->display('model');
$id = $pods->field('id');
?>
<article>
<header class="entry-header">
<?php if ( ! is_null($picture) ) : ?>
<div class="grid">
<div class="col-third">
<div class="entry-thumbnail">
<?php echo wp_get_attachment_image( $picture['ID'] ); ?>
</div>
</div>
<div class="col-2third">
<h1 class="entry-title">
<a href="<?php echo esc_url( $permalink); ?>" rel="bookmark"><?php _e( $title , 'PP2014' ); ?></a>
</h1>
</div>
</div>
<?php else : ?>
<h1 class="entry-title">
<a href="<?php echo $permalink; ?>" rel="bookmark"><?php echo $title; ?></a>
</h1>
<?php endif; ?>
</header><!-- .entry-header -->
<div class="entry-content">
<a href="<?php echo $permalink; ?>" rel="bookmark" class="button primary">Read More</a>
</div><!-- .entry-content -->
</article><!-- #post -->
<?php
} //endwhile
} //endif
//do the pagination
echo $pods->pagination( array( 'type' => 'advanced' ) );
?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
<?php
/**
*
* Template Name: Spaceship Single
*/
get_header();
?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php
//get current url
$slug = pods_v( 'last', 'url' );
//get pod name
$pod_name = pods_v( 0, 'url');
//get pods object for current item
$pods = pods( $pod_name, $slug );
?>
<article>
<?php
//Output template of the same name as Pod, if such a template exists.
$temp = $pods->template($pod_name);
if ( isset($temp) ) {
echo $temp;
}
?>
</article><!-- #post -->
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment