0

我正在尝试为一组通过 Wordpress 管理面板作为 Pod 输入的 div 创建一个循环。

我有 Pods 设置。我可以让它们设置不正确,但我相信它们设置正确。我有一个 Pod,信息如下:

豆荚信息:

  • 标签: 顾问
  • 姓名:顾问
  • 类型:自定义帖子类型
  • 存储类型:元
  • 字段数:2

字段 1 信息:

  • 标签:顾问姓名
  • 名称:advisor_name
  • 字段类型:纯文本

字段 2 信息:

  • 标签:顾问头衔
  • 名称:advisor_title
  • 字段类型:纯文本

我试图复制的 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>

如果有人有任何意见,将不胜感激。

谢谢

4

2 回答 2

4

您正在使用 Pods 1.X 方法。这是使用 Pods 2.X 方法的更简单的代码。您将需要查看pods()和的文档页面pods::find(),其中包含有关如何设置$parampods()信息,以获取更多信息。

         <?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
        ?> 
于 2013-10-15T19:36:43.897 回答
0

使用核心 Wordpress 循环类型和结构在循环内发布 Pod,您可以将其与您自己的数据值一起使用

<?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; ?>
于 2021-09-28T06:46:13.293 回答