Blogger Information
Blog 35
fans 0
comment 0
visits 26793
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
简单的企业站案例
锋芒天下的博客
Original
621 people have browsed it

实例

<!--列表页面list.php-->

<?php require __DIR__ .'/header.php'?>
    <!--主体-->
    <div id="box">

        <?php
        foreach ($cates as $cate){

            if (intval($_GET['cate_id']) === $cate['cate_id']){
                 echo "<h2>{$cate['alias']}</h2>";
            foreach ($movies as $movie){
                if ($cate['cate_id'] === $movie['cate_id']){
                    echo '<ul>';
                    echo "<li><a href='article.php?mov_id={$movie['mov_id']}' >{$movie['name']}</a></li>";
                    echo '</ul>';
                }

            };
            echo '<hr>';
        }
            }

        ?>

    </div>
    <!--end主体-->

    <!--footer-->
<?php require __DIR__ . '/footer.php'?>

运行实例 »

点击 "运行实例" 按钮查看在线实例

实例

<!--内容页article.php-->

<?php require __DIR__ .'/header.php'?>
    <!--主体-->
    <div id="box">

        <?php

                foreach ($movies as $movie){
                    if ($movie['mov_id'] ===intval($_GET['mov_id'])){
                        echo "<h2>{$movie['name']}</h2>";
                        echo $movie['detail'];
                    }
        }

        ?>

    </div>
    <!--end主体-->

    <!--footer-->
<?php require __DIR__ . '/footer.php'?>

运行实例 »

点击 "运行实例" 按钮查看在线实例

实例

<!--首页index.php-->

<?php require __DIR__ .'/header.php'?>
        <!--主体-->
        <div id="box">

            <?php
            foreach ($cates as $cate){
                echo "<h2>{$cate['alias']}</h2>";
                foreach ($movies as $movie){
                    if ($cate['cate_id'] === $movie['cate_id']){
                        echo '<ul>';
                        echo "<li><a href='article.php?mov_id={$movie['mov_id']}' >{$movie['name']}</a></li>";
                        echo '</ul>';
                    }

                };
                echo '<hr>';
            }
            ?>

        </div>
        <!--end主体-->

        <!--footer-->
<?php require __DIR__ . '/footer.php'?>

运行实例 »

点击 "运行实例" 按钮查看在线实例

实例

<!--公共底部footer.php-->

<div id="footer">
    <?php echo $system['copy'] . '© 版权所有' ?>
</div>
<!--end footer-->
</div>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

实例

<!--公共头部header.php-->
<?php
// 栏目数组
$cates = [
    ['cate_id'=>1, 'alias'=>'国内新闻'],
    ['cate_id'=>2, 'alias'=>'娱乐八卦'],
    ['cate_id'=>3, 'alias'=>'生活常识'],
];
// 网站的系统设置
$system = [
    'sys_id'=>1,
    'title'=>'今日头条',
    'desc'=>'推荐有价值的个性化的信息',
    'key'=>'新闻,娱乐,生活',
    'copy'=>'方泽网络科技***'
];
// 新闻数组
$movies = [
    [
        'mov_id'=>1,
        'name'=>'国内新闻111',
        'image'=>'yttlj.jpg',
        'detail'=>'国内新闻111国内新闻111国内新闻111国内新闻111国内新闻111国内新闻111国内新闻111国内新闻111…	',
        'cate_id'=>1
    ],

    [
        'mov_id'=>2,
        'name'=>'国内新闻222',
        'image'=>'dth.jpg',
        'detail'=>' 国内新闻222国内新闻222国内新闻222国内新闻222国内新闻222国内新闻222国内新闻222国内新闻222…	',
        'cate_id'=>1
    ],

    [
        'mov_id'=>3,
        'name'=>'国内新闻333',
        'image'=>'rgkyzya.jpg',
        'detail'=>'国内新闻333国内新闻333国内新闻333国内新闻333国内新闻333国内新闻333国内新闻333国内新闻333国内新闻333…	',
        'cate_id'=>1
    ],

    [
        'mov_id'=>4,
        'name'=>'娱乐八卦111',
        'image'=>'fczlm.jpg',
        'detail'=>'娱乐八卦111娱乐八卦111娱乐八卦111娱乐八卦111娱乐八卦111娱乐八卦111娱乐八卦111娱乐八卦111娱乐八卦111…',
        'cate_id'=>2
    ],

    [
        'mov_id'=>5,
        'name'=>'娱乐八卦222',
        'image'=>'bxmykxq.jpg',
        'detail'=>'娱乐八卦222娱乐八卦222娱乐八卦222娱乐八卦222娱乐八卦222娱乐八卦222娱乐八卦222娱乐八卦222娱乐八卦222!',
        'cate_id'=>2
    ],

    [
        'mov_id'=>6,
        'name'=>'娱乐八卦333',
        'image'=>'fczlm.jpg',
        'detail'=>'娱乐八卦333娱乐八卦333娱乐八卦333娱乐八卦333娱乐八卦333娱乐八卦333娱乐八卦333娱乐八卦333娱乐八卦333!',
        'cate_id'=>2
    ],

    [
        'mov_id'=>7,
        'name'=>'生活常识111',
        'image'=>'qs.jpg',
        'detail'=>'生活常识111生活常识111生活常识111生活常识111生活常识111生活常识111生活常识111生活常识111生活常识111…',
        'cate_id'=> 3
    ],

    [
        'mov_id'=>8,
        'name'=>'生活常识222',
        'image'=>'tkzc.jpg',
        'detail'=>'生活常识222生活常识222生活常识222生活常识222生活常识222生活常识222生活常识222生活常识222生活常识222…',
        'cate_id'=>3
    ],

    [
        'mov_id'=>9,
        'name'=>'生活常识333',
        'image'=>'lm.jpg',
        'detail'=>'生活常识333生活常识333生活常识333生活常识333生活常识333生活常识333生活常识333生活常识333生活常识333…',
        'cate_id'=>3
    ],

];


?>

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="keywords" content="<?php echo $system['key'] ?>" />
    <meta name="description" content="<?php echo $system['desc'] ?> " />
    <title><?php echo $system['title'] ?></title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        #container{
            width: 1000px;
            margin: 0 auto;
        }
        #container #header{
            width: 100%;
            height: 50px;
            background: #000;
            margin: 0 auto;
        }
        #container #header .nav{
            width: 600px;
            margin: 0 auto;
            overflow: hidden;
        }
        #container #header .nav li{
            width: 120px;
            height: 50px;
            float: left;
            line-height: 50px;
            list-style: none;
            text-align: center;
        }
        #container #header .nav li:hover{
            background: #444444;
        }
        #container #header .nav li a{
            color: white;
            text-decoration: none;
        }
        #container #box{
            width: 100%;
            height: 600px;
            border: 1px solid #cccccc;
            margin: 10px auto;
        }
        #container #box ul{
            margin-left: 20px;
        }
        #container #box ul li{
            list-style: none;
            height: 30px;
            margin-bottom: 5px;
        }
        #container #box ul li a{
            color: black;
            margin-left: 20px;
        }
        #container #footer{
            width: 100%;
            height: 40px;
            background: #cccccc;
            text-align: center;
            line-height: 40px;
        }
    </style>
</head>
<body>
<div id="container">
    <!--    头部-->
    <div id="header">
        <ul class="nav">
            <li style="background: red"><a href="index.php">首页</a></li>
            <?php foreach ($cates as $value) : ?>
                <li><a href="list.php?cate_id=<?php echo $value['cate_id'] ?>"><?php echo $value['alias'] ?></a></li>
            <?php endforeach; ?>
        </ul>
    </div>
    <!--end头部-->

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:qualified

Teacher's comments:每个页面, 通过GET参数进行关联是一种常用的技巧, 后面的框架还会提及
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