PodsCast #3 Displaying Data Index & Archive Template

This particular template is based off of Twenty Fifteen and works for both the Single & Index/Archive & Search.

This particular template is based off of Twenty Fifteen and works for both the Single & Index/Archive & Search.

<?php
/**
 * The default template for displaying content
 *
 * Used for both single and index/archive/search.
 *
 * @package WordPress
 * @subpackage Twenty_Fifteen
 * @since Twenty Fifteen 1.0
 */
?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
	<?php
		// Post thumbnail.
		twentyfifteen_post_thumbnail();
	?>

	<header class="entry-header">
		<?php
			if ( is_single() ) :
				the_title( '<h1 class="entry-title">', '</h1>' );
			else :
				the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' );
			endif;
		?>
	</header><!-- .entry-header -->

	<div class="entry-content">
		<?php
			/* translators: %s: Name of current post */
			the_content( sprintf(
				__( 'Continue reading %s', 'twentyfifteen' ),
				the_title( '<span class="screen-reader-text">', '</span>', false )
			) );
			wp_link_pages( array(
				'before'      => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentyfifteen' ) . '</span>',
				'after'       => '</div>',
				'link_before' => '<span>',
				'link_after'  => '</span>',
				'pagelink'    => '<span class="screen-reader-text">' . __( 'Page', 'twentyfifteen' ) . ' </span>%',
				'separator'   => '<span class="screen-reader-text">, </span>',
			) );
		?>
	</div><!-- .entry-content -->

	<?php if ( is_single() || is_singular() ) : ?>
		<?php
			// Setup the Pods object
			$pods = pods( get_post_type(), get_the_ID() );
			if ( ! empty( $pods ) ) :
		?>
			<div class="my-custom-fields">
				<dl>
					<dt>
						Teams:
					</dt>
					<dd>
						<?php
							// Core WP term usage
							$teams = wp_get_object_terms( get_the_ID(), 'teams', array( 'fields' => 'names' ) );
							$teams = implode( ', ', $teams );
							echo strip_tags( $teams );
							// Pods API usage
							$teams = $pods->field( 'teams' );
							$format = '<a href="%s">%s</a>';
							foreach ( $teams as $k => $team ) {
								$team[$k] = sprintf(
									$format,
									esc_url( get_term_link( $team['term_id'], 'teams' ) ),
							        strip_tags( $team['name'] )
								);
								$team[$k] = '<a href="' . esc_url( get_term_link( $team['term_id'], 'teams' ) ) . '">'
											. strip_tags( $team['name'] ) . '</a>';
							}
						?>
					</dd>

					<dt>
						Size:
					</dt>
					<dd>
						<?php
							// Core WP meta usage
							$size = get_post_meta( get_the_ID(), 'size', true );
							// Pods API usage
							$size = $pods->display( 'size' );
							// Or get all meta (very minor performance difference)
							// $all_meta_fields = get_post_meta( get_the_ID() );
							// $size = $all_meta_fields['size'];
							// $related_post = $all_meta_fields['related_post'];
							echo esc_html( $size );
						?>
					</dd>

					<dt>
						Related Item:
					</dt>
					<dd>
						<?php
							// Core WP meta usage
							// Single
							// Pods stores raw related IDs as _pods_{field_name}
							$related_post = get_post_meta( get_the_ID(), 'related_post', true );
							// Core WP meta usage
							echo get_the_title( $related_post );
							// Pods API usage
							echo $pods->display( 'related_post' ); // Outputs post_title
							// Core WP meta usage
							$another_field = get_post_meta( $related_post, 'another_field', true );
							// Pods API usage
							$another_field = $pods->display( 'related_post.another_field' );
						?>

						(Another Field: <?php echo esc_html( $another_field ); ?>)
					</dd>

					<dt>
						Related Items:
					</dt>
					<?php
						// Core WP meta usage
						// Multiple
						$related_posts = get_post_meta( get_the_ID(), 'related_posts' );
						foreach ( $related_posts as $related_post ) {
							echo '<dd>' . get_the_title( $related_post ) . '</dd>';
						}
					?>
				</dl>
			</div>
		<?php endif; ?>
	<?php endif; ?>

	<?php
		// Author bio.
		if ( is_single() && get_the_author_meta( 'description' ) ) :
			get_template_part( 'author-bio' );
		endif;
	?>

	<footer class="entry-footer">
		<?php twentyfifteen_entry_meta(); ?>
		<?php edit_post_link( __( 'Edit', 'twentyfifteen' ), '<span class="edit-link">', '</span>' ); ?>
	</footer><!-- .entry-footer -->

</article><!-- #post-## -->

 

Questions