2 个嵌套转发器中的高级自定义字段 post object 不工作
Advanced Custom Field post object inside 2 nested repeater is not working
我正在努力实现这样的目标。我正在尝试将 post object 作为中继器显示在 2 个嵌套中继器字段中。我正在使用此中继器和 post object 在名为 page-bagels.php 的页面模板中。这 2 个中继器按预期显示第 2 行输出。但是 post object 没有显示或没有返回值。相反,它是页面的返回值。就像我用过的地方一样,它返回页面标题而不返回 post object 标题。我的代码如下
<?php while ( have_posts() ) : the_post(); ?>
<div class="main-content">
<div class="main-wrap">
<div class="col-sm-12">
<div class="breadcrumbs">
<?php if(function_exists('bcn_display'))
{
bcn_display();
}?>
</div> <!-- breadcrambs ends here -->
</div><!-- col-sm-12 ends here -->
<?php
// check for rows (parent repeater)
if( have_rows('product_page') ): ?>
<div class="col-lg-12 row product-row">
<?php
// loop through rows (parent repeater)
while( have_rows('product_page') ): the_row(); ?>
<div class="col-sm-12">
<div class="marque">
<span class="brand-lg"><img src="<?php the_sub_field('brand_image'); ?>" /></span>
</div>
</div>
<?php
// check for rows (sub repeater)
if( have_rows('post_repeater') ): ?>
<div class="col-sm-12 product-item-row">
<?php
// loop through rows (sub repeater)
while( have_rows('post_repeater') ): the_row();?>
<div class="col-sm-3 product-item">
<?php
$postobject = get_sub_field('product_post'); ?>
<a href="<?php $postURL = get_permalink($postobject->ID);?>">
<img class="product-img" src="<?php bloginfo('template_directory');?>/images/product-images/321600_moelleux_blanc_trepais.png" width="100%" />
<p class="product-name"><?php the_title();?></p>
<p class="product-seemore">See More</p>
</a>
</div><!-- col ends here -->
<?php endwhile; ?>
</div><!-- col Product Items row here -->
<?php endif; //if( get_sub_field('items') ): ?>
<?php endwhile; // while( has_sub_field('to-do_lists') ): ?>
</div><!-- col lg 12 ends here or row ends here -->
<?php endif; // if( get_field('to-do_lists') ): ?>
<?php endwhile; // end of the loop. ?>
<div class="lnk-top">
<a href="#"><span class="icon-arrow-up up-arrow"></span><br>Top</a>
</div>
</div><!-- main wrap ends here -->
<div class="clr"></div>
</div><!-- main content ends here -->
所以在这段代码中你可以看到 post object 也是一个中继器..所以这意味着我正在使用 3 个中继器。如果你看到代码,你就会得到它
这是我得到的输出 http://ahsanurrahman.com/myprojects/cms/wp/gadoua/en/bagels/
非常感谢您的帮助。
我能够为您修复它。请参阅下面的代码
<?php while ( have_posts() ) : the_post(); ?>
<div class="main-content">
<div class="main-wrap">
<div class="col-sm-12">
<div class="breadcrumbs">
<?php if(function_exists('bcn_display'))
{
bcn_display();
}?>
</div> <!-- breadcrambs ends here -->
</div><!-- col-sm-12 ends here -->
<?php
// check for rows (parent repeater)
if( have_rows('product_page') ): ?>
<div class="col-lg-12 row product-row">
<?php
// loop through rows (parent repeater)
while( have_rows('product_page') ): the_row(); ?>
<div class="col-sm-12">
<div class="marque">
<span class="brand-lg"><img src="<?php the_sub_field('brand_image'); ?>" /></span>
</div>
</div>
<?php
// check for rows (sub repeater)
if( have_rows('post_repeater') ): ?>
<div class="col-sm-12 product-item-row">
<?php
// loop through rows (sub repeater)
while( have_rows('post_repeater') ): the_row();?>
<div class="col-sm-3 product-item">
<?php
$postobject = get_sub_field('product_post');
$image = wp_get_attachment_image_src(get_post_thumbnail_id( $postobject->ID ),'medium');
//echo "<pre>";print_r($postobject); echo"</pre>";
$image = $image[0];
//$new = get_field('new_product_item');
//echo $image;
?>
<a href="<?php echo get_permalink($postobject->ID);?>">
<?php if ( get_field( 'new_product_item',$postobject->ID) ): ?>
<img class="new-label-en" src="<?php bloginfo('template_directory');?>/images/label-en.png" />
<img class="new-label-fr" src="<?php bloginfo('template_directory');?>/images/label-fr.png" />
<img class="product-img" src="<?php echo $image;?>" width="100%" height="100%" />
<p class="product-name"><?php echo $postobject->post_title;?></p>
<p class="product-seemore"><?php echo $product_details_link_text;?></p>
<?php else: // field_name returned false ?>
<img class="product-img" src="<?php echo $image;?>" width="100%" height="100%" />
<p class="product-name"><?php echo $postobject->post_title;?></p>
<p class="product-seemore"><?php echo $product_details_link_text;?></p>
</a>
<?php endif; //if( get_sub_field): ?>
</div><!-- col ends here -->
<?php endwhile; ?>
</div><!-- col Product Items row here -->
<?php endif; //if( get_sub_field('items') ): ?>
<?php endwhile; // while( has_sub_field('to-do_lists') ): ?>
</div><!-- col lg 12 ends here or row ends here -->
<?php endif; // if( get_field('to-do_lists') ): ?>
<?php endwhile; // end of the loop. ?>
<div class="lnk-top">
<a href="#"><span class="icon-arrow-up up-arrow"></span><br>Top</a>
</div>
</div><!-- main wrap ends here -->
<div class="clr"></div>
</div><!-- main content ends here -->
我正在努力实现这样的目标。我正在尝试将 post object 作为中继器显示在 2 个嵌套中继器字段中。我正在使用此中继器和 post object 在名为 page-bagels.php 的页面模板中。这 2 个中继器按预期显示第 2 行输出。但是 post object 没有显示或没有返回值。相反,它是页面的返回值。就像我用过的地方一样,它返回页面标题而不返回 post object 标题。我的代码如下
<?php while ( have_posts() ) : the_post(); ?>
<div class="main-content">
<div class="main-wrap">
<div class="col-sm-12">
<div class="breadcrumbs">
<?php if(function_exists('bcn_display'))
{
bcn_display();
}?>
</div> <!-- breadcrambs ends here -->
</div><!-- col-sm-12 ends here -->
<?php
// check for rows (parent repeater)
if( have_rows('product_page') ): ?>
<div class="col-lg-12 row product-row">
<?php
// loop through rows (parent repeater)
while( have_rows('product_page') ): the_row(); ?>
<div class="col-sm-12">
<div class="marque">
<span class="brand-lg"><img src="<?php the_sub_field('brand_image'); ?>" /></span>
</div>
</div>
<?php
// check for rows (sub repeater)
if( have_rows('post_repeater') ): ?>
<div class="col-sm-12 product-item-row">
<?php
// loop through rows (sub repeater)
while( have_rows('post_repeater') ): the_row();?>
<div class="col-sm-3 product-item">
<?php
$postobject = get_sub_field('product_post'); ?>
<a href="<?php $postURL = get_permalink($postobject->ID);?>">
<img class="product-img" src="<?php bloginfo('template_directory');?>/images/product-images/321600_moelleux_blanc_trepais.png" width="100%" />
<p class="product-name"><?php the_title();?></p>
<p class="product-seemore">See More</p>
</a>
</div><!-- col ends here -->
<?php endwhile; ?>
</div><!-- col Product Items row here -->
<?php endif; //if( get_sub_field('items') ): ?>
<?php endwhile; // while( has_sub_field('to-do_lists') ): ?>
</div><!-- col lg 12 ends here or row ends here -->
<?php endif; // if( get_field('to-do_lists') ): ?>
<?php endwhile; // end of the loop. ?>
<div class="lnk-top">
<a href="#"><span class="icon-arrow-up up-arrow"></span><br>Top</a>
</div>
</div><!-- main wrap ends here -->
<div class="clr"></div>
</div><!-- main content ends here -->
所以在这段代码中你可以看到 post object 也是一个中继器..所以这意味着我正在使用 3 个中继器。如果你看到代码,你就会得到它
这是我得到的输出 http://ahsanurrahman.com/myprojects/cms/wp/gadoua/en/bagels/
非常感谢您的帮助。
我能够为您修复它。请参阅下面的代码
<?php while ( have_posts() ) : the_post(); ?>
<div class="main-content">
<div class="main-wrap">
<div class="col-sm-12">
<div class="breadcrumbs">
<?php if(function_exists('bcn_display'))
{
bcn_display();
}?>
</div> <!-- breadcrambs ends here -->
</div><!-- col-sm-12 ends here -->
<?php
// check for rows (parent repeater)
if( have_rows('product_page') ): ?>
<div class="col-lg-12 row product-row">
<?php
// loop through rows (parent repeater)
while( have_rows('product_page') ): the_row(); ?>
<div class="col-sm-12">
<div class="marque">
<span class="brand-lg"><img src="<?php the_sub_field('brand_image'); ?>" /></span>
</div>
</div>
<?php
// check for rows (sub repeater)
if( have_rows('post_repeater') ): ?>
<div class="col-sm-12 product-item-row">
<?php
// loop through rows (sub repeater)
while( have_rows('post_repeater') ): the_row();?>
<div class="col-sm-3 product-item">
<?php
$postobject = get_sub_field('product_post');
$image = wp_get_attachment_image_src(get_post_thumbnail_id( $postobject->ID ),'medium');
//echo "<pre>";print_r($postobject); echo"</pre>";
$image = $image[0];
//$new = get_field('new_product_item');
//echo $image;
?>
<a href="<?php echo get_permalink($postobject->ID);?>">
<?php if ( get_field( 'new_product_item',$postobject->ID) ): ?>
<img class="new-label-en" src="<?php bloginfo('template_directory');?>/images/label-en.png" />
<img class="new-label-fr" src="<?php bloginfo('template_directory');?>/images/label-fr.png" />
<img class="product-img" src="<?php echo $image;?>" width="100%" height="100%" />
<p class="product-name"><?php echo $postobject->post_title;?></p>
<p class="product-seemore"><?php echo $product_details_link_text;?></p>
<?php else: // field_name returned false ?>
<img class="product-img" src="<?php echo $image;?>" width="100%" height="100%" />
<p class="product-name"><?php echo $postobject->post_title;?></p>
<p class="product-seemore"><?php echo $product_details_link_text;?></p>
</a>
<?php endif; //if( get_sub_field): ?>
</div><!-- col ends here -->
<?php endwhile; ?>
</div><!-- col Product Items row here -->
<?php endif; //if( get_sub_field('items') ): ?>
<?php endwhile; // while( has_sub_field('to-do_lists') ): ?>
</div><!-- col lg 12 ends here or row ends here -->
<?php endif; // if( get_field('to-do_lists') ): ?>
<?php endwhile; // end of the loop. ?>
<div class="lnk-top">
<a href="#"><span class="icon-arrow-up up-arrow"></span><br>Top</a>
</div>
</div><!-- main wrap ends here -->
<div class="clr"></div>
</div><!-- main content ends here -->