Mar 19, 2007

WP Real Static Homepage

PLEASE Scroll down for Chinese version

This plugin enables the wp system to convert your dynamic homepage to static index.html, more importantly, keep the content up to date. It can speed up the loading for your homepage.

Readme:

  1. Plugin WP-Cron is needed for this plugin, I've packed WP-Cron v 1.4 in the zip file.
    Please upzip all the files to plugins/static-index, so that it look like:
    ------plugins/
    ------------static-index/
    ----------------static.php
    ----------------wp-cron-static-index.php
    ----------------wp-cron.php
  2. Active two plugins :WP-cron and WP-Cron Static Homepage.
  3. Create a file named index.html in your blog root folder, set
    666 permissions for it.

Well, the system will update index.html automatically (per 15 mins), you may hack wp-cron.php at line 49 to change the time for scheduled exection actions.

More Tips:

  1. You may use the following php to refresh homepage when comments come in.

    <?php
    include (get_settings('siteurl') . "/wp-content/plugins/static-index/static.php");
    ?>

  2. The following script is to demo how to set cookies in the html files.

    <script type="text/javascript">
    function GetCookie(sName, id)
    {
    // cookies are separated by semicolons
    var something = document.getElementById(id);
    if(!something) return 0;
    for (var i=0; i < aCookie.length; i++)
    {
    // a name alue pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0])
    {
    if(sName=="comment_author_10add94cfc29a64b08306c8a8f9edb30")
    something.value = decodeURI(aCrumb[1]);
    else
    something.value=unescape(aCrumb[1]);
    return 1;
    }
    }
    // a cookie with the requested name does not exist
    return 0;
    }
    //please fill in with your own cookie id
    GetCookie("comment_author_8e11b42cc2f3a74aac664cc9afa5baf7", "authorname");
    GetCookie("comment_author_email_8e11b42cc2f3a74aac664cc9afa5baf7", "email");
    GetCookie("comment_author_url_8e11b42cc2f3a74aac664cc9afa5baf7", "url");</script>

WP Static Homepage(首页静态化)插件的目的是为了将WP的index.php转化为index.html,从而实现首页静态化的目的,提高主页的浏览速度。 如果您想要全站静态化,请参考阅微堂的文章。

安装说明:

  1. 您需要安装WP-Cron插件,在上述的下载地址中已经包含该插件的1.4版本,您也可以自行下载。
  2. 将下载文件中的所有文件解压缩后上传到plugins下的static-index目录中,目录结构如下:
    ------plugins/
    ----static-index/
    ------------static.php
    ------------wp-cron-static-index.php
    ------------wp-cron.php
  3. 激活wp-cron,WP-Cron Static Homepage两个插件。
  4. 在blog根目录建立一个index.html的文件,设置属性为666。

运行之后,系统会每镉15分钟将index.php的内容刷新为index.html,提高浏览速度。 题外话:

  1. 关于留言问题。 留言系统我采用的也是阅微堂的基于MSN风格的留言系统,该系统基于ajax技术,因此可以在静态页面上使用。如果要使用该留言系统,建议在里面的comment-reply.php文件中包含以下语句,保证留言之后会重新刷新静态主页。

    <?php include (get_settings('siteurl') . "/wp-content/plugins/static-index/static.php"); ?>

  2. 关于cookies读取,在阅微堂的文章中已经有详细的阐述,这里借花献佛,也就是加入如下代码:

    <script type="text/javascript">
    function GetCookie(sName, id)
    {
    // cookies are separated by semicolons
    var something = document.getElementById(id);
    if(!something) return 0;
    for (var i=0; i < aCookie.length; i++)
    {
    // a name alue pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0])
    {
    if(sName=="comment_author_10add94cfc29a64b08306c8a8f9edb30")
    something.value = decodeURI(aCrumb[1]);
    else
    something.value=unescape(aCrumb[1]);
    return 1;
    }
    }
    // a cookie with the requested name does not exist
    return 0;
    }
    以下为我的cookie设置,用户请自行寻找自己的cookie id
    GetCookie("comment_author_8e11b42cc2f3a74aac664cc9afa5baf7", "authorname");
    GetCookie("comment_author_email_8e11b42cc2f3a74aac664cc9afa5baf7", "email");
    GetCookie("comment_author_url_8e11b42cc2f3a74aac664cc9afa5baf7", "url");</script>

参考文献:

  1. 阅微堂
  2. WP-Cron
Post by SUN @ 7:32 am
(Required)
(Required, will not be published)
:mrgreen: :| :twisted: :arrow: 8O :) :? 8) :evil: :D :idea: :oops: :P :roll: ;) :cry: :o :lol: :x :( :!: :?: