简体   繁体   English

动态创建链接并为链接创建内容,php

[英]Creating links, and creating content for the links, on the fly, php

I have a index.php, it calls a function post_themes_front(), the function gets all the "posts" from the SQL database and creates all the content, including the links. 我有一个index.php,它调用一个函数post_themes_front(),该函数从SQL数据库获取所有“帖子”并创建所有内容,包括链接。 Example: picture A links to www.index.com/picture_a_name 示例:图片A链接到www.index.com/picture_a_name

code sample: 代码示例:

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>
    ';
}

There is no such file as "picture_a_name", id like to create that, when the user clicks on it, and send him there with the apropriate values for comments, link etc, fetched from SQL. 没有诸如“ picture_a_name”之类的文件,ID类似于在用户单击该文件时创建的文件,并将其与适当的注释,链接等值一起从SQL那里发送给他。

But is it to late to create it on click? 但是,在点击时创建它是否为时已晚?

Does it have to be created before that? 是否必须在此之前创建? i could make a function to create the content of all posts in index, and call it on index, and send them there on click but that would take up quite alot of client resources ..... in therms of loading time (I know its server side)... 我可以创建一个函数来创建索引中所有帖子的内容,并在索引上调用它,然后在单击时将它们发送到那里,但这将占用大量的客户端资源.....在加载时间的过程中(我知道服务器端)...

Any suggestions are welcome 欢迎任何建议

Example of what i want to achive, newone.org the frontpage, contains loads of "posts" which all link to seperate content. 我想要实现的示例,newone.org,首页,包含所有链接到单独内容的“帖子”负载。

I understand that there are plenty of CMSes that will do this for me, but i dislike using drupal / joomla / wordpress 我了解有很多CMS可以为我完成此操作,但是我不喜欢使用drupal / joomla / wordpress

What you can do is make an .htaccess file which catches all requests to non-existing files, something like this: 您可以做的是制作一个.htaccess文件,该文件捕获对不存在文件的所有请求,如下所示:

<IfModule mod_rewrite.c>
  RewriteEngine On

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

So that, when 'picture_a_name' doesn't exist, the request is redirected to createContent.php?file=picture_a_name . 这样,当'picture_a_name'不存在时,该请求将重定向到createContent.php?file = picture_a_name In createContent you can now create the asked content and save it to 'picture_a_name'. 现在,您可以在createContent中创建要求的内容并将其保存到“ picture_a_name”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM