-
Wordpress去插件化之合并插件
Posted in 技术分享, 辐射鱼
-
前段时间我和大家分享过Wordpress主题之去插件化,让主题使用者避免了安装主题却忘记启用主题必须的插件时出错的尴尬,但这还不是我们的最终目的,一旦主题使用者一直忘记启用相应的插件,那他就看不到插件带来的个性化效果,这有违主题创作的初衷!合并插件到functions.php文件里,就能很好解决这一冲突!
- 首先,确定你所使用的插件的调用代码
- < ?php if(function_exists('get_mostcommented')) { get_mostcommented($limit = 10); } ?>
- 其次,移植插件代码
- /* Mostcommented Topics */
- function get_mostcommented($limit = 12) {
- global $wpdb, $post;
- $mostcommenteds = $wpdb->get_results("SELECT $wpdb->posts.ID, post_title, post_name, post_date, COUNT($wpdb->comments.comment_post_ID) AS 'comment_total' FROM $wpdb->posts LEFT JOIN $wpdb->comments ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID WHERE comment_approved = '1' AND post_date_gmt < '".gmdate("Y-m-d H:i:s")."' AND post_status = 'publish' AND post_password = '' GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_total DESC LIMIT $limit");
- foreach ($mostcommenteds as $post) {
- $post_title = htmlspecialchars(stripslashes($post->post_title));
- $comment_total = (int) $post->comment_total;
- echo "<li><a href=\"".get_permalink()."\">$post_title <strong>($comment_total)</strong></a></li>";
- }
- }
- 最后,停掉你所使用的插件,现在你就可以挥一挥手作别昨天的烦恼了!
比如我在Thirdinfo.com的侧栏调用了热评文章,代码如下:
复制代码到wp-content/themes/yourtheme/functions.php文件第一行后面,如果没有,请新建之。下面是我的热评文章代码:
注意:移植有选择项的插件相当麻烦,请谨慎使用!
如果你有新颖的wordpress技巧,不妨投稿至admin#wopus.org和大家一起分享?!关联阅读






4 Comments
[...] Wordpress去插件化之合并插件 [...]
你的方法,是不是在插件编辑那里,把那个插件的代码都复制到functions.php里?
而且好像那些插件的代码好长?
@ Poshi ,是的,放到function.php里。