wordpress 自定义文章类型(register_post_type)详解

functions.php添加以下代码

创建文章类型:

add_action('init', 'create_post_type');
function create_post_type()
{
   register_post_type('blog',
   array(
   'labels' => array(
   'name' => __('博客'),
   'singular_name' => __('博客')
    ),
   'public' => true,
   'has_archive' => true,
   'rewrite' => array('slug' => 'blog'),
   'supports' => array('title', 'editor', 'comments')
   )
  );
}

添加分类:

add_action('init', 'create_blog_taxonomies', 0);
function create_blog_taxonomies()
{
    $labels = array(
        'name' => '分类',
    );
    register_taxonomy('blogcate', array('blog'), array(
        'hierarchical' => true,
        'labels' => $labels,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => true,
//        'rewrite' => array('slug' => 'blogcate'),
    ));
}

前台模板文件:

taxonomy.php 或者 taxonomy-blogcate.php

jquery 加载 google-analytics

<script type=”text/javascript”>
var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.” : “http://www.”);
$.getScript(gaJsHost + “google-analytics.com/ga.js”,function(){
try {
var pageTracker = _gat._getTracker(“UA-123456-16″);
pageTracker._trackPageview();
} catch(err) {}
});
</script>

各浏览器中 Date 对象的 toLocaleString 方法的返回值不一致

问题分析

假设当前时间为 2009 年 12 月 29 日 12:00:16,地点为 中国 北京,测试以下代码:

alert(new Date().toLocaleString());

各浏览器下的输出结果,如下表所示:

各浏览器下的输出结果,如下表所示:

IE Firefox 2009年12月29日 12:00:161
Chrome Tue Dec 29 2009 12:00:16 GMT+0800 (China Standard Time)
Safari Tuesday, December 29, 2009 12:00:16
Opera 2009-12-29 12:00:16

可见:不能保证 Date.prototype.toLocaleString() 在各浏览器下返回相同的字符串。

解决方案


要获得相同格式的时间字符串,请不要使用 Date.prototype.toLocaleString() 方法,可以通过分别使用 getFullYear、getMonth、getDate 和 getDay 分别获得各关键字符串并拼装。

UBUNTU 10.04 搭建 nginx1.0.5+php5.3.5+php-fpm 环境

$ sudo -s

//添加源
sudo echo "deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main" /etc/apt/sources.list.d/nginx-stable-lucid.list
sudo echo "deb http://ppa.launchpad.net/nginx/php5/ubuntu lucid main" /etc/apt/sources.list.d/nginx-stable-lucid.list
sudo echo "deb-src http://ppa.launchpad.net/nginx/php5/ubuntu lucid main" /etc/apt/sources.list.d/nginx-stable-lucid.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C300EE8C
//更新源
sudo aptitude update
//安装nginx
sudo aptitude install nginx
//安装php及相关依赖
sudo aptitude install php5 php5-cgi php5-cli php5-mysql php5-memcached php5-gd php5-curl php-pear php-apc php-fpm
//启动
service nginx start
service php-fpm start
//测试
ps aux | grep nginx
root     14051  0.0  0.1  71092  1568 ?        Ss   May28   0:00 nginx: master process /usr/sbin/nginx
www-data 14052  0.1  0.2  72496  3568 ?        S    May28   3:47 nginx: worker process
ps aux | grep php
root     14238  0.0  0.3 182432  4944 ?        Ss   May28   0:25 php-fpm: master process (/etc/php5/fpm/main.conf)
www-data 14255  0.1  3.1 192428 48292 ?        S    May28   4:54 php-fpm: pool www
www-data 14256  0.1  4.0 207328 62988 ?        S    May28   4:43 php-fpm: pool www
www-data 14258  0.1  3.8 202720 59212 ?        S    May28   4:36 php-fpm: pool www
www-data 14291  0.1  3.6 199648 55496 ?        S    May28   4:39 php-fpm: pool www
www-data 14293  0.1  3.3 196576 52260 ?        S    May28   4:51 php-fpm: pool www
www-data 14294  0.1  3.4 196576 52952 ?        S    May28   4:47 php-fpm: pool www
www-data 14297  0.1  4.5 214756 70368 ?        S    May28   4:34 php-fpm: pool www
www-data 14298  0.1  3.1 192336 48900 ?        S    May28   4:46 php-fpm: pool www
www-data 14299  0.1  3.1 192332 48856 ?        S    May28   5:05 php-fpm: pool www
www-data 14300  0.1  2.9 191044 46132 ?        S    May28   4:58 php-fpm: pool www
//nginx 配置 路径 /etc/nginx/sites-avilable/example.com
$  vi  /etc/nginx/sites-avilable/example.com
server {
listen 80;
server_name www.example.com;
rewrite ^(.*) http://example.com$1 permanent;
}
server {
listen   80;
server_name  example.com;
access_log /var/log/nginx/example.com.access.log;
error_log /var/log/nginx/example.com.error.log;
root /var/www/example.com;
index  index.php index.html;
try_files $uri $uri/ /index.php?q=$1;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
location ~ /\.ht {
deny  all;
}
#添加软链

$ ln -s /etc/nginx/sites-availabe/example.com /etc/nginx/sites-enabled/example.com

#重启nginx
$service nginx restart
#配置hosts
$ vi /etc/hosts  //添加 127.0.0.1 example.com
#完成
访问:example.com
#1、 安装过程源找不到,请到“新立得”里手工加上
#2、 安装过程提示nginx-full/nginx错误导致php-fpm安装失败,请到“新立得”里重新安装php-fpm按提示强制删除nginx,然后再安装nginx。
#3、注意测试地址在:/var/www/example.com/XXXX.html

解决wordpress无法上传中文名文件

找开 :wordpress/wp-admin/includes/file.php

查找:$filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback );  //3.21版本在324行

在其后加上:

$fileTypeNameArr =explode(“.” , $filename);

$countNum=count($fileTypeNameArr)-1;

$fileExt =  $fileTypeNameArr[$countNum];  //取得所上传文件后缀名

$filename = time().’-’.rand(0,999999999).’.’.$fileExt; //将文件由原名改为时间戳

以后方法是上传的文件不再以中文存储,而是以时间戳为名称存储。

上传中文名的文件后,依然能够将原中文文件名作为文件的标题。

gitignore 忽略文件

1、在.git目录同一位置创建一个文件: .gitignore

2、如果要忽略的文件已被git管理,先移除:

git rm -r –cached  .idea/*

3、编辑.gitignore 文件添加需要忽略的文件或者目录

#dir
.idea/*

#file

config.xml