Reputation: 235
I am trying to create a loop for a group of divs that are being entered in as Pods via Wordpress admin panel.
I have the Pods setup. I could have them setup improperly, but I believe they are setup correctly. I have one Pod and the info is as follows:
Pods Information:
Field 1 Information:
Field 2 Information:
The HTML I am trying to replicate is:
<div class="small-container text-center advisor-list">
<h1 class="text-center">Header Title</h1>
<div class="row gutter-0 padding-30 text-center vpadding-30 ">
<div class="box column large-3 vpadding-10 medium-3 text-center">
<img src="/wp-content/uploads/2013/08/icon-star.png">
<h2>Name</h2>
<h4>Title</h4>
</div>
<div class="box column large-3 vpadding-10 medium-3 text-center">
<img src="/wp-content/uploads/2013/08/icon-star.png">
<h2>Name</h2>
<h4>Title</h4>
</div>
<div class="box column large-3 vpadding-10 medium-3 text-center">
<img src="/wp-content/uploads/2013/08/icon-star.png">
<h2>Name</h2>
<h4>Title</h4>
</div>
<div class="box column large-3 vpadding-10 medium-3 text-center">
<img src="/wp-content/uploads/2013/08/icon-star.png">
<h2>Name</h2>
<h4>Title</h4>
</div>
<button id="showPartners" class="bttn bttn-4 bttn-4a vpadding-30">View Our List of Partners</button>
</div>
This is as far as I have gotten with the PHP:
<div class="small-container text-center advisor-list">
<h1 class="text-center">Header Title</h1>
<div class="row gutter-0 padding-30 text-center vpadding-30 ">
<?php
function get_the_pod($pod_name, $pod_fields, $order = 'name'){
$item_no=0;
$pod = new Pod($pod_name);
$pod->findRecords($order);
while ($pod->fetchRecord()){
foreach ($pod_fields as &$field){
$results[$item_no][str_replace(".guid","",$field)] = $pod->get_field($field);
if($field == end($pod_fields)){$item_no++;}
}
}
return $results;
}
?>
<?php $fields = array('name'); ?>
<?php $advisors = get_the_pod('advisors', 'name DESC'); ?>
<?php foreach($advisors as $advisor){ ?>
<div class="box column large-3 vpadding-10 medium-3 text-center">
<img src="/wp-content/uploads/2013/08/icon-star.png">
<h2 ><?php echo $item['advisor_name']; ?></h2>
<h4><?php echo $item['advisor_title']; ?></h4>
</div>
<?php } ?>
<button id="showPartners" class="bttn bttn-4 bttn-4a vpadding-30">View Our List of Partners</button>
</div>
</div>
If anyone has any input, it would be greatly appreciated.
Thanks
Upvotes: 0
Views: 5823
Reputation: 3018
Pods posts within loop using core Wordpress loop type and structure, you can use it with your own data values
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<div class="entry">
<?php
$team = new Pod('sliders');
$team->findRecords('slider_number ASC');
$total_members = $team->getTotalRows();
?>
<?php if( $total_members>0 ) : ?>
<?php while ( $team->fetchRecord() ) : ?>
<?php
// set our variables
echo $member_id = $team->get_field('id');
echo $member_name = $team->get_field('post_title');
echo $number = $team->get_field('slider_number');
echo $img = $team->get_field('slide_img._img');
?>
<?php endwhile ?>
<?php endif ?>
</div>
</div>
<?php endwhile; endif; ?>
Upvotes: 0
Reputation: 3558
You are using Pods 1.X methods. Here is much simpler code using Pods 2.X methods.
You will want to check out the docs pages for pods()
and pods::find()
, which has the infromation about how to set $param
for pods()
, for more information.
<?php
$param = array( 'orderby' => 't.name' );
$advisors = pods('advisors', $param );
foreach($advisors as $advisor) {
$advisor_name = $advisor->field( 'advisor_name' );
$advisor_title = $advisor->field( 'advisor_title' );
?>
<div class="box column large-3 vpadding-10 medium-3 text-center">
<img src="/wp-content/uploads/2013/08/icon-star.png" />
<h2><?php echo $advisor_name; ?></h2>
<h4><?php echo $advisor_title; ?></h4>
</div>
<?php } //end foreach
?>
Upvotes: 4