【问题标题】:Creating links, and creating content for the links, on the fly, php动态创建链接,并为链接创建内容,php
【发布时间】:2013-03-06 19:18:30
【问题描述】:

我有一个 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 获取的 cmets、link 等适当的值发送给他。

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

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

欢迎提出建议

我想要实现的示例,newone.org 的首页,包含大量“帖子”,它们都链接到单独的内容。

我知道有很多 CMS 可以为我做这件事,但我不喜欢使用 drupal / joomla / wordpress

【问题讨论】:

    标签: php on-the-fly


    【解决方案1】:

    您可以做一个.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”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-22
      • 2011-10-16
      • 2023-04-06
      • 2011-09-17
      • 1970-01-01
      • 1970-01-01
      • 2020-07-16
      相关资源
      最近更新 更多