WordPress是个优秀的博客程序是公认的,不过那是好久以前的事情了!Wordpress对于我们这些小玩家来说,的确太庞大了,我要的是简单的博客系统,而他给我的确是一个可以与CMS系统相比的玩意!这也就意味着,WordPress过于占资源,由于没有使用缓存,因此文章加载速度也成了一个大问题。
于是,我冒出了一个奇怪的想法,在保持现有Wordpress系统不变的情况下,直接调用Wordpress的数据库和现有的修改后的模板直接生成页面。简单的说就是用Wordpress发表文章,然后使用自己写的单一代码来加载文章。说写就写,可是想一想就会发现,这个工作量是非常庞大的。例如wp的分类表,很难理解,不过也非常的强大。
我并非没有动手去实现这一程序,而是我放弃了,虽然我有那么多的时间去解决这一系列的问题,在我折腾几天后,发现这似乎完全没有必要,我何必去研究一个如此复杂的代码库呢!倒不如哪天有时间来自己写一个,这样也许会更轻松,代码质量也会更高!
我几天的测试结果可以说明一个问题,获取首页文章及其分类目录标签只需要链接数据库五次即可!其他的只是字符串处理了!所以加载速度会比wp自身快很多。具体的数据我也不想去统计,都放弃了,什么都无所谓了!不过放一部分很惨的代码或许是可以的!
//创建分类和标签
foreach($GLOBALS['posts_content'] as $name => $value){
$GLOBALS['posts_content'][$name]['tag']=array();
$GLOBALS['posts_content'][$name]['category']=array();
$i=0;$j=0;
foreach($GLOBALS['THE_POSTS']['terms_id'] as $name2 => $value2){
if($value['ID']!=$value2['object_id'])continue;
$k=0;
foreach($GLOBALS['THE_POSTS']['terms_id_type'] as $name3 => $value3){
if($value3['term_taxonomy_id']==$value2['term_taxonomy_id']){
if($value3['taxonomy'] == 'post_tag'){
$GLOBALS['posts_content'][$name]['tag'][$i]=array();
$GLOBALS['posts_content'][$name]['tag'][$i]['name']=$GLOBALS['THE_POSTS']['terms_id_name'][$k]['name'];
$GLOBALS['posts_content'][$name]['tag'][$i]['slug']=$GLOBALS['THE_POSTS']['terms_id_name'][$k]['slug'];
$i++;
}
else if($value3['taxonomy'] == 'category'){
if($value3['parent']!=0){
$l=0;$m=0;
foreach($GLOBALS['posts_content'][$name]['category'] as $name4 => $value4){
if($value4['term_id']==$value3['parent']){
$m=$GLOBALS['posts_content'][$name]['category'][$l]['sub']++;
if($value4['sub']==0)$GLOBALS['posts_content'][$name]['category'][$l]['sub_arr']=array();
$GLOBALS['posts_content'][$name]['category'][$l]['sub_arr'][$m]['name']=$GLOBALS['THE_POSTS']['terms_id_name'][$k]['name'];
$GLOBALS['posts_content'][$name]['category'][$l]['sub_arr'][$m]['slug']=$GLOBALS['THE_POSTS']['terms_id_name'][$k]['slug'];
$GLOBALS['posts_content'][$name]['category'][$l]['sub_arr'][$m]['description']=$value3['description'];
$GLOBALS['posts_content'][$name]['category'][$l]['sub_arr'][$m]['term_id']=$value3['term_id'];
$GLOBALS['posts_content'][$name]['category'][$l]['sub_arr'][$m]['parent']=$value3['parent'];
}
$l++;
}
if($l==0){
$GLOBALS['posts_content'][$name]['category'][$j]=array();
$GLOBALS['posts_content'][$name]['category'][$j]['name']=$GLOBALS['THE_POSTS']['terms_id_name'][$k]['name'];
$GLOBALS['posts_content'][$name]['category'][$j]['slug']=$GLOBALS['THE_POSTS']['terms_id_name'][$k]['slug'];
$GLOBALS['posts_content'][$name]['category'][$j]['description']=$value3['description'];
$GLOBALS['posts_content'][$name]['category'][$j]['term_id']=$value3['term_id'];
$GLOBALS['posts_content'][$name]['category'][$j]['parent']=$value3['parent'];
$GLOBALS['posts_content'][$name]['category'][$j]['sub']=0;
$j++;
}
}else{
$GLOBALS['posts_content'][$name]['category'][$j]=array();
$GLOBALS['posts_content'][$name]['category'][$j]['name']=$GLOBALS['THE_POSTS']['terms_id_name'][$k]['name'];
$GLOBALS['posts_content'][$name]['category'][$j]['slug']=$GLOBALS['THE_POSTS']['terms_id_name'][$k]['slug'];
$GLOBALS['posts_content'][$name]['category'][$j]['description']=$value3['description'];
$GLOBALS['posts_content'][$name]['category'][$j]['term_id']=$value3['term_id'];
$GLOBALS['posts_content'][$name]['category'][$j]['parent']=$value3['parent'];
$GLOBALS['posts_content'][$name]['category'][$j]['sub']=0;
$j++;
}
}
}
$k++;
}
}
}
//
foreach($GLOBALS['posts_content'] as $name => $value){
$GLOBALS['posts_content'][$name]['tag']=array();
$GLOBALS['posts_content'][$name]['category']=array();
$i=0;$j=0;
foreach($GLOBALS['THE_POSTS']['terms_id'] as $name2 => $value2){
if($value['ID']!=$value2['object_id'])continue;
$k=0;
foreach($GLOBALS['THE_POSTS']['terms_id_type'] as $name3 => $value3){
if($value3['term_taxonomy_id']==$value2['term_taxonomy_id']){
if($value3['taxonomy'] == 'post_tag'){
$GLOBALS['posts_content'][$name]['tag'][$i]=array();
$GLOBALS['posts_content'][$name]['tag'][$i]['name']=$GLOBALS['THE_POSTS']['terms_id_name'][$k]['name'];
$GLOBALS['posts_content'][$name]['tag'][$i]['slug']=$GLOBALS['THE_POSTS']['terms_id_name'][$k]['slug'];
$i++;
}
else if($value3['taxonomy'] == 'category'){
if($value3['parent']!=0){
$l=0;$m=0;
foreach($GLOBALS['posts_content'][$name]['category'] as $name4 => $value4){
if($value4['term_id']==$value3['parent']){
$m=$GLOBALS['posts_content'][$name]['category'][$l]['sub']++;
if($value4['sub']==0)$GLOBALS['posts_content'][$name]['category'][$l]['sub_arr']=array();
$GLOBALS['posts_content'][$name]['category'][$l]['sub_arr'][$m]['name']=$GLOBALS['THE_POSTS']['terms_id_name'][$k]['name'];
$GLOBALS['posts_content'][$name]['category'][$l]['sub_arr'][$m]['slug']=$GLOBALS['THE_POSTS']['terms_id_name'][$k]['slug'];
$GLOBALS['posts_content'][$name]['category'][$l]['sub_arr'][$m]['description']=$value3['description'];
$GLOBALS['posts_content'][$name]['category'][$l]['sub_arr'][$m]['term_id']=$value3['term_id'];
$GLOBALS['posts_content'][$name]['category'][$l]['sub_arr'][$m]['parent']=$value3['parent'];
}
$l++;
}
if($l==0){
$GLOBALS['posts_content'][$name]['category'][$j]=array();
$GLOBALS['posts_content'][$name]['category'][$j]['name']=$GLOBALS['THE_POSTS']['terms_id_name'][$k]['name'];
$GLOBALS['posts_content'][$name]['category'][$j]['slug']=$GLOBALS['THE_POSTS']['terms_id_name'][$k]['slug'];
$GLOBALS['posts_content'][$name]['category'][$j]['description']=$value3['description'];
$GLOBALS['posts_content'][$name]['category'][$j]['term_id']=$value3['term_id'];
$GLOBALS['posts_content'][$name]['category'][$j]['parent']=$value3['parent'];
$GLOBALS['posts_content'][$name]['category'][$j]['sub']=0;
$j++;
}
}else{
$GLOBALS['posts_content'][$name]['category'][$j]=array();
$GLOBALS['posts_content'][$name]['category'][$j]['name']=$GLOBALS['THE_POSTS']['terms_id_name'][$k]['name'];
$GLOBALS['posts_content'][$name]['category'][$j]['slug']=$GLOBALS['THE_POSTS']['terms_id_name'][$k]['slug'];
$GLOBALS['posts_content'][$name]['category'][$j]['description']=$value3['description'];
$GLOBALS['posts_content'][$name]['category'][$j]['term_id']=$value3['term_id'];
$GLOBALS['posts_content'][$name]['category'][$j]['parent']=$value3['parent'];
$GLOBALS['posts_content'][$name]['category'][$j]['sub']=0;
$j++;
}
}
}
$k++;
}
}
}
//
最近空间快到期,也想换个空间,请问博主这个wordpress的博客主机空间,包年多少,在国内速度如何、
我这个空间是别人的!不要钱的,一般不错的虚拟机200左右吧!应该很不错了!