1

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.com/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'); ?>

Garden Tips ACF Group

Any help on above would be greatly appreciated

Thanks

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. Feb 4, 2021 at 22:17

1 Answer 1

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'); ?>
2
  • All working except the banner image appearing Feb 5, 2021 at 11:54
  • @NeilKearney Sorry I missed the image part, I've updated the answer but you were basically using get_sub_field( 'banner_image' ) instead of get_field( 'banner_image' ) - The image isn't within a repeater field so that's why nothing was being returned. My answer also only shows the banner if one has been added. The image field itself also requires the image array selected as the return format. Feb 5, 2021 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.