网站开发(十三)首页文章循环显示和显示文章内容

来源:互联网 发布:java专业技能怎么写 编辑:程序博客网 时间:2024/05/22 06:16

首页文章循环显示效果

这里写图片描述

显示文章内容效果

这里写图片描述


一、首页文章循环显示

1、进入Home下的indexController.class.php,(因为首页文章都在first数据表中),所以要获取first所以数据,然后分配数据。所以在index的控制器中在index函数中添加代码

$first=D('first');        $firsts=$first->select();        $this->assign('firsts',$firsts);

这里写图片描述


2、首页文章与后台同步(动态)

1.进入Home/View/Index下的index.html
2.对文章部分进行循环数据(volist)
3.对文章标题进行从数据库中读取
4.if判断是否有图片,若无图片显示一张无图片的图片(将无图片的图片存在根目录下的Uploads下)这里写图片描述
5.加上时间函数,并加上时间戳

    <volist name="list" id="vo">        <div class="list">          <ul>            <li>                <h1 class="title"><a href="#" >{$vo.f_title}</a></h1>                <div class="info"><span>{$vo.time|date="Y-m-d",###}</span></div>                <div class="thumb">                <a href="#" >                <if condition="$vo['f_pic'] neq null">                <img width="1200" height="630" src="__ROOT__{$vo.f_pic}" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" />                <else/>                <img width="1200" height="630" src="__ROOT__/Uploads/暂无图片.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" />                </if>                </a></div>            </li>          </ul>        </div>    </volist>

这里写图片描述


文章循环显示完成


二、首页文章内容页

1.先创建首页文章内容页的html(在Home/View/Index下和index.html同级)article.html


article.html代码

<!doctype html><html  lang="zh-CN" prefix="og: http://ogp.me/ns#"><head><title>文章页面</title><include file="Common:header"/><div class="body"><div class="wrapper cls">    <div class="main">        <div class="list">          <ul>            <li>                <h1 class="title"><a href="#" >{$firsts.f_title}</a></h1>                <div class="info"><span>{$firsts.time|date="Y-m-d",###}</span></div>                <!-- 文章内容 -->                {$firsts.f_content}<!-- 获取文章内容 -->                <!-- 文章内容 -->            </li>          </ul>        </div>    <div class="list page b-page">        {$page}        </div>    </div>      <include file="Common:right"/>    <include file="Common:footer"/>

这里写图片描述


2.修改index.html中点击动态标题的超链接

href="__CONTROLLER__/article/id/{$vo.f_id}"

这里写图片描述


3.写控制器中article的方法

1.进入indexController.class.php创建article函数并写方法

article函数代码

    public function article(){        //进入article页面导航的蓝色背景        $cate=D('cate');        $cateid=1;        $cateids=$cate->find($cateid);        $this->assign('cateids',$cateids);        //获取文章内容        $first=D('first');        $firstid=I('id');        $firsts=$first->find($firstid);        $this->assign('firsts',$firsts);        $this->display();    }

完成