php,即时创建链接,创建链接内容

时间:2013-03-06 19:18:30

标签: php on-the-fly

我有一个index.php,它调用一个函数post_themes_front(),该函数从SQL数据库获取所有“帖子”并创建所有内容,包括链接。示例:图片A链接到www.index.com/picture_a_name

代码示例:

while($row = mysql_fetch_array($result))
    {

    echo '

     <div class="post">
        <h2>

        <a href=http://www.meetthemes.com/'. $row['name'] .'" title="'. $row['name'] .'">'. $row['name'] .'</a>
        </h2>

    <div class="infos b20">

     By <em>MeetThemes</em> on <em>'. $row['date'] .'</em>

     <span class="label label-important pull-right">'. $row['views'] .' views</span> 
     <a href="http://www.meetthemes.com/'. $row['name'] .'#comments" class="label label-info pull-right r5" title="Comments">'. $row['comments'] .'</a>
     <a href="http://www.meetthemes.com/'. $row['name'] .'" class="label label-info pull-right r5">'. $row['catagory'] .'</a>
     <a href="http://www.meetthemes.com/'. $row['catagory'] .'" class="label label-info pull-right r5">'. $row['catagory'] .'</a>
  </div>

  <p>
     <a href="http://www.meetthemes.com/'. $row['name'] .'" title="ThemeForest - Silicon - Responsive WordPress Theme">
     <img alt="ThemeForest - Silicon - Responsive WordPress Theme" src="img/'. $row['image_path'] .'" class="post_img" />
     </a>
     </div>
    ';
}

没有像“picture_a_name”这样的文件,id就像创建它一样,当用户点击它时,并在那里发送带有从SQL获取的评论,链接等的适当值。

但是点击创建它是否为时已晚?

是否必须在此之前创建?我可以创建一个函数来创建索引中的所有帖子的内容,并在索引上调用它,并在点击时发送它们,但这会占用很多客户端资源.....在加载时间(我知道)它的服务器端)...

欢迎任何建议

我想要获得的内容的例子,newone.org的首页,包含所有链接到单独内容的“帖子”。

我知道有很多CMS会为我做这个,但我不喜欢使用drupal / joomla / wordpress

1 个答案:

答案 0 :(得分:0)

你可以做的是制作一个.htaccess文件来捕获对不存在文件的所有请求,如下所示:

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ createContent.php?file=$1 [QSA,L]
</IfModule>

因此,当'picture_a_name'不存在时,请求将重定向到 createContent.php?file = picture_a_name 。在createContent中,您现在可以创建被询问的内容并将其保存为“picture_a_name”。

相关问题