douyi9597 2016-10-08 22:33
浏览 23

PHP BootStrap网格

I'm making a WordPress theme and using Advanced Custom Fields I have added a repeater option.

Now the thing is I want to allow the user to add as many "services" as they want but I am not sure how to make this so that bootstrap grids are dynamically created based on the number of services.

I saw this question: Using PHP loop to add Bootstrap rows and proper column numbers to elements But couldn't figure out how to use it properly with what I need.

What I tried was counting the number of services and returning the html from that function.

Then I made a str_replace_first_occurance function that basically did an str_replace on the first occurrence of "Content". And it looped through this the number of services there were.

I guess this should've worked but it became very messy and doesn't seem like the best way to do this.

What's the best way to achieve this?

  • 写回答

2条回答 默认 最新

  • douluan5444 2016-10-09 03:30
    关注

    How many do you want displayed per row? You would most likely want to run a foreach through the array that is given from your ACF repeater. Then put your value inside of the below. I assume you know how to get the php into your front-end?

        <div class="col-lg-4">
            // Content which is your service
        </div>
    

    You could also get the count of the array from your repeater field to figure out how many services were added. Then you could do some logic to figure out if you want it to be a col-lg-3 or a col-lg-4.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用