【问题标题】:Advance Custom Fields - All fields from one field group in one frontent array?高级自定义字段 - 一个前端数组中一个字段组的所有字段?
【发布时间】:2015-01-31 15:36:15
【问题描述】:

我必须强调我不是开发人员,所以我可能会使用一些“不受支持”的术语 :)。

好的,我创建了名为 Firm 的自定义帖子类型。我还创建了包含 7 个字段(主要是文本字段,包括网站 URL 字段和 Google 地图字段)的字段组,并且我制作了在前端页面上显示这些字段的模板。保存后,所有数据都将保存在数据库中,并创建帖子类型公司下的新帖子。所以一切都很好。主要问题/问题是:

如何在一页上显示该帖子类型(公司)的所有新帖子?我知道我必须为这些帖子创建一些循环和数组,但正如我所说我不是开发人员,所以我有点坚持这个。

如果有人可以给我一个提示或一些链接,或任何类型的指针,那么我可以弄清楚该往哪个方向发展。提前感谢您的回答。

【问题讨论】:

    标签: arrays wordpress frontend custom-post-type advanced-custom-fields


    【解决方案1】:

    可以参考Wordpress Codex.

    检查下面给出的示例代码

    $args = array( 'post_type' => 'product', 'posts_per_page' => 10 ); // for more parameter check link http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
      the_title();
      // Displays Advanced custom field value
      the_field('field-name');
      echo '<div class="entry-content">';
      the_content();
      echo '</div>';
    endwhile;
    

    【讨论】:

      【解决方案2】:

      好的,到目前为止,谢谢@Arun,我想出了这个:

      <?php
                          $args = array( 'post_type' => 'company', 'posts_per_page' => 10 );
                          $loop = new WP_Query( $args );
                          while ( $loop->have_posts() ) : $loop->the_post();
                            the_title();
                            echo '<div class="entry-content">';
                            echo '<p>' . '<span>Official Wesite</span>' . '<span> : </span>' . get_field('web_site') . '</p>';
                            echo '</div>';
                           endwhile; ?>
      
                          <?php 
      
                          $location = get_field('location');
      
                          if( !empty($location) ):
                          ?>
                          <div class="acf-map">
                              <div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>"></div>
                          </div>
                          <?php endif; ?>
      

      所以我现在正在努力解决如何将这个谷歌地图合并到循环中。我确实有所有帖子的标题和网站链接,但我也需要为每个帖子提供地图。

      【讨论】:

        【解决方案3】:

        好的,这就是我最后所拥有的,它正在工作。

        <?php
                            $args = array( 'post_type' => 'company', 'posts_per_page' => 15 );
                            $loop = new WP_Query( $args );
                            while ( $loop->have_posts() ) : $loop->the_post(); ?>
                            <div class="boxy">
                            <div class="acf_company_name">
                            <h5>Company Name: </h5>
                            <p><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_field('company_name'); ?></a></p>
                            </div>
                            <div class="acf_full_name">
                            <h5>Full Name: </h5>
                            <?php the_field('full_name'); ?>
                            </div>
                            <div class="acf_vat">
                            <h5>VAT: </h5>
                            <?php the_field('vat'); ?>
                            </div>
                            <div class="acf_email">
                            <h5>E-mail: </h5>
                            <a href="mailto:<?php the_field('email'); ?>"><?php the_field('email'); ?></a>
                            </div>
                            <div class="acf_website">
                            <h5>Official website: </h5>
                            <?php the_field('website'); ?>
                            </div>
                            <?php if ( get_field('logo_company') ) : ?>
                            <div class="acf_logo_company"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php $image = get_field(logo_company); ?>
        
                            <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" /></a></div>
                            <?php endif; ?>
        
                            <div class="acf_company_location"><?php $location = get_field('company_location');?>
        
                            <div class="acf-map">
                                <div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>" data-lng="<?php echo $location['address']; ?>"></div>
                            </div></div>
                            <div class="acf_company_location">
                            <h5>Company location: </h5>
                            <?php the_field('company_location'); ?>
                            </div>
                            </div>
                            <?php endwhile; ?>
        

        【讨论】:

          猜你喜欢
          • 2014-07-09
          • 1970-01-01
          • 1970-01-01
          • 2016-05-31
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-08-06
          • 1970-01-01
          相关资源
          最近更新 更多