Skip to content

Instantly share code, notes, and snippets.

@quasel
Forked from nicdford/page-resources.php
Created December 3, 2015 03:23
Show Gist options
  • Save quasel/ebef95bff18a4b79fbbe to your computer and use it in GitHub Desktop.
Save quasel/ebef95bff18a4b79fbbe to your computer and use it in GitHub Desktop.
A Pods Example on running a loop inside a loop.
<?php
/**
* Template Name: Library Resource List
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages
* and that other 'pages' on your WordPress site will use a
* different template.
*
* @package asotin_county_library
*/
get_header(); ?>
<div id="primary" class="row content-area library-resource-list">
<main id="main" class="site-main columns small-12 medium-8" role="main">
<?php
$params = array(
'limit' => -1,
'expires' => 0
);
$resource_category = pods( 'aclib_resource_category', $params );
if ( 0 < $resource_category->total() ) :
while ( $resource_category->fetch() ) : ?>
<?php $resource_image = $resource_category->field('image'); ?>
<div class="category-heading-contain" id="<?php echo $resource_category->field( 'slug' ); ?>">
<h2>
<?php echo $resource_category->field( 'name' ); ?>
<span class="top"><a href="#top">Back to Top</a></span>
</h2>
<img src="<?=$resource_image['guid'];?>" alt="<?=$resource_image['post_title'];?>">
</div>
<?php
$category_slug = $resource_category->field( 'slug' );
$params = array(
'limit' => -1,
'where' => 'resource_category_item.slug = "' . $category_slug . '"',
'expires' => 0
);
$resources = pods( 'library_resources', $params );
if ( 0 < $resources->total() ) : ?>
<div class="resource-item-container">
<?php while ( $resources->fetch() ) :
$resources_url = $resources->field( 'url' );
$resources_title = $resources->field( 'title' );
$resources_content = $resources->field( 'content' );
?>
<div class="resource-item">
<h3><a href="<?php echo $resources_url; ?>" target="_blank"><?php echo $resources_title; ?></a></h3>
<p><?php echo $resources_content; ?></p>
<a href="<?php echo $resources_url; ?>" target="_blank">Learn More</a>
</div>
<?php endwhile; ?>
</div>
<?php endif;
endwhile;
endif;
?>
</main><!-- #main -->
<div class="section-nav columns medium-4">
<div class="section-nav-contain">
<?php
$params = array(
'limit' => -1,
'expires' => 0
);
$resource_category->find( $params );
if ( 0 < $resource_category->total() ) : ?>
<h3>Jump to a Section</h3>
<ul>
<?php while ( $resource_category->fetch() ) : ?>
<li><a href="#<?php echo $resource_category->field( 'slug' );?>"><?php echo $resource_category->field( 'name' ); ?></a></li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php
$resources->find( array( 'limit' => -1, 'expires' => 0 ) );
?>
<h3>A-Z Index</h3>
<ul>
<?php while ( $resources->fetch() ) : ?>
<li><a href="<?php echo $resources->field( 'url' );?>" target="_blank"><?php echo $resources->field( 'title' ); ?></a></li>
<?php endwhile; ?>
</ul>
</div>
</div>
</div><!-- #primary -->
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment