druybew06513 2013-08-11 18:26
浏览 5

任何人都可以解释这个PHP?

<ul class="top_ads">
    <?php
        $totalImages = 5;
        $all = range(1,$totalImages);
        shuffle($all);

        foreach ($all as $single) {
            echo "<li><a href='' /><img src='"; echo bloginfo('template_url') . "/images/ads/ad_0$single.png' alt='ad' /></li>";
        }
    ?>
</ul>

can anyone please explain bloginfo('template_url') within this php code? sorry, if it seems trivial to you. also the path "/images/ads/ad_0$single.png". I am learning php. Thank you.

Which function I need to use in place of bloginfo('template_url') if I do not use wordpress but php as a template engine? anyone helps me?

  • 写回答

1条回答 默认 最新

  • dousui3124 2013-08-11 18:32
    关注

    the function is randomizing 5 ads.
    each ad has the name in: /images/ads/ad_01.png .. /images/ads/ad_05.png.

    first the range (1, 5) makes an array {1,2,3,4,5} shuffle mixes it up so it looks more like {4,3,5,1,2} foreach ($all as $single) will call the echo statement for each of those numbers in the new order

    bloginfo('template_url') is a function somewhere else in your code. it is outputting a template url path partial. most likely its something like /templates.

    using chrome: you can figure that out by right clicking on one of these ads and choosing inspect element and find the exact url that is being built out.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?