Blogger Information
Blog 30
fans 0
comment 1
visits 22017
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0110PHP静态网站转换为动态
Admin
Original
1039 people have browsed it

效果图

Index页面

list页面

文章页面

核心代码部分

Index页面

index内容的核心代码

  1. <ul class="list-group list-group-flush">
  2. <?php foreach ($dms as $v) : ?>
  3. <li class="list-group-item">
  4. <?php foreach ($category as $cate) : ?>
  5. <?php if ($v['cid'] === $cate['id']) : ?>
  6. <a href="<?php echo $cate['url'] ?>"><?php echo $cate['name'] ?></a>
  7. <?php endif; ?>
  8. <?php endforeach; ?>
  9. <a href="show.php?id=<?php echo $v['id'] ?>"><?php echo $v['title'] ?></a>
  10. <span><?php echo $v['filesize'] ?></span>
  11. </li>
  12. <?php endforeach; ?>
  13. </ul>

首页内容的重点是使用了foreach嵌套循环出的内容,因为我们的动态数据不是从数据库中来,所以有一丝小麻烦要做到文章分类(也就是cid显示中文)
header部分循环导航也没什么可以写的就是简简单单的循环

list列表页面

  1. $cid = intval($_GET['cid']);
  2. //定义函数用来列出分类资源
  3. /**
  4. * getCidDms获取分页动漫列表
  5. * $cid 分类ID
  6. * $dms 资源列表
  7. * Return array类型 资源
  8. */
  9. function getCidDms($cid,$dms){
  10. foreach($dms as $dm){
  11. if ($dm['cid'] === $cid) {
  12. $ciddms[]=$dm;
  13. }
  14. }
  15. return $ciddms;
  16. }
  17. function getCidName($cid,$category){
  18. foreach($category as $v){
  19. if($cid === $v['id']){
  20. $cname = $v['name'];
  21. }
  22. }
  23. return $cname;
  24. }
  25. $ciddms = getCidDms($cid,$dms);
  26. $cname = getCidName($cid,$category);

在列表页面我这边实现了分类显示,分类内容以上是核心代码,封装成了简单函数

文章界面核心代码

  1. function getDm($id,$dms){
  2. foreach($dms as $v){
  3. if ($id === $v['id']) {
  4. $dmactive[] = $v['title'];
  5. $dmactive[] = $v['cid'];
  6. }
  7. }
  8. return $dmactive;
  9. }
  10. function getCidName($cid,$category){
  11. foreach($category as $v){
  12. if($cid === $v['id']){
  13. $cname = $v['name'];
  14. }
  15. }
  16. return $cname;
  17. }
  18. $dmactive = getDm($id,$dms);
  19. // $cname = getCidName($dmactive[1],$category);
  20. // var_dump($cname);

config.php代码

  1. $siteweb = '爱动漫网';
  2. //栏目导航
  3. $category=[
  4. ['id'=>1,'name'=>'新番连载','url'=>'list.php?cid=1'],
  5. ['id'=>2,'name'=>'动画合集','url'=>'list.php?cid=2'],
  6. ];
  7. $dms=[
  8. ['id'=>1,'title'=>'[ReinForce] 街角魔族 Machikado Mazoku (BDRip 1920x1080 x264 FLAC)','filesize'=>'123.57MB','cid'=>1],
  9. ['id'=>2,'title'=>'【飞沐team】飞哥与小佛 第一季 Phineas and Ferb Season 1 (2007) (26集全)(国英双语)(1080P)[MKV]','filesize'=>'585.7MB','cid'=>2],
  10. ['id'=>3,'title'=>'[Lilith-Raws] 理科生墜入情網,故嘗試證明。/ Rikekoi [01-12][BiliBili][WEB-DL][1080p][AVC AAC][CHT][MKV]','filesize'=>'585.7MB','cid'=>1],
  11. ['id'=>4,'title'=>'食戟之灵 第一季 Shokugeki no Souma 1-24 [BD 1920x1080 HEVC 10bit][简繁内封字幕]','filesize'=>'585.7MB','cid'=>1],
  12. ];

由于本次作业是在兼职店中的空闲时间完成,所以看上去会比较简陋,但是该有的功能全部都有。只需要在config.php中添加所对应的内容即可

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:咱们现在是在学习阶段 , 写简单点更好, 代码越短, bug越少... 只要能实现所要求的功能即可
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