Blogger Information
Blog 28
fans 0
comment 0
visits 13022
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
网站的首页和产品页进行动态替换
手机用户1594223549
Original
511 people have browsed it

一.网站的首页动态替换
1.输出结果

2.代码部分

  1. <?php
  2. // 加载外部文件
  3. require 'template/public/header.php';
  4. $news = require 'data/news.php';
  5. $items = require './data/items.php';
  6. ?>
  7. <main>
  8. <!-- 新闻列表 -->
  9. <div class="news">
  10. <h2>新闻列表</h2>
  11. <div class="list">
  12. <?php for ($i=0;$i<5;$i++) : extract($news[$i])?>
  13. <a href="<?=$url ?>"><?=mb_substr($title, 0, 18) ?>...</a>
  14. <?php endfor ?>
  15. </div>
  16. </div>
  17. <!-- 产品列表 -->
  18. <div class="items">
  19. <h2>产品列表</h2>
  20. <div class="list">
  21. <?php for ($i=0;$i<4;$i++) : extract($items[$i])?>
  22. <div class="item">
  23. <img src="<?=$img?>" alt="" />
  24. <a
  25. href="<?=$url ?>"><?=mb_substr($title, 0, 18) ?>...</a>
  26. </div>
  27. <?php endfor ?>
  28. </main> -->
  29. <?php
  30. // 加载外部文件
  31. require 'template/public/footer.php';
  32. ?>

二.产品页进行动态替换
1.输出结果

2.代码部分

  1. <?php
  2. // 加载外部文件页眉
  3. require 'template/public/header.php';
  4. $news = require 'data/news.php';
  5. $items = require './data/items.php';
  6. ?>
  7. <main>
  8. <!-- 新闻列表 -->
  9. <div class="news">
  10. <h2>新闻列表</h2>
  11. <div class="list">
  12. <?php for ($i=0;$i<5;$i++) : extract($news[$i])?>
  13. <a href="<?=$url ?>"><?=mb_substr($title, 0, 18) ?>...</a>
  14. <?php endfor ?>
  15. </div>
  16. </div>
  17. <!-- 产品列表 -->
  18. <div class="items">
  19. <h2>产品列表</h2>
  20. <div class="list">
  21. <?php for ($i=0;$i<4;$i++) : extract($items[$i])?>
  22. <div class="item">
  23. <img src="<?=$img?>" alt="" />
  24. <a
  25. href="<?=$url ?>"><?=mb_substr($title, 0, 18) ?>...</a>
  26. </div>
  27. <?php endfor ?>
  28. </main> -->
  29. <?php
  30. // 加载外部文件页脚
  31. require 'template/public/footer.php';
  32. ?>
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:完成的不错, 继续加油
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post