Php 如何在循环中设置html布局
我想在循环中为多个类别设置一个html布局视图。我的html代码在这里…有许多类别来自(wp admin)woocommerce。给定的代码是如何在Php 如何在循环中设置html布局,php,wordpress,loops,for-loop,categories,Php,Wordpress,Loops,For Loop,Categories,我想在循环中为多个类别设置一个html布局视图。我的html代码在这里…有许多类别来自(wp admin)woocommerce。给定的代码是如何在home.php中显示我的类别的布局,因此我想通过循环在home.php中添加更多类别。谢谢 我的html代码到目前为止 <div class="selected-products-wrapper clearfix"> <div class="category-list"> <span class
home.php
中显示我的类别的布局,因此我想通过循环在home.php
中添加更多类别。谢谢
我的html代码到目前为止
<div class="selected-products-wrapper clearfix">
<div class="category-list">
<span class="category-main" style="background-color: #5D973E">
<div class="category-main_logo">
<img src="" alt="" class="v-middle"></div>
<span class="category-main-title">
<a href="<?php
echo get_term_link($cat->slug, 'product_cat');
?>">
<?php echo $cat->name; ?></a></span>
<div class="category-main-yakataheader"><img src=""></div>
</span>
<ul class="sub-category-list">
<li><a href="#"><?php echo $sub_category ->name; ?></a></li>
</ul>
<a href="#" class="view-all">View all</a>
</div>
<div class="images-list">
<a href="" class="large-img">
<img src="" alt="Confectionery"
class="v-middle lazy-img" height="351" width="290">
</a>
<span class="small-img-block">
<a href="">
<img src="" alt="Fruits & Veggies"
class="v-middle lazy-img" height="175" width="171">
</a>
<a href="">
<img src="" alt="Noodles"
class="v-middle lazy-img" height="175" width="171">
</a>
</span>
<span class="center_img-block">
<a href="">
<img src="" alt="Oats"
class="v-middle lazy-img" height="175" width="344">
</a>
<a href="">
<img src="" alt="Ofada"
class="v-middle lazy-img" height="175" width="344">
</a>
</span>
<span class="small-img-block last-img-block">
<a href="">
<img src="" alt="Cooking Oils"
class="v-middle lazy-img" height="175" width="171">
</a>
<a href="">
<img src="" alt="Seasoning"
class="v-middle lazy-img" height="175" width="171">
</a>
</span>
</div>
<div class="alt-images-block">
<a href="">Fruits & Veggies</a>
<a href="">Noodles</a>
<a href="">Cooking Oils</a>
<a href="">Seasoning</a>
</div>
</div>
您需要使用要重复的数据创建一个自定义php函数
e、 g
//您要重复的html代码位于此处。
那你就可以用
<?php
repeat_category();
?>
无论您希望html代码出现在何处。将此函数作为常用函数,并将该函数返回到您想要的任何位置?谢谢@fresh。请告诉我…我是初学者。我无法理解复杂的理论以实际的方式讲述(代码)。我以为你是老板?你想重复什么代码?
<?php
repeat_category();
?>