Author Archives: Kevin

如何获取youtube缩略图

youtube视频默认提示4张缩略图,包括一张比较大的(默认的)以及三张较小的。 youtube视频都具有如下的地址:http://www.youtube.com/watch?v=VIDEO_ID 而其缩略图地址的格式如下:http://img.youtube.com/vi/VIDEO_ID/#.jpg (其中#为0,1,2,3)。 http://img.youtube.com/vi/VIDEO_ID/0.jpg是默认的缩略图(唯一的一张大尺寸缩略图480px X 360px)。其余三张为小尺寸(120px X 90px)。 因此在做youtube的功能时,只需要知道该视频的地址,就能通过字符串操作函数很方便得获取这些缩略图的图片路径。

Posted in wordpress原创文章 | Tagged , , , | Leave a comment

运用playlists实现Youtube多视频连续播放功能

对于做网站项目外包的朋友来说,嵌入youtube视频已经是一个再常见不过的功能了。embed嵌入代码很方便实用。但遇到要求多youtube视频连续播放的项目,却还真是没接触过。 试了许多视频播放插件,都不尽人意。 其实完全没必要那么麻烦。 youtube自带的Playlists(播放列表)功能就能满足此需要。 1. 登陆自己的youtube账号。 2. 点击My Videos(我的视频)。 3. 在My videos&playlists(我的视频和播放列表)里,创建一个新的playlists。选择类型为public并且允许别人使用播放列表的嵌入代码。 4. 之后当你浏览任何youtube视频的时候,你都可以将它加入到你创建的这个playlist里面。 5. 在你的playlist里面点击share按钮,就能取得嵌入代码。 6. 像嵌入单个youtube视频那样嵌入这段代码就可以了。 7. youtube视频代码提供了很多参数,这些参数同样可以用于playlist的代码中,具体参数参照http://code.google.com/apis/youtube/player_parameters.html

Posted in wordpress原创文章 | Tagged , , , , , | Leave a comment

如何写WordPress Child Themes

Child Theme 是用来改写主题的一个好方法。 对于很多收费主题来说,主题作者都会有或多或少的更新,比如主题框架功能的更新完善。 我们自己定制化后的这些主题,更新以后会丢失定制化的部分,所以选择child theme方式来定制这类主题,是个不错的方式。 Child Theme的编写基本规则: 1. Child Theme的文件位置 跟普通theme主题一样,都位于wp-content/themes下面。 2. Child Theme的文件结构 Child Theme对文件的要求要简单一些, 只有style.css是必需的,别的文件都是可有可无的。 具体如下:style.css (必需)      functions.php (可选)           Template files (可选)          Other files (可选) 3. style.css文件结构要求 以给默认主题Twenty Eleven写Child Theme为例: /* Theme Name: Twenty Eleven Child Theme … Continue reading

Posted in wordpress原创文章 | Tagged , , , | Leave a comment

wordpress获取当前登录用户信息的方法

1). get_currentuserinfo(); 此函数将当前登录用户信息赋给全局变量$current_user以及一些单独的用户信息全局变量例如$display_name, $user_email等。 代码如下: <?php global $current_user, $display_name , $user_email; get_currentuserinfo(); //全局变量$current_user echo ‘Username: ‘ . $current_user->user_login . “\n”; echo ‘User email: ‘ . $current_user->user_email . “\n”; echo ‘User first name: ‘ . $current_user->user_firstname . “\n”; echo ‘User last … Continue reading

Posted in wordpress原创文章 | Tagged , , , | Leave a comment

wordpress数据库查询相关类,对象,函数的整理

1). WP_Query 是一个wordpress类,而$wp_query 是一个WP_Query的实例化对象。 我们可以用 WP_Query()来实现。 <?php // The Query $the_query = new WP_Query( $args ); ?> WP_Query提供了大量的参数,包括author,category, tag, taxonomy, post&page, type&status, pagination, offset, order&orderby, sticky post, time, custom field, permission.  另外还提供了Filters方式,从而可以进一步定制查询sql语句。 包括:posts_distinct, posts_groupby, posts_join, post_limits, posts_orderby, posts_where, posts_join_paged, posts_where_paged,posts_clauses. … Continue reading

Posted in wordpress原创文章 | Tagged , , , , , , | Leave a comment

用css模拟firefox,chrome,IE等浏览器通用的title标签换行效果

链接的title标签是html最常用到的标签之一,文字多了,title标签里的内容会自动换行。 如link  代码如下:<a href=”#” title=”title title title title title title title title title title title title title title title title title title title title title title title title title title title title title title title title title title title title … Continue reading

Posted in wordpress原创文章 | Tagged , , , , | Leave a comment

去掉wordpress后台post,page等编辑页的sidebar相关模块

对普通用户来说,可以通过使用wordpress3+的Show on screen功能,只显示自己希望的screen Options。 但是对于wordpress开发者来说,有时候想彻底将某一右边栏的栏目去掉, 可以使用remove_meta_box函数。比如我们想让author用户只能在默认分类中发表文章post,则可以去掉发表文章界面右边的选择分类模块。 具体代码如下: // 判断是否在后台管理页面 if (is_admin()) : function my_remove_meta_boxes() { //判断登陆用户是否是author角色 if(!current_user_can(‘author’)) { // 是author,则去掉选择分类模块 remove_meta_box(‘categorydiv’, ‘post’, ‘normal’); } } // admin_menu hook. add_action( ‘admin_menu’, ‘my_remove_meta_boxes’ ); endif;

Posted in wordpress原创文章 | Tagged , , | Leave a comment

wordpress页面、用户权限、用户角色的判断

wordpress小提示:偶然间看到is_admin()函数,就莫名其妙的以为是检查该用户是否是管理员了。 正好打算检查登陆用户是否是author,所以就用了is_author来判断。  结果行不通,原来is_admin()是用来检测当前打开的页面是否为后台管理页面。 而is_author则顺理成章的是当前打开页面是否为作者页。 类似的还有is_404(), is_archive(), is_home()等。悲催啊。 正确的方法是用current_user_can()函数来判断当前用户的权限。  其参数接受capability(权限)或者是role name(角色名)。 <?php // 如果当前用户的角色是 editor, 则 current_user_can(‘administrator’) # => false current_user_can(‘editor’) # => true current_user_can(‘contributor’) # => false current_user_can(‘subscriber’) # => false //而判断权限的如下函数结果都为true current_user_can(‘edit_posts’) current_user_can(‘delete_posts’) current_user_can(‘manage_categories’) //而下面的就是false,因为editor并没有激活插件的权限。 current_user_can(‘activate_plugins’) ?>

Posted in wordpress原创文章 | Tagged , , , , | Leave a comment

删除wordpress缩略图功能

我个人还是很喜欢wordpress的缩略图功能的,感觉很强大,能生成适合自己使用的多种尺寸的wordpress缩略图。 但有的朋友不这么认为, 可能他上传的图片都是自己希望的尺寸,或者可能收到服务器空间小的制约。 这时候禁用wordpress的缩略图功能就是一个不错的选择了。 将width(宽度)和Height(高度)等等都设置为0就可以了。 设置后如图:

Posted in wordpress原创文章 | Tagged , , , | Leave a comment

wordpress分页(默认分页,分页插件,文章内分页)

方法一:wordpress自带的分页函数,包括文章内分页。 wordpress自带的分页函数包括previous_posts_link()和next_posts_link()。previous_posts_link()将获取前一文章查询的所有的posts,假如你后台设置的5篇文章换页,就会显示前5篇文章;如果设置的是10篇文章换页则会显示前10篇文章。 next_posts_link()类似。 具体查看http://codex.wordpress.org/Function_Reference/previous_posts_link和http://codex.wordpress.org/Function_Reference/next_posts_link 同样的可以使用previous_post_link和next_post_link来只显示一篇文章,通常用于单篇日志模板中,用来显示之前或之后的一篇文章。 文章内分页相信也是很多朋友经常用到的。如果自己写了一篇几千甚至上万字的博文(哇。。。),一页显示太长怎么办。这时候就要用到文章内分页功能了。 wordpress提供了函数wp_link_pages().  官方地址http://codex.wordpress.org/Function_Reference/wp_link_pages。 要使用该函数,你需要在编辑日志的时候以HTML模式加入<!–nextpage–>标签来实现文章内分页。 方法二:使用WP-Paginate插件。 插件的安装就不再赘余。安装以后可以查看插件的readme.txt查看具体用法。大体思路是该插件提供了几个函数,用来替换wordpress自带的分页函数。 你需要修改主题的相关文件。 1. 打开主题文件,wordpress3.0+的在loop.php里面。之前版本在index.php,archive.php以及search.php里面都有(Ps. 因为首页,存档以及搜索结果页都涉及显示多篇日志,所以这些模板都需要改)。 2. 用wp_paginate()函数来替换默认的previous_posts_link()以及next_posts_link()。 可以先验证下wp_paginate()函数是否存在, 具体代码如下: <?php if(function_exists(‘wp_paginate’)) { wp_paginate(); } ?> 3. WP-Paginate插件同样提供了评论的分页功能,用来替换默认的previous_comments_link()和next_comments_link()。 代码如下: <?php if(function_exists(‘wp_paginate_comments’)) { wp_paginate_comments(); } ?> 4. 你可以去后台的插件配置那里更改一下分页的显示图标,文字之类的。弄成自己喜欢的样子。 方法三:pagebar插件。使用方法和wp-paginate类似。 安装以后替换wordpress的默认分页函数。 同样也可以在后台该插件那里修改配置。 默认样式有点囧。 … Continue reading

Posted in wordpress原创文章 | Tagged , , , , , | Leave a comment