Php ACF repeater字段未呈现行
我有这个网站,我正在为客户工作。我跳进了这个项目,我必须在模板文件上为特定页面创建手风琴。我刚刚开始深入了解PHP,所以在本文中在线找到了一个解决方案 现在,我的问题是: 我用两个子字段创建了repeater字段,并选择它仅显示在此页面模板上 然后,我用该模板在实际页面上创建了字段,并将文章中的代码插入模板文件。当然,我用字段名修改了名称。问题是,在前面,即使行存在,它也不显示行,只是跳转到else语句。我将粘贴该模板页面的完整代码,因此,如果有人能够提供帮助,这将是非常棒的。在这个问题上,我已经绞尽脑汁两天了 代码(我标记了代码的开始和结束位置):Php ACF repeater字段未呈现行,php,wordpress,advanced-custom-fields,Php,Wordpress,Advanced Custom Fields,我有这个网站,我正在为客户工作。我跳进了这个项目,我必须在模板文件上为特定页面创建手风琴。我刚刚开始深入了解PHP,所以在本文中在线找到了一个解决方案 现在,我的问题是: 我用两个子字段创建了repeater字段,并选择它仅显示在此页面模板上 然后,我用该模板在实际页面上创建了字段,并将文章中的代码插入模板文件。当然,我用字段名修改了名称。问题是,在前面,即使行存在,它也不显示行,只是跳转到else语句。我将粘贴该模板页面的完整代码,因此,如果有人能够提供帮助,这将是非常棒的。在这个问题上,我已
尝试将内容包装到:
//所有与帖子相关的内容,包括转发器代码。
这样,转发器将在您当前的帖子/页面范围内。或者,您可以在repeater函数中将post id指定为参数。非常感谢,它解决了问题!!!你能解释一下为什么这是必要的,因为这是一个特定帖子类型的模板,也是一个特定页面模板的模板?在启动这样的循环之前,我是否总是需要检查是否有post;在那里设置所有与文章相关的变量,这样,如果您查看任何标准页面pr文章模板,它也会在与文章相关的内容周围显示这些代码行。也许wordpress codex可以比我解释得更好,所以你可以在那里查找_post函数及其作用:)
<?php
/**
* Template Name: Services
*
**/
global $post;
$post_slug = $post->post_name;
$grandParent_title=get_page(get_ancestors($post->ID,'page')[0] )->post_title;
$grandParent_Image=wp_get_attachment_url( get_post_thumbnail_id(get_ancestors($post->ID,'page')[0] )) ;
get_header();
global $wp;
$current_slug = add_query_arg( array(), $wp->request );
$url_slug=explode('/', $current_slug);
$uri_string=$url_slug[1];
$_SESSION['current_url']=$uri_string;
function find_string_in_array ($arr, $string) {
return array_filter($arr, function($value) use ($string) {
return strpos($value, $string) !== false;
});
}
if(find_string_in_array ($url_slug, 'poly')==true)
{
$nav_theme_location='polystyrene';
$BannerClass='';
$post_type='polystyrene';
$galleryClass='';
}elseif(find_string_in_array ($url_slug, 'fiber')==true){
$nav_theme_location='fiberglass';
$BannerClass='fiberbanner';
$post_type='fiberglass_type';
$galleryClass='fiber';
}elseif (find_string_in_array ($url_slug, 'wood')==true) {
$nav_theme_location='woodwork';
$BannerClass='woodworkbanner';
$post_type='woodworks';
$galleryClass='wood';
}
elseif (find_string_in_array ($url_slug, 'creative')==true) {
$nav_theme_location='creative_production';
$BannerClass='creativebanner';
$post_type='creative_services';
$galleryClass='creative';
}elseif (find_string_in_array ($url_slug, 'f-and-b')==true) {
$nav_theme_location='fb';
$BannerClass='fandbbanner';
$post_type='creative_services';
$galleryClass='';
}else{
$nav_theme_location='';
$BannerClass='';
$post_type='';
$galleryClass='';
}
?>
<section class="banner inner-banner <?= $BannerClass;?>">
<!-- <div class="bannerBox" style="background-image: url(<?php // echo get_the_post_thumbnail_url())?get_the_post_thumbnail_url():;?>)"> -->
<div class="bannerBox" style="background-image: url(<?= (get_the_post_thumbnail_url()!='')?get_the_post_thumbnail_url():$grandParent_Image;?>)">
<div class="bannerContent">
<div class="overlay"></div>
<h1><?= $grandParent_title;?></h1>
</div>
</div>
</section>
<section class="secondrynavigation">
<div class="container">
<div class="innerMenu">
<?php
$args=array(
'theme_location'=>$nav_theme_location,
'container' =>false,
'menu_class' =>'',
);
wp_nav_menu($args);
?>
</div>
</div>
</section>
<section class="pad">
<div class="container-fluid">
<div class="innerHeading">
<h3><?php the_title();?></h3>
<p><?php
$content_post = get_post($post->ID);
echo $content = $content_post->post_content;?></p>
</div>
</div>
<div class="gallery <?= $galleryClass?>">
<div class="container">
<div class="row">
<?php
// echo $post_type;exit;
$loops = new WP_Query(array('posts_per_page'=> -1,
'post_type' => $post_type,
'orderby' => 'id',
'order' => 'asc',
'category_name'=>$uri_string));
// echo "<pre>";
// print_r($loops);exit;
if($loops->have_posts()):
while ($loops->have_posts()) :
$loops->the_post();
global $post;
$post_slug = $post->post_name;
?>
<div class="col-lg-4">
<a href="<?= get_permalink();?>">
<div class="galleryBox">
<div class="overlay">
<p><i>Read More</i></p>
</div>
<div class="image" style="background-image: url(<?= get_the_post_thumbnail_url();?>)"></div>
<div class="galleryText">
<h5><?php the_title();?></h5>
</div>
</div>
</a>
</div>
<?php endwhile;
endif;?>
</div>
</div>
</div>
</section>
<!--MY CODE-->
<?php
if( have_rows('services_accordion') ):
// loop through the rows of data for the tab header
while ( have_rows('services_accordion') ) : the_row();
// $title = get_sub_field('services_title');
// $description = get_sub_field('servises_description');
?>
<button class="accordion"><?php echo get_field('services_title'); ?></button>
<div class="panel">
<p><?php echo get_field('services_description'); ?></p>
</div>
<?php
endwhile;
else :
echo 'In progress';
endif; ?>
<!--MY CODE END-->
<?php get_footer();?>
<?php while (have_posts()) : the_post(); ?>
// all your content related to the post including repeater code.
<?php endwhile; // End of the loop.?>