0

我目前正在处理两个项目,一个用于练习和掌握一些概念的小型 Flash 游戏网站,以及一个博客/游戏开发广告混合体。我对你们的问题是什么是加载帖子的最有效方式,所以我可以做一些事情,比如生成具有指定数量条目的页面,并根据我稍后定义的类别对它们进行排序。这可能只是我的无知,但是将每个文件存储在一个文件中似乎效率很低,因为要存储的文件很多。来自小型 Flash 游戏网站的基本游戏“帖子”示例,它实际上只是一个 div 容器,而且我可以添加一些类似标签系统的东西,以便稍后对其进行整理

    <div class="game">
                <a href="games/game.php?game=somegame"><img src="images/somegame.png"></a>
                <div id="content">
                    <a href="games/game.php?game=somegame"><header>Game name</header></a>
                    <p>
                        Lorem ipsum dolor sit amet, consectetur adipiscing elit. 

                    </p>
                </div>
            </div>
4

3 回答 3

0

看来您是发展中国家的新手(不是问题)。您可能想寻找开箱即用的解决方案。

想到的东西:Tumblr、Wordpress 等……

如果您真的想自己破解它,我建议您使用“框架”,您可以将其视为编程语言之上的一个额外层,以填补空白/使东西更易于使用。

我真的可以推荐使用 laravel ( http://laravel.com/docs ),它使用起来非常简单,文档会让你快速上手。

希望能帮助到你

于 2013-03-21T04:44:42.060 回答
0

您可以像这样制作 XML 文件。有多种读取 XML 文件的方法。我的猜测是你想把它读入 Flash。所以你会看actionscript。为此,您可以轻松找到信息并开始学习。(即http://gotoandlearn.com/play.php?id=64

这取决于你想要什么。您可以使用 XML 文件中的信息即时生成 div 块。

<games>
    <game>
        <name>Some name</name>
        <link>"games/game.php?game=somegame</link>
        <image>"images/somegame.png"</image>
        <content>Lorem Ipsum</content>
    </game>
    <game>
        <name>Second name</name>
        <link>"games/game.php?game=secondgame</link>
        <image>"images/secondgame.png"</image>
        <content>Lorem Ipsum</content>
    </game>
</games>
于 2013-03-21T05:03:57.350 回答
0

将 3 个文件放在(本地)主机上的文件夹中并运行 index.php - 这就是您要查找的内容吗?

/wwwroot/post.tpl

<article id="{$postId}" class="{$postType}">
    <div class="content" style="width:450px;float:left;margin-right:20px;">     
        <h3><a href="single-post.php?id={$postId}">{$postTitle}</a></h3>
        <p>{$postContent}</p>
    </div>
    <a href="single-post.php?id={$postId}"><img style="height:150px;" src="{$postPreviewImage}"></a>
</article><br clear="all"/>

/wwwroot/main.tpl

<!doctype html>
<html>
<head>
  <meta charset="UTF-8"/>
  <title>{$pageTitle}</title>
  <script type="text/javascript" src="//code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
  <h1>{$pageH1}</h1>
  <hr>
  Filter posts: 
  <select id="filter">
    <option id="all">Show all posts</option>
    {$filterOptions}
  </select>
  <hr>
  {$posts}
  <script>
    $().ready(function() {
      $("#filter").change(function() {
        for(var b = $(this).find(":selected").attr("id"), d = document.getElementsByTagName("article"), c = 0;c < d.length;c++) {
          var a = d[c];
          "all" === b || b === a.className ? $(a).fadeIn() : b !== a.className && $(a).fadeOut()
        }
      });
    });
  </script>
</body>
</html>

/wwwroot/index.php

<?php
// get categories from DB
$postCategoriesFromDb = array(
    array(
        'slug' => 'games',
        'name' => 'Games'
    ),
    array(
        'slug' => 'dev',
        'name' => 'Development'
    )
);

// get posts from DB
$postsFromDb = array(
    array(
      'id'      => 1,
      'type'    => 'games',
      'image'   => 'http://openmatt.org/wp-content/uploads/2012/12/Game-On-banner.png',
      'title'   => 'A post about games',
      'content' => 'This is the content of my game post.. lorem ipsum..'
    ),
    array(
      'id'      => 2,
      'type'    => 'dev',
      'image'   => 'http://gregrickaby.com/wp-content/uploads/2012/03/github-logo.png',
      'title'   => 'A post about development',
      'content' => 'This is the content of my dev post.. lorem ipsum..'
    )
);

// function to populate single post template with post data
function getPostHtml($postData) {
    $html = file_get_contents(__DIR__ . '/post.tpl');

    $vars = array(
        '{$postId}'           => $postData['id'],
        '{$postType}'         => $postData['type'],
        '{$postPreviewImage}' => $postData['image'],
        '{$postTitle}'        => $postData['title'],
        '{$postContent}'      => $postData['content']
    );

    return strtr($html, $vars);
}

// create HTML for each post
$posts = '';    
foreach ($postsFromDb as $post) {
    $posts .= getPostHtml($post);
}

// create HTML for category filter
$options = '';  
foreach ($postCategoriesFromDb as $cat) {
    $options .= sprintf('<option id="%s">%s</option>', $cat['slug'], $cat['name']);
}

// get main page template
$html = file_get_contents(__DIR__ . '/main.tpl');

// template vars
$vars = array(
    '{$pageTitle}'     => 'Page title',
    '{$pageH1}'        => 'Hello World!',
    '{$filterOptions}' => $options,
    '{$posts}'         => $posts
);

// output to client
echo strtr($html, $vars);
于 2013-03-21T06:07:39.913 回答