使用PHP—;从ACF中提取嵌套转发器内容;关闭标签的问题
我是一个php新手,我很难确定结束标记(主要是div)需要放在这个php中的什么位置,以匹配我在没有动态内容的情况下编写的原始HTML(对于Wordpress站点)。现在我的页脚(下面没有显示)被推来推去,因为页脚太多/不够,并且元素没有正确嵌套 代码的功能是从高级自定义字段中的嵌套转发器中提取信息,循环遍历每个元素并将其放入html结构中 PHP:使用PHP—;从ACF中提取嵌套转发器内容;关闭标签的问题,php,wordpress,nested-loops,advanced-custom-fields,Php,Wordpress,Nested Loops,Advanced Custom Fields,我是一个php新手,我很难确定结束标记(主要是div)需要放在这个php中的什么位置,以匹配我在没有动态内容的情况下编写的原始HTML(对于Wordpress站点)。现在我的页脚(下面没有显示)被推来推去,因为页脚太多/不够,并且元素没有正确嵌套 代码的功能是从高级自定义字段中的嵌套转发器中提取信息,循环遍历每个元素并将其放入html结构中 PHP: 原始HTML: <div class="block_title cf" id="collectie_block_title">Ta
原始HTML:
<div class="block_title cf" id="collectie_block_title">Tassen</div>
<div class="block cf" id="item_block">
<div class="item_block_left cf">
img img img make this a backstretch slideshow that autoplays when item is selected
</div>
<div class="item_block_right cf">
<div class="item_block_right_header cf">
<ul class="item_block_right_header_list">
<li id="product_title">SANNE</li>
<li id="product_subtitle">leren backpack XL</li>
</ul>
<div class="item_block_right_viewoptions">bestellen opties</div>
</div>
<div class="item_block_right_details cf">
<div class="item_block_right_details_specs">
<h5 class="item_block_right_details_specstitle">Lorem Ipsum</h5>
<ul class="item_block_right_details_specslist">
<li>lorem ipsum</li>
<li>lorem ipsum</li>
<li>lorem ipsum</li>
</ul>
</div>
<div class="item_block_right_details_kleuren">
<p id="item_block_right_details_kleuren_title">Kleuren</p>
<div id="item_block_right_details_kleuren_swatches">,.,.,.,.,.,.,</div>
</div>
<div class="item_block_right_details_ordering">
<h5 class="item_block_right_details_orderingtitle">Lorem Ipsum</h5>
<p class="item_block_right_details_orderingp">
All products created through DITT Bags are custom made. Details such as color, size and detailing will be discussed upon the beginning of a new project. To order a bag and begin a new project, send an inquiry to inquiries@dittbags.com
</p>
</div>
</div>
塔森
img img img使其成为一个backstretch幻灯片,在选中项目时自动播放
-
SANNE
leren双肩包XL
- 同侧眼睑
- 同侧眼睑
- 同侧眼睑
通过DITT袋创建的所有产品都是定制的。颜色、尺寸和细节等细节将在新项目开始时讨论。要订购包并开始新项目,请向发送询价inquiries@dittbags.com
谢谢大家 以回音的形式在一行中打开和关闭元素会导致各种问题。这一行是我要避免的主要行(我认为这就是错误所在)
echo'.'Lorem Ipsum'.“.”通过DITT袋创建的所有产品都是定制的。颜色、尺寸和细节等细节将在新项目开始时讨论。若要订购袋并开始新项目,请向发送询价inquiries@dittbags.com“.
”;
下面的代码中肯定有个人偏好,但下面有几个关键点:
您将使用两种类型的PHP文件。一种用于视图(在其中呈现HTML),另一种仅用于逻辑。您的文件更像是以逻辑风格编写的,其中所有内容都封装在一个巨大的PHP标记中
如果您要呈现一个视图,我建议打开和关闭每行逻辑的PHP
这有助于以更容易的方式阅读文件。我知道有很多打开和关闭操作,但当您查看时,我想您会同意这更容易解释
最重要的一点-缩进-执行上述操作意味着您可以保持打开和关闭标记正确缩进,并且可以更轻松地查看元素打开和关闭的位置
下面是我将如何编写这个文件。我没有测试这个文件,因为我没有数据来呈现它,但它向您展示了这个概念,缩进让我相信它是正确的
<?php if (have_rows('pSect')): ?>
<?php while (have_rows('pSect')) : ?>
<?php the_row(); ?>
<?php $productSectionTitle = get_sub_field('pSecTitle'); ?>
<div class="block_title cf" id="collectie_block_title"><?php echo $productSectionTitle; ?></div>
<?php if (have_rows('prods')) : ?>
<?php while (have_rows('prods')): ?>
<?php the_row(); ?>
<?php $products = get_sub_field('prods'); ?>
<div class="block cf" id="item_block">
<?php if (have_rows('indivProd')): ?>
<?php while (have_rows('indivProd')): ?>
<?php the_row(); ?>
<?php
$individualProduct = get_sub_field('indivProd');
$images = get_sub_field('images');
?>
<?php if ($images): ?>
<?php foreach ($images as $image): ?>
<?php $full_image_url = $image['url']; ?>
<div class="item_block_left bstretchMe cf" data-img-src="<?php echo $full_image_url; ?>"></div>
<?php endforeach; ?>
<?php endif; ?>
<?php
$productName = get_sub_field('product_name');
$productType = get_sub_field('product_type');
?>
<div class="item_block_right cf">
<div class="item_block_right_header cf">
<ul class="item_block_right_header_list">
<li id="product_title"><?php echo $productName; ?></li>
<li id="product_subtitle"><?php $productType; ?></li>
</ul>
</div>
<div class="item_block_right_viewoptions">bestellen opties</div>
</div>
<div class="item_block_right_details cf">
<div class="item_block_right_details_specs">
<h5 class="item_block_right_details_specstitle">Lorem Ipsum</h5>
<ul class="item_block_right_details_specslist">
<?php if (have_rows('detailList')): ?>
<?php while (have_rows('detailList')): ?>
<?php the_row(); ?>
<?php
$bijzonderheden = get_sub_field('bijzonderheden');
$message = "working!?";
?>
<li><?php echo $bijzonderheden; ?></li>;
<?php endwhile; ?>
<?php endif; ?>
</ul>
</div>
<div class="item_block_right_details_kleuren cf">
<p id="item_block_right_details_kleuren_title">Kleuren</p>
<?php if (have_rows('colOps')): ?>
<?php while (have_rows('colOps')): ?>
<?php the_row(); ?>
<?php $colorPick = get_sub_field('cPick'); ?>
<div id="item_block_right_details_kleuren_swatches" style="background-color:<?php echo $colorPick; ?>"></div>
<?php endwhile; ?>
<?php endif; ?>
</div>
<div class="item_block_right_details_ordering">
<h5 class="item_block_right_details_orderingtitle">Lorem Ipsum</h5>
<p class="item_block_right_details_orderingp">
All products created through DITT Bags are custom made. Details such as color, size and detailing will be discussed upon the beginning of a new project. To order a bag and begin a new project, send an inquiry to inquiries@dittbags.com
</p>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
您的输出HTML是什么样子的?是的!这非常有帮助。这似乎也是ACF建议的方式。一种方式对页面性能比另一种方式更好吗?我开始用这种方式编写php,因为我读到它对页面加载速度更有利。但我确实明白为什么您的建议更清晰。很高兴id有用:)。
<?php if (have_rows('pSect')): ?>
<?php while (have_rows('pSect')) : ?>
<?php the_row(); ?>
<?php $productSectionTitle = get_sub_field('pSecTitle'); ?>
<div class="block_title cf" id="collectie_block_title"><?php echo $productSectionTitle; ?></div>
<?php if (have_rows('prods')) : ?>
<?php while (have_rows('prods')): ?>
<?php the_row(); ?>
<?php $products = get_sub_field('prods'); ?>
<div class="block cf" id="item_block">
<?php if (have_rows('indivProd')): ?>
<?php while (have_rows('indivProd')): ?>
<?php the_row(); ?>
<?php
$individualProduct = get_sub_field('indivProd');
$images = get_sub_field('images');
?>
<?php if ($images): ?>
<?php foreach ($images as $image): ?>
<?php $full_image_url = $image['url']; ?>
<div class="item_block_left bstretchMe cf" data-img-src="<?php echo $full_image_url; ?>"></div>
<?php endforeach; ?>
<?php endif; ?>
<?php
$productName = get_sub_field('product_name');
$productType = get_sub_field('product_type');
?>
<div class="item_block_right cf">
<div class="item_block_right_header cf">
<ul class="item_block_right_header_list">
<li id="product_title"><?php echo $productName; ?></li>
<li id="product_subtitle"><?php $productType; ?></li>
</ul>
</div>
<div class="item_block_right_viewoptions">bestellen opties</div>
</div>
<div class="item_block_right_details cf">
<div class="item_block_right_details_specs">
<h5 class="item_block_right_details_specstitle">Lorem Ipsum</h5>
<ul class="item_block_right_details_specslist">
<?php if (have_rows('detailList')): ?>
<?php while (have_rows('detailList')): ?>
<?php the_row(); ?>
<?php
$bijzonderheden = get_sub_field('bijzonderheden');
$message = "working!?";
?>
<li><?php echo $bijzonderheden; ?></li>;
<?php endwhile; ?>
<?php endif; ?>
</ul>
</div>
<div class="item_block_right_details_kleuren cf">
<p id="item_block_right_details_kleuren_title">Kleuren</p>
<?php if (have_rows('colOps')): ?>
<?php while (have_rows('colOps')): ?>
<?php the_row(); ?>
<?php $colorPick = get_sub_field('cPick'); ?>
<div id="item_block_right_details_kleuren_swatches" style="background-color:<?php echo $colorPick; ?>"></div>
<?php endwhile; ?>
<?php endif; ?>
</div>
<div class="item_block_right_details_ordering">
<h5 class="item_block_right_details_orderingtitle">Lorem Ipsum</h5>
<p class="item_block_right_details_orderingp">
All products created through DITT Bags are custom made. Details such as color, size and detailing will be discussed upon the beginning of a new project. To order a bag and begin a new project, send an inquiry to inquiries@dittbags.com
</p>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>