主题发布:Inpad
Inpad其实是我很久之前就开始构思的一个主题,可是当时做得十分失败。这次发布的Inpad代码已经全部经过重写,并且通过了详细的测试,错漏应该比较少了,就重新发布吧。

Inpad其实是我很久之前就开始构思的一个主题,可是当时做得十分失败。这次发布的Inpad代码已经全部经过重写,并且通过了详细的测试,错漏应该比较少了,就重新发布吧。

对于经常对大量文章进行编辑操作的童鞋来说,最麻烦的事就是修改完一篇文章以后需要保存,退出编辑,再打开下一篇文章进行编辑。
Admin Post Navigation是一款后台插件,在编辑文章的时候会在编辑器上方添加一个链接到上一篇文章和下一篇文章的导航栏,如下图。

最近给我的音乐博客修改主题,在主题发现了一段有趣的函数,可以自由定制Gravatar的默认头像,现在记录一下。
主函数如下,作用是获取Gravatar头像。
WordPress是一款成熟的开源CMS平台,新推出的2.9版本依然保持了以往良好的口碑。这篇文章从WordPress 2.9的codex文档里摘录出几个开发者应该留意的功能进行简析。
![]()
WordPress 2.9 一个比较重头的新功能就是提供了不需要自定义字段的文章缩略图功能,这将对使用者提供很大的便利,但由于一些兼容性的限制,你必须对主题的function.php文件进行修改才能使用这个功能。
在主题的function.php里添加如下代码,你就能使用WordPress的文章缩略图功能。
1 2 3 | if ( function_exists( 'add_theme_support' ) ) { //检查WP版本是否为2.9或以上版本 add_theme_support('post-thumbnails'); //如果WP版本符合最低要求则添加文章缩略图 } |

WordPress的模板非常灵活,一个优秀的模板所实现的功能往往超出你的想象。这篇文章说说在WordPress里调用文章的发布日期。
自从换了域名,换了主题以后,我一直努力令博客的浏览体验更加好,但因此也挂载了大量的JS文件,页面的载入速度一度变得非常缓慢。于是优化就迫在眉睫了。我的优化步骤是:
一般需要另外加载JS或者CSS的插件都会存在add_action(“wp_head”,”xxxx”)或者add_action(“wp_footer”,”xxxx”)这两句代码,目的是把自己的脚本或者样式插入到主题的wp_head()和wp_footer()处,使插件可以正常工作(那些反映说插件激活了但看不到效果的人注意了,我观察到相当一部分人所使用的主题不能正常加载插件的脚本,缺的就是这两个函数了)。
下面转回正题。我们需要优化载入进程,也就是流量整形,把CSS文件移到head里(这点100%的插件都能做到,不用担心),把JS文件放在页面最后。我们可以把add_action(xxxx)这句删掉,然后手工把所需的文件插入到主题模板里。
FEED是WEB 2.0时代一种重要的网站阅读手段。通过FEED订阅,用户不需要登录网站就可以了解到该网站上最新的更新。而且随着鲜果、Google Reader、Puto等网络阅读器的兴起,订阅喜欢的网站的FEED已经成为了网民中流行的一种阅读方式。
WordPress默认也提供FEED订阅接口,但其默认订阅地址却比较难记、难输入。WordPress的原始FEED地址有:
http://example.com/?feed=rss
http://example.com/?feed=rss2
http://example.com/?feed=rdf
http://example.com/?feed=atom
这几种,其中的区别是针对不同的协议进行不同的优化,以适应不同的订阅设备。下面用电脑上最常用的rss协议讲讲自定义WordPress FEED地址。
成为一个优秀的Wordpress开发者是很多WPer的梦想,这次大家来看看国外开发者Mike Smith的经验。
如果你有留意收费主题的发展趋势,你会发现带有一个方便用户个性化的选项面板已经是收费主题的标配。其实为主题做一个选项面板,无论是对主题的用户还是自己使用都是有很大的帮助的。通过一个选项面板,用户可以自定义广告,FEED订阅器等,而不必接触繁琐的代码,因此作为一个开发者,你应该知道如何去创建一个主题选项面板。
如果你还不懂得这个技术,可以阅读MG12的教程:《主题技巧: 为主题添加管理选项》
众所周知,开启Gzip能极大地压缩文本数据的体积,可是有的主机上并没有安装Gzip模块(例如我现在使用的主机),因此不能通过写.htaccess文件或者httpd参数等方法开启Gzip压缩功能。今天给大家介绍两个兄弟版的WordPress插件:WP CSS和WP JS,作者都是Halmat Ferello。
WP CSS能自动清除使用@import参数载入的CSS文件里的空格,并生成缓存文件,在浏览器发出请求时以Gzip的方式输出。这样就不需要每次加载CSS的时候都进行动态压缩,降低了服务器负担。
经过WP CSS压缩后的CSS文件经本人测试在IE系列兼容性较差的浏览器上都能正常解析。但在进行W3C CSS在线验证时会产生未知错误(当然,CSS还是符合W3C标准的),原因未明。
本文参考了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评论钩子 ?> |
Recent Comments