我正在尝试为通过Wordpress管理面板作为Pod输入的一组div创建一个循环。
我有Pods设置。我可以让它们设置不正确,但我相信它们设置正确。我有一个Pod,信息如下:
Pods信息:
字段1信息:
字段2信息:
我想复制的HTML是:
<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>
据我所知,这是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>
如果有人有任何意见,我们将不胜感激。
由于
答案 0 :(得分:3)
您正在使用Pods 1.X方法。这是使用Pods 2.X方法的更简单的代码。
您需要查看pods()
和pods::find()
的文档页面,其中包含有关如何为$param
设置pods()
的信息,以获取更多信息。
<?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
?>