最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Multiple ACF Repeaters within a Custom Post Type

programmeradmin0浏览0评论

I am trying to create a single post template for the custom post type Garden Tips (single-garden-tip.php)

The url to this page is:

/

When I render my code its blank so wondering what I am missing or what I need to do to resolve this issue

Code for template


<?php get_template_part('header'); ?>

<?php get_template_part('includes/inner-post-header'); ?>

<section class="e-blog-v3 garden-set-pd-sm-lg">
    <div class="container">
        <div class="row">
            <div class="col-sm-12">

            <?php while ( have_posts() ) : the_post(); ?>

                <?php if( have_rows('garden_tips') ): ?>
                
                   <?php $image = get_sub_field('banner_image');?>
                   <?php echo wp_get_attachment_image( $image, 'medium_large' ); ?>

                
                <h6>Flowers</h6>
                 <ul class="garden_tips_list">
                            <?php while( have_rows('flowers') ): the_row(); ?>
                            <li>
                                <i class="fas fa-leaf"></i> <?php the_sub_field('flower_tip'); ?>
                            </li>
                            <?php endwhile; ?>
                    </ul>


                <h6>Fruit and Veg</h6>
                <ul class="garden_tips_list">
                            <?php while( have_rows('fruit_veg') ): the_row(); ?>
                            <li>
                                <i class="fas fa-leaf"></i> <?php the_sub_field('fruit_veg_tip'); ?>
                            </li>
                            <?php endwhile; ?>
                    </ul>

            <h6>Greenhouse</h6>
                <ul class="garden_tips_list">
                            <?php while( have_rows('greenhouse') ): the_row(); ?>
                            <li>
                                <i class="fas fa-leaf"></i> <?php the_sub_field('fruit_veg_tip'); ?>
                            </li>
                            <?php endwhile; ?>
                    </ul>

            <h6>Garden Maintenance</h6>
                <ul class="garden_tips_list">
                            <?php while( have_rows('garden_maintenance') ): the_row(); ?>
                            <li>
                                <i class="fas fa-leaf"></i> <?php the_sub_field('fruit_veg_tip'); ?>
                            </li>
                            <?php endwhile; ?>
                    </ul>
                <?php endif; ?>

            <?php endwhile; // end of the loop. ?>

            </div>
        </div>
</section>


<?php get_template_part('footer'); ?>

Any help on above would be greatly appreciated

Thanks

I am trying to create a single post template for the custom post type Garden Tips (single-garden-tip.php)

The url to this page is:

http://evergreenhorticulture-co-uk.stackstaging/garden-tip/january/

When I render my code its blank so wondering what I am missing or what I need to do to resolve this issue

Code for template


<?php get_template_part('header'); ?>

<?php get_template_part('includes/inner-post-header'); ?>

<section class="e-blog-v3 garden-set-pd-sm-lg">
    <div class="container">
        <div class="row">
            <div class="col-sm-12">

            <?php while ( have_posts() ) : the_post(); ?>

                <?php if( have_rows('garden_tips') ): ?>
                
                   <?php $image = get_sub_field('banner_image');?>
                   <?php echo wp_get_attachment_image( $image, 'medium_large' ); ?>

                
                <h6>Flowers</h6>
                 <ul class="garden_tips_list">
                            <?php while( have_rows('flowers') ): the_row(); ?>
                            <li>
                                <i class="fas fa-leaf"></i> <?php the_sub_field('flower_tip'); ?>
                            </li>
                            <?php endwhile; ?>
                    </ul>


                <h6>Fruit and Veg</h6>
                <ul class="garden_tips_list">
                            <?php while( have_rows('fruit_veg') ): the_row(); ?>
                            <li>
                                <i class="fas fa-leaf"></i> <?php the_sub_field('fruit_veg_tip'); ?>
                            </li>
                            <?php endwhile; ?>
                    </ul>

            <h6>Greenhouse</h6>
                <ul class="garden_tips_list">
                            <?php while( have_rows('greenhouse') ): the_row(); ?>
                            <li>
                                <i class="fas fa-leaf"></i> <?php the_sub_field('fruit_veg_tip'); ?>
                            </li>
                            <?php endwhile; ?>
                    </ul>

            <h6>Garden Maintenance</h6>
                <ul class="garden_tips_list">
                            <?php while( have_rows('garden_maintenance') ): the_row(); ?>
                            <li>
                                <i class="fas fa-leaf"></i> <?php the_sub_field('fruit_veg_tip'); ?>
                            </li>
                            <?php endwhile; ?>
                    </ul>
                <?php endif; ?>

            <?php endwhile; // end of the loop. ?>

            </div>
        </div>
</section>


<?php get_template_part('footer'); ?>

Any help on above would be greatly appreciated

Thanks

Share Improve this question asked Feb 4, 2021 at 15:16 Neil KearneyNeil Kearney 132 bronze badges 1
  • Neil, it's always best to ask questions pertaining to third-party plugins directly with the developers of that third-party plugin. They're far better informed about their code base than the standard WordPress developer. – Tony Djukic Commented Feb 4, 2021 at 22:17
Add a comment  | 

1 Answer 1

Reset to default 1

You've mixed a few things up in your template

The opening repeater field for example you have called garden_tips after the name of the ACF Field Group instead of the name of the repeater

Eg:

therefore you need to remove that and the closing <?php endif; ?> which related to it further down the template.

Then look at each section eg: Flowers and do something like this

<?php if( have_rows('flowers') ): ?>
 <h6>Flowers</h6>
 <ul class="garden_tips_list">
  <?php while( have_rows('flowers') ): the_row(); ?>
  <li>
   <i class="fas fa-leaf"></i> <?php the_sub_field('flower_tip'); ?>
  </li>
  <?php endwhile; ?>
 </ul>
<?php endif; ?>

You'll need to do this for each section.

With the banner, this isn't inside a repeater and you're using get_sub_field instead of get_field.

You should also make sure you return the image Object, rather than the ID or URL (its in the settings of the field) then use something like this for getting the image url itself

$banner = get_field( 'banner_image' ) ? : false;
if( $banner ):
    $bannerSize = 'medium_large';
    $bannerUrl = $banner['sizes'][$bannerSize];
    $bannerAlt = $banner['title'];?>
<img src="<?php echo $bannerUrl;?>" alt="<?php echo $bannerAlt;?>">
<?php endif;?>

Overall, it should be something like this

    <?php get_template_part('header'); ?>
        
        <?php get_template_part('includes/inner-post-header'); ?>
        
        <section class="e-blog-v3 garden-set-pd-sm-lg">
          
          <div class="container">
            
            <div class="row">
              
              <div class="col-sm-12">
                
                <?php while ( have_posts() ) : the_post(); ?>
        
                  $banner = get_field( 'banner_image' ) ? : false;
        if( $banner ):
            $bannerSize = 'medium_large';
            $bannerUrl = $banner['sizes'][$bannerSize];
            $bannerAlt = $banner['title'];?>
<img src="<?php echo $bannerUrl;?>" alt="<?php echo $bannerAlt;?>">
<?php endif;?>
    
    
                  
                  <?php if( have_rows('flowers') ): ?>
                  <h6>Flowers</h6>
                  <ul class="garden_tips_list">
                  <?php while( have_rows('flowers') ): the_row(); ?>
                    <li>
                      <i class="fas fa-leaf"></i> <?php the_sub_field('flower_tip'); ?>
                    </li>
                  <?php endwhile; ?>
                  </ul>
                  <?php endif; ?>
        
                  
                  <?php if( have_rows('fruit_veg') ): ?>
                  <h6>Fruit and Veg</h6>
                  <ul class="garden_tips_list">
                  <?php while( have_rows('fruit_veg') ): the_row(); ?>
                    <li>
                      <i class="fas fa-leaf"></i> <?php the_sub_field('fruit_veg_tip'); ?>
                    </li>
                  <?php endwhile; ?>
                  </ul>
                  <?php endif; ?>
        
        
                  <?php if( have_rows('greenhouse') ): ?>
                  <h6>Greenhouse</h6>
                  <ul class="garden_tips_list">
                    <?php while( have_rows('greenhouse') ): the_row(); ?>
                    <li>
                      <i class="fas fa-leaf"></i> <?php the_sub_field('fruit_veg_tip'); ?>
                    </li>
                    <?php endwhile; ?>
                  </ul>
                  <?php endif; ?>
        
                            
                  <?php if( have_rows('garden_maintenance') ): ?>
                  <h6>Garden Maintenance</h6>
                  <ul class="garden_tips_list">
                    <?php while( have_rows('garden_maintenance') ): the_row(); ?>
                    <li>
                      <i class="fas fa-leaf"></i> <?php the_sub_field('fruit_veg_tip'); ?>
                    </li>
                    <?php endwhile; ?>
                  </ul>
                  <?php endif; ?>
        
        
                <?php endwhile; // end of the loop. ?>
        
            </div>
          </div>
        </section>
        
        <?php get_template_part('footer'); ?>
发布评论

评论列表(0)

  1. 暂无评论
ok 不同模板 switch ($forum['model']) { /*case '0': include _include(APP_PATH . 'view/htm/read.htm'); break;*/ default: include _include(theme_load('read', $fid)); break; } } break; case '10': // 主题外链 / thread external link http_location(htmlspecialchars_decode(trim($thread['description']))); break; case '11': // 单页 / single page $attachlist = array(); $imagelist = array(); $thread['filelist'] = array(); $threadlist = NULL; $thread['files'] > 0 and list($attachlist, $imagelist, $thread['filelist']) = well_attach_find_by_tid($tid); $data = data_read_cache($tid); empty($data) and message(-1, lang('data_malformation')); $tidlist = $forum['threads'] ? page_find_by_fid($fid, $page, $pagesize) : NULL; if ($tidlist) { $tidarr = arrlist_values($tidlist, 'tid'); $threadlist = well_thread_find($tidarr, $pagesize); // 按之前tidlist排序 $threadlist = array2_sort_key($threadlist, $tidlist, 'tid'); } $allowpost = forum_access_user($fid, $gid, 'allowpost'); $allowupdate = forum_access_mod($fid, $gid, 'allowupdate'); $allowdelete = forum_access_mod($fid, $gid, 'allowdelete'); $access = array('allowpost' => $allowpost, 'allowupdate' => $allowupdate, 'allowdelete' => $allowdelete); $header['title'] = $thread['subject']; $header['mobile_link'] = $thread['url']; $header['keywords'] = $thread['keyword'] ? $thread['keyword'] : $thread['subject']; $header['description'] = $thread['description'] ? $thread['description'] : $thread['brief']; $_SESSION['fid'] = $fid; if ($ajax) { empty($conf['api_on']) and message(0, lang('closed')); $apilist['header'] = $header; $apilist['extra'] = $extra; $apilist['access'] = $access; $apilist['thread'] = well_thread_safe_info($thread); $apilist['thread_data'] = $data; $apilist['forum'] = $forum; $apilist['imagelist'] = $imagelist; $apilist['filelist'] = $thread['filelist']; $apilist['threadlist'] = $threadlist; message(0, $apilist); } else { include _include(theme_load('single_page', $fid)); } break; default: message(-1, lang('data_malformation')); break; } ?>