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
1 Answer
Reset to default 1You'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'); ?>