2

我正在开发一个动态博客/投资组合:

参考链接:http ://www.andrewryan.me/

我已经在我的个人网站上工作了一个多月了。我一直在修改东西,因为我觉得我把整个事情都设置错了。我知道我在某种程度上是这样或那样的,我终于寻求帮助。

我一直在研究动态站点结构,我想知道一些事情:

  1. 动态内容的最佳实践。

    • 我在根文件夹中有网站的框架。这包括索引和样式。
      (连同脚本文件夹、图像文件夹和其他杂项文件类型..)

    • 最新的博客条目被拉到索引页面上。如果他们想查看我所有的专业帖子/主题,他们只需转到任何给定的子部分。
      (例如:index.php?p=professional)

    • 从那里; 如果用户想要完整地查看一篇博文,他们只需点击该博文,然后它就会被进一步动态拉起。
      (例如:index.php?p=professional/thispost (idfk))

  2. 如何在动态内容中创建动态内容。

    • 页面和子页面然后继续在个人文件夹中的链上。(例如:index.php > index.php?p=personal)
  3. 如何制作可更新的内容,一旦页面上传到其各自的文件夹,这些内容将被归档。

    • 我应该考虑为此使用数据库还是 XML?如果是这样,任何人都可以向我指出有关制作此类网站的任何好的教程吗?对此无需过多解释。

这是我的文件结构:

root/   
  > images/  
    ||--> x.png   
  > pages/  
    ||--> personal.php  
    ||--> professional.php  
    ||--> contact.php   
    ||--> 404.php  
    ||--> contact.php 
    > personal/  
        |||--> personalposts.php  
    > professional
        |||--> professionalposts.php  
    > gallery/  
        |||--> galleryposts.php   
  > scripts  
    ||--> scripts.php/js/etc
  |--> .htaccess
  |--> index.php  
  |--> style.css    
  |--> robots.txt  
  |--> humans.txt

...以及动态页面的代码:

<?php
    $pages_dir = 'pages'; //Scans the pages directory

    if (!empty($_GET['p'])) { //If not empty it will get the file
        $pages = scandir ($pages_dir, 0); //Sets up files as array
        unset ($pages[0], $pages[1]); //Unsets the first two. These are just dots.
        $p = $_GET['p'];

        if (in_array($p.'.php',$pages)) {
            include ($pages_dir.'/'.$p.'.php');
        } else {
        include($pages_dir.'/404.php'); //DENIED!
        }
    } else {
        include($pages_dir.'/blog.php'); //if it's the index page
    }
?>  

我或多或少想知道我的结构是否正确,或者是否有更好的方法来做到这一点。我希望能够制作这个网站一次,并在需要时自动更新它的内容。

4

1 回答 1

2

啊哈,我一直在等待的问题。我正在一个做这个的网站上工作。首先,您必须将您的网站分成页面(每个页面都有不同的布局)。例如,要注销,您将有如下内容:sitename.com/?action=logout

要回家,您可以访问 sitename.com,如果您尝试 /?p=somethingThatDoesntExist,您仍然可以访问主页(或错误页面)

如果您可以访问 Web 根目录下的某些内容,那就更好了。然后,您应该将所有 .php 文件保留在 /root/content/ 中,并且在 /root/www/ 中仅保留一个 index.php

如果玩家已登录(如果他是管理员,则可选)此代码是我用来为玩家提供页面的代码

// Check if alternate page requested
if (!empty($_GET["p"]) and !empty($_SESSION['id']))
{
    $page = $_GET["p"];

    if (!empty($pages[$page]))
    {
        $page_array = $pages[$page];
        if ( (!empty($page_array['auth'])) && ($user['Auth'] < $page_array['auth']) )
        {
            $page_array = $pages['index'];
        }
    }
    else
    {
        $page = '';
    }
}

然后,你做你的基本工作:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang='en'>  
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
        <title><? echo $page_array['title'] ?></title>

        <link rel="stylesheet" href="css/3p/reset.css" type="text/css"/>
        <link rel="stylesheet" href="css/3p/formalize.css" type="text/css"/>

        <link href="css/bootstrap.css" rel="stylesheet">
        <link href="css/main.css" rel="stylesheet">
        <link href="css/bootstrap-responsive.css" rel="stylesheet">
    </head>  
    <body>  
            <?php
                    require("../content/header.php");
                    require($page_array['require']);
                    require("../content/footer.php");
            ?>
    </body>
</html>

以下是 page_array 的内容:

$pages = Array();
$pages['admin'] = Array(
    'auth' => 3,
    'require' => "../admin/index.php",
    'title' => "Administration - NPG CP"
);

$pages['index'] = Array(

    'require' => "../content/index.php",
    'title' => "Home - NPG CP"
);

$pages['friends'] = Array(

    'require' => "../content/index.php",
    'title' => "Friends - NPG CP"
);

$pages['pm'] = Array(

    'require' => "../content/index.php",
    'title' => "Messages - NPG CP"
);

$pages['stats'] = Array(

    'require' => "../content/index.php",
    'title' => "Statistics - NPG CP"
);

在我的网站上,我只使用一个可查看的文件来处理其他所有内容。我希望我对你有所帮助。我可以给你我网站的源代码,只需给我发电子邮件到 [my_username]@gmail.com 就可以了 :)

于 2012-07-15T01:38:46.423 回答