如果谈绿色, 谈低碳, 那我们公司做的, 那叫一个环保集约, 举例来说: 几乎所有的数据load, 都是lazy的(PartialObject). 譬如:
你要显示一个新闻列表, 那数据库发来得只有连接给标题, 没有内容啊 附件啊, 等你要打开显示详情了, 再去load. 出于这么一个环保节约的理念, 今天在研究Wordpress文档时惊讶的发现, 哇, wp也很环保呀, 试看:
Some post-related data is not available to get_posts by default, such as post content through the_content(), or the numeric ID. This is resolved by calling an internal function setup_postdata(), with the $post array as its argument.
我们天真的以为wp也很环保啊, 我英文也不球行, 以为是lazy的, 于是在只想做个新闻列表的时候不想load content. 但是来回翻了几遍代码, 发现没有处理PartialObject的地方!
我们老板比较熟悉PHP, 在qury.php中发现了猫腻, 加了个debug打印, 抓图奉上:
请看仔细: 是Select wp_posts.*, 也就是说, 虽然只想打印一个Recent Posts, 但从数据库load的时候, 你会load他的标题, 作者, 时间, 内容(MySql类型为: longtext) — 当然这只是从数据库load到服务器, 并不一定直接表现在网页上, 但在如果流量极大的情况下, 如此频繁并剧烈的Select, 相比会大大延缓速度.
如果wp一直这样load数据, 那必须得用cache了.
也就是说, 数据是一次load全部的, setup_postdata($post)只是设定值,而不是读取完整的对象,
对于get_posts()后, 取得post Attribute的方法:
文档中要求:
1。 要使用形如get_the_ID(), get_the_title()等方法, 需要先进行setup_postdata($post)
2。 或者直接使用形如: $post->ID, (注意Column名要写对)
从此处推理或从代码中搜索亦可印证: setup_postdata($post)作用只是对数据库读取的值进行处理,以便使用get_the_ID()等方式直接获取Attribute.
对于普通用户来讲:
用越多的Recent, Related, Random的Post会成倍增加SELECT的数量与对数据库的压力(当然, 前提是你博客流浪巨大的情况下, 如果只是跟本站一般低迷, 就不需要考虑这么多了)
废话一句: qury.php里的method好长啊
用Wordpress这么久了, 从没看过文档也没用过API. 近期有如此需求, 譬如说我站内已有一个网站, 另有一个Wordpress, 两个都在一个主机上, 我希望在WordPress之外使用其API, 显示文章列表啊什么的.
发现有如下之参考: see: http://www.webopius.com/content/139/using-the-wordpress-api-from-pages-outside-of-wordpress
在php文档一开头就声明:
<?php define('WP_USE_THEMES', false); ?> <?php require('wp-blog-header.php');?>
此后, WordPress API可用.
的确可用.
但今天在讨论Wordpress读取post的SQL时对qury进行了debug, 发现, 只要include/require了 wp-blog-heard.php就会立马辗转Call一下Classes.query_posts(), 先查询10个post再说.
分析后发现不可引用wp-blog-heard.php, 转而引用:wp-load.php就够.
因此, 如果需要在站外使用API, php声明:
define('WP_USE_THEMES', false); require 'C:\xampp\htdocs\wp\wp-load.php'; // instead of wp-blog-header.php
无需注册,立即获得代码: http://www.streampad.com/getit#
将获得后的代码放入网页中 放置妥当后, 会自动播放网页中的mp3链接.如包含:
我这里放了个mp3链接,所以才会播放!
总之:
有两个条件:
1. js代码已放入网页中 – 播放器有了
2. 网页中包含有mp3链接- 要播放的音乐有了.
演示:http://liguoliang.com/2010/03/1187/
另外: 简洁直接的播放器, 尤其适合一般音乐不多的情况下:
演示 : http://liguoliang.com/2009/05/927/
更多的http://hi.baidu.com/huipk/blog/item/8a7b02086e1a92d062d98694.html
出现形如: “You do not have sufficient permissions to update plugins for this blog”的错误
今天帮老刘升级WordPress时出现这个错误, 很晕,据 http://wordpress.org/support/topic/230668 知:
原因在于表*options表中的user_roles 数据不准确, 如你也碰到此类问题, 又想启用自动更新, 你可拷贝以下将你的覆盖掉.
a:5:{s:13:"administrator";a:2:{s:4:"name";s:13:"Administrator";s:12:"capabilities";a:53:{s:13:"switch_themes";b:1;s:11:"edit_themes";b:1;s:16:"activate_plugins";b:1;s:12:"edit_plugins";b:1;s:10:"edit_users";b:1;s:10:"edit_files";b:1;s:14:"manage_options";b:1;s:17:"moderate_comments";b:1;s:17:"manage_categories";b:1;s:12:"manage_links";b:1;s:12:"upload_files";b:1;s:6:"import";b:1;s:15:"unfiltered_html";b:1;s:10:"edit_posts";b:1;s:17:"edit_others_posts";b:1;s:20:"edit_published_posts";b:1;s:13:"publish_posts";b:1;s:10:"edit_pages";b:1;s:4:"read";b:1;s:8:"level_10";b:1;s:7:"level_9";b:1;s:7:"level_8";b:1;s:7:"level_7";b:1;s:7:"level_6";b:1;s:7:"level_5";b:1;s:7:"level_4";b:1;s:7:"level_3";b:1;s:7:"level_2";b:1;s:7:"level_1";b:1;s:7:"level_0";b:1;s:17:"edit_others_pages";b:1;s:20:"edit_published_pages";b:1;s:13:"publish_pages";b:1;s:12:"delete_pages";b:1;s:19:"delete_others_pages";b:1;s:22:"delete_published_pages";b:1;s:12:"delete_posts";b:1;s:19:"delete_others_posts";b:1;s:22:"delete_published_posts";b:1;s:20:"delete_private_posts";b:1;s:18:"edit_private_posts";b:1;s:18:"read_private_posts";b:1;s:20:"delete_private_pages";b:1;s:18:"edit_private_pages";b:1;s:18:"read_private_pages";b:1;s:12:"delete_users";b:1;s:12:"create_users";b:1;s:17:"unfiltered_upload";b:1;s:14:"edit_dashboard";b:1;s:14:"update_plugins";b:1;s:14:"delete_plugins";b:1;s:15:"install_plugins";b:1;s:13:"update_themes";b:1;}}s:6:"editor";a:2:{s:4:"name";s:6:"Editor";s:12:"capabilities";a:34:{s:17:"moderate_comments";b:1;s:17:"manage_categories";b:1;s:12:"manage_links";b:1;s:12:"upload_files";b:1;s:15:"unfiltered_html";b:1;s:10:"edit_posts";b:1;s:17:"edit_others_posts";b:1;s:20:"edit_published_posts";b:1;s:13:"publish_posts";b:1;s:10:"edit_pages";b:1;s:4:"read";b:1;s:7:"level_7";b:1;s:7:"level_6";b:1;s:7:"level_5";b:1;s:7:"level_4";b:1;s:7:"level_3";b:1;s:7:"level_2";b:1;s:7:"level_1";b:1;s:7:"level_0";b:1;s:17:"edit_others_pages";b:1;s:20:"edit_published_pages";b:1;s:13:"publish_pages";b:1;s:12:"delete_pages";b:1;s:19:"delete_others_pages";b:1;s:22:"delete_published_pages";b:1;s:12:"delete_posts";b:1;s:19:"delete_others_posts";b:1;s:22:"delete_published_posts";b:1;s:20:"delete_private_posts";b:1;s:18:"edit_private_posts";b:1;s:18:"read_private_posts";b:1;s:20:"delete_private_pages";b:1;s:18:"edit_private_pages";b:1;s:18:"read_private_pages";b:1;}}s:6:"author";a:2:{s:4:"name";s:6:"Author";s:12:"capabilities";a:10:{s:12:"upload_files";b:1;s:10:"edit_posts";b:1;s:20:"edit_published_posts";b:1;s:13:"publish_posts";b:1;s:4:"read";b:1;s:7:"level_2";b:1;s:7:"level_1";b:1;s:7:"level_0";b:1;s:12:"delete_posts";b:1;s:22:"delete_published_posts";b:1;}}s:11:"contributor";a:2:{s:4:"name";s:11:"Contributor";s:12:"capabilities";a:5:{s:10:"edit_posts";b:1;s:4:"read";b:1;s:7:"level_1";b:1;s:7:"level_0";b:1;s:12:"delete_posts";b:1;}}s:10:"subscriber";a:2:{s:4:"name";s:10:"Subscriber";s:12:"capabilities";a:2:{s:4:"read";b:1;s:7:"level_0";b:1;}}}
今天录了段音, 想放上来, 想搞个稍微花哨的播放器. 顺手找到的俩假单的, look:
1. 使用站点: http://www.blogcastone.net/ 填入mp3地址, 然后加入生成的代码
2. 直接使用flash的player, 手动改代码其实也慢方便的:
如: Google Reader的:
代码:
效果:
// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.