文章详情显示功能
1,修改indexHtml.php代码:
2,新建并编辑ArticleShow.php
准备数据:
所有分类信息:$categories
当前点击的文章详情信息:$result
当前分类下有哪些文章:$articles
<?php require './init.php'; //获取展示文章的ID $articleId=isset($_GET['id'])?intval($_GET['id']):0; //取出文章分类 $sql="select *from cms_article where id=$articleId"; //文章详细信息 $result=$db->fetchRow($sql); //文章对应的分类id $cid=$result['cid']; //当前分类下有哪些文章 $sql="select *from cms_article where cid=$cid"; $articles=$db->fetchAll($sql); $sql="select name from cms_category where id=".$result['cid']; $cname=$db->fetchRow($sql); $result['cname']=$cname['name']; //所有分类信息 $sql="select name from cms_category ORDER BY sort"; $categories=$db->fetchAll($sql); require 'ArticleShowHtml.php';
3,新建ArticleShowHtml.php文件
图片展示:
对图片显示的红框进行遍历即可
具体代码如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <link href="./css/common.css" rel="stylesheet" type="text/css"> <link href="./css/header.css" rel="stylesheet" type="text/css"> <link href="./css/label.css" rel="stylesheet" type="text/css"> <link href="./css/style.css" rel="stylesheet" type="text/css"> <link href="./css/index.css" rel="stylesheet" type="text/css"> </head> <body> <div class="logo"><img src="./image/logo1.jpg"></div> <div id="nav"> <div class="nav_menu clearfix"> <ul id="menu_nav"> <li class=""><a href="./index.php">首页</a></li> <?php foreach ($categories as $v): ?> <li class=""><a href="#"><?php echo $v['name'];?></a></li> <?php endforeach;?> </ul> </div> </div> <div class="wrap"><!--content--> <div class="position"><A href="./">首页</A> > <a href="./"><?php echo $result['cname'];?></a> > <a href="./"><?php echo $result['title'];?></a>> 详细内容 </div> <div class="clear"></div> <div class="container"> <div class="contain_left"> <div class="show_box_leftmenu common_mbottom "> <div class="sb1_head"> <div class="sb1_head_tit"><?php echo $result['cname'];?></div></div> <div class="sb1_main"><ul class="tabs" id="tabs"> <?php foreach ($articles as $a): if ($a['id']==$result['id']) :?> <li class="cid_1322 thistab"><a href="<?php echo "ArticleShow.php?id=".$a['id']; ?>"><?php echo $a['title'];?></a></li> <?php else:?> <li class="cid_1322"><a href="<?php echo "ArticleShow.php?id=".$a['id']; ?>"><?php echo $a['title'];?></a></li> <?php endif;endforeach;?> </ul></div> <div class="sb1_bottom"> </div></div> </div> <div class="contain_right"> <div class="show_box_2"><!--layout article content--> <div class="sb2_head"> <div class="layout_txtcontent_position" style="background-position: 0px -203px; height: 23px; color: rgb(16, 80, 157); padding-left: 38px; font-size: 13px;"> 分类:<?php echo $result['cname'];?> > 正文 </div> </div> <div class="sb2_main layout_txtcontent common_mbottom"> <div class="layout_txtcontent_title"> <?php echo $result['title'];?></div> <div class="layout_txtcontent_info">日期:<?php echo $result['addtime'];?> <SPAN class="item_views"><script language="JavaScript" src="../include/Hits.php?artid=87" type="text/javascript"></script></SPAN> <SPAN id="operation" style="color: rgb(0, 64, 255); margin-left: 15px; display: none; cursor: pointer;"></SPAN> </div> <div class="layout_txtcontent_content"> <?php echo $result['content'];?> </div> <div class="layout_txtcontent_list"></div> <div class="common_digg"> <div class="clear"></div></div> <div class="change"> <ul> </ul></div> </div><!--layout comment--> </div></div></div><!--footer--> </div> <div id="footer" style="position:absolute;bottom:0;" > <div class="foot"> <br> <p><span style="font-size: 12px;">Copyright All Rights Reserved <a href="">PHP中文网文章管理系统</a></span></p> </div> </div> </body></html>