Archive for 2009 November
2009November . 9th

成为一个优秀WordPress开发者的10条秘诀

成为一个优秀的Wordpress开发者是很多WPer的梦想,这次大家来看看国外开发者Mike Smith的经验。

1.为自己的主题创建方便定制的选项面板

如果你有留意收费主题的发展趋势,你会发现带有一个方便用户个性化的选项面板已经是收费主题的标配。其实为主题做一个选项面板,无论是对主题的用户还是自己使用都是有很大的帮助的。通过一个选项面板,用户可以自定义广告,FEED订阅器等,而不必接触繁琐的代码,因此作为一个开发者,你应该知道如何去创建一个主题选项面板。
如果你还不懂得这个技术,可以阅读MG12的教程:《主题技巧: 为主题添加管理选项》

2009November . 7th

无Gzip模块主机实现Gzip压缩js和css

众所周知,开启Gzip能极大地压缩文本数据的体积,可是有的主机上并没有安装Gzip模块(例如我现在使用的主机),因此不能通过写.htaccess文件或者httpd参数等方法开启Gzip压缩功能。今天给大家介绍两个兄弟版的WordPress插件:WP CSSWP JS,作者都是Halmat Ferello

WP CSS

WP CSSWP CSS能自动清除使用@import参数载入的CSS文件里的空格,并生成缓存文件,在浏览器发出请求时以Gzip的方式输出。这样就不需要每次加载CSS的时候都进行动态压缩,降低了服务器负担。

点评

经过WP CSS压缩后的CSS文件经本人测试在IE系列兼容性较差的浏览器上都能正常解析。但在进行W3C CSS在线验证时会产生未知错误(当然,CSS还是符合W3C标准的),原因未明。

2009November . 6th

为主题添加AJAX提交评论功能

本文参考了Xiaorsz的使用 jQuery 实现 wordpress 的 Ajax 留言
前几天,为了提高评论体验,为了减轻服务器负担,我为主题添加了AJAX提交评论功能,现在分享一下方法。
首先需要在主题的function.php文件里添加一段函数:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
< ?php
function fail($s) {
    header('HTTP/1.0 500 Internal Server Error');
    echo $s;
    exit;
}
 
function ajax_comment(){
 
if($_POST['action'] == 'ajax_comment') {
 
    global $wpdb, $db_check;
        // Check DB
        if(!$wpdb->dbh) {
            echo('Our database has issues. Try again later.');
			die();
        } 
nocache_headers();
$comment_post_ID = (int) $_POST['comment_post_ID'];
 
$status = $wpdb->get_row("SELECT post_status, comment_status FROM $wpdb->posts WHERE ID = '$comment_post_ID'");
if ( empty($status->comment_status) ) {
    do_action('comment_id_not_found', $comment_post_ID);
    fail('The post you are trying to comment on does not currently exist in the database.');
} elseif ( 'closed' ==  $status->comment_status ) {
    do_action('comment_closed', $comment_post_ID);
    fail('Sorry, comments are closed for this item.');
} elseif ( in_array($status->post_status, array('draft', 'pending') ) ) {
    do_action('comment_on_draft', $comment_post_ID);
    fail('The post you are trying to comment on has not been published.');
}
$comment_author       = trim(strip_tags($_POST['author']));
$comment_author_email = trim($_POST['email']);
$comment_author_url   = trim($_POST['url']);
$comment_content      = trim($_POST['comment']);
// If the user is logged in
$user = wp_get_current_user();
if ( $user->ID ) {
    $comment_author       = $wpdb->escape($user->display_name);
    $comment_author_email = $wpdb->escape($user->user_email);
    $comment_author_url   = $wpdb->escape($user->user_url);
    if ( current_user_can('unfiltered_html') ) {
        if ( wp_create_nonce('unfiltered-html-comment_' . $comment_post_ID) != $_POST['_wp_unfiltered_html_comment'] ) {
            kses_remove_filters(); // start with a clean slate
            kses_init_filters(); // set up the filters
        }
    }
} else {
    if ( get_option('comment_registration') )
        fail('Sorry, you must be logged in to post a comment.');
}
$comment_type = '';
if ( get_option('require_name_email') && !$user->ID ) {
    if ( 6> strlen($comment_author_email) || '' == $comment_author )
        fail('Sorry: please fill the required fields (name, email).');
    elseif ( !is_email($comment_author_email))
        fail('Sorry: please enter a valid email address.');
}
if ( '' == $comment_content )
    fail('Sorry: please type a comment.');
// Simple duplicate check
$dupe = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = '$comment_post_ID' AND ( comment_author = '$comment_author' ";
if ( $comment_author_email ) $dupe .= "OR comment_author_email = '$comment_author_email' ";
$dupe .= ") AND comment_content = '$comment_content' LIMIT 1";
if ( $wpdb->get_var($dupe) ) {
    fail('Duplicate comment detected; it looks as though you\'ve already said that!');
}
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'user_ID');
if( !$user->ID ){
	$result_set = $wpdb->get_results("SELECT display_name, user_email FROM $wpdb->users WHERE display_name = '" . $comment_author . "' OR user_email = '" . $comment_author_email . "'");
	if ($result_set) {
	if ($result_set[0]->display_name == $comment_author){
	fail( __('Error: you are not allowed to use the nickname that you entered.if you are the administrator you hava to login to comment.','philna2') );
	} else {
	fail( __('Error: you are not allowed to use the email that you entered.if you are the administrator you hava to login to comment.','philna2') );
	}
	}
}
$comment_id = wp_new_comment( $commentdata );
$comment = get_comment($comment_id);
 
if( !$user->ID ){
	setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
	setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
	setcookie('comment_author_url_' . COOKIEHASH, clean_url($comment->comment_author_url), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
}
@header('Content-type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
?>
	//这里需要粘贴你的评论框架代码,不过相关的调用代码有所变化:
	//评论ID:$comment->comment_ID
	//评论者名字:$comment->comment_author
	//判断评论者是否填写了网站地址:$comment->get_comment_author_url
	//评论者URL:$comment->comment_author_url
	//评论时间:mysql2date(__('F jS, Y'),$comment->comment_date)
	//评论者e-mail:$comment->comment_author_email
	//评论内容$comment->comment_content
< ?php
	die();
}
}
add_action('init', 'ajax_comment');
//添加AJAX评论钩子
?>
2009November . 4th

2010年网页设计趋势

网页设计就像时装,每一年都会流行新的设计。一起来看看2010年,网页设计师们将会有什么新搞作。

巨大的Logo/头部

巨大的头部
设计理念:巨大的头部能令访客第一时间记住你。

Subscriber selector

Close