Author: 迎迎 姚
Adding Taxonomy Filter to Admin posts List for Custom Post Type
在 wordpress 默认的文章 class TerminQuery{ public function __construct() { add_filter(‘parse_query’,array($this, ‘query’)); add_action(‘restrict_manage_posts’,array($this, ‘restrict’)); } function query($query) { global $pagenow; global $typenow; $qv = &$query->query_vars; if ($typenow!=’post’ && $pagenow==’edit.php’) { $taxonomies = get_object_taxonomies($typenow); foreach ($taxonomies as $taxonomy) { if (isset($qv[$taxonomy]) && is_numeric($qv[$taxonomy])) { $term = get_term_by(‘id’,$qv[$taxonomy],$taxonomy); $qv[$taxonomy] = ($term ? $term->slug : ”); } } }…
定制 WordPress 的默认 Query
One of the most powerful features of WordPress is the WP Query. It is what determines what content is displayed on what page. And often you’ll want to modify this query to your specific needs. Some examples: Don’t display posts from Category X on the homepage Increase or decrease the number of posts displayed per…
20段Web开发不容错过的CSS代码
Web开发技术每年都在革新,浏览器已逐渐支持CSS3特性,并且网站设计师和前端开发者普遍采用这种新技术进行设计与开发。但仍然有一些开发者迷恋着一些CSS2代码。 本文将分享20段非常专业的CSS2/CSS3代码供大家使用,你可以把它们保存在IDE里、或者存储在CSS文档里,这些代码片段绝对会给你带来意外的惊喜。 1. CSS Resets 网络上关于CSS重置的代码非常多。本段代码是根据Eric Meyer’s reset codes进行改编的,里面包含一点响应式图片和所有核心元素的边界框设置,这样就可以保持页边距和填充可以很好地对齐。 html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd,…
WPML:Get posts also available in other languages
文章页面里,在文章的底部显示该篇文章对应的翻译的语种(国旗)和标题。 暂时没有发现有现成的函数或 API 接口。但是从WPML 的表里面不难看出他们的关系,通过一句SQL即可找出当前文章对应文章的ID, 如下: function _post_foot_languages(){ global $post, $wpdb, $sitepress; $active_languages = $sitepress->get_active_languages(); unset($active_languages[ICL_LANGUAGE_CODE]); //print_r(array_keys($active_languages)); $source_language_code = “”; if(ICL_LANGUAGE_CODE != $sitepress->get_default_language()) $source_language_code = ” and source_language_code = ‘”.$sitepress->get_default_language().”‘”; $query =” SELECT * FROM {$wpdb->prefix}icl_translations WHERE trid = ( SELECT trid FROM {$wpdb->prefix}icl_translations WHERE element_id = {$post->ID}{$source_language_code}) AND language_code in (‘”.join(‘\’,\”,array_keys($active_languages)).”‘)”; //AND language_code !=…
Get costom post type taxonomies
returning array of taxonomies about a custom post type like array( [0] =>taxonomy_name1, [1] =>taxonomy_name2 ) Code function _get_post_taxonomies($post_type) { // Passing an object // Why another var?? $output = ‘objects’; // name / objects $taxonomies = get_object_taxonomies($post_type); /*// Passing a string using get_post_type: return (string) post, page, custom… $post_type = get_post_type($post); $taxonomies = get_object_taxonomies($post_type,…
How to register new post type with new taxonomy
这篇文章我将详细叙说如何在 WordPress 里运用 register_post_type 和 register_taxonomy添加新的文章类型和分类。 例如我们要新建一个文章类型叫 wine, 与之相对应的分类有两个,分别为 type, region。 所以我们大致需要这些数据,我把他们放到一个数组里: $plugin_name = ‘yaocms’; $portfolio_type = array( ‘type’ => ‘wine’, //注册在数据库里的文章类型 ‘name’ => __(‘Wine’, $plugin_name), //后台里显示菜单名称 ‘singular’ => __(‘Wine’, $plugin_name), //单数形式 ‘capability’ => ‘page’, //兼容模式,page 或 post ‘supports’ => array(‘title’, ‘editor’, ‘thumbnail’, ‘page-attributes’), //默认支持的字段,依次是:标题,主编辑区域,特色图片,排序 ‘slug’ => ‘wine-view’, //显示在前端url里: https://yaoyingying.com/{$this slug}/文章名 ‘taxonomy’ => array( //分类学…
让 jQuery Datepicker 兼容 WordPress 和 WPML
没什么好说的,直接代码: jQuery(function($){ $.datepicker.regional[‘zh-hans’] = $.datepicker.regional[‘zh_CN’] = { closeText: ‘关闭’, prevText: ‘<上月’, nextText: ‘下月>’, currentText: ‘今天’, monthNames: [‘一月’,’二月’,’三月’,’四月’,’五月’,’六月’, ‘七月’,’八月’,’九月’,’十月’,’十一月’,’十二月’], monthNamesShort: [‘一’,’二’,’三’,’四’,’五’,’六’, ‘七’,’八’,’九’,’十’,’十一’,’十二’], dayNames: [‘星期日’,’星期一’,’星期二’,’星期三’,’星期四’,’星期五’,’星期六’], dayNamesShort: [‘周日’,’周一’,’周二’,’周三’,’周四’,’周五’,’周六’], dayNamesMin: [‘日’,’一’,’二’,’三’,’四’,’五’,’六’], weekHeader: ‘周’, dateFormat: ‘yy-mm-dd’, firstDay: 1, isRTL: false, showMonthAfterYear: true, yearSuffix: ‘年’}; $.datepicker.setDefaults( $.datepicker.regional[ “<?php echo defined(‘ICL_LANGUAGE_CODE’)?ICL_LANGUAGE_CODE:WPLANG;?>” ] ); }); 最后一行,这儿由于 WPML 和 WORDPRESS 的语言静态变量不一样,值也不同,需要判断然后输出,输出的值可能是 zh-hans,或 zh_CN,所以在第一行声明了两个变量来存储翻译。
CarouFredSel中TouchSwipe不支持带链接的元素
http://caroufredsel.dev7studios.com/configuration.php caroufredsel 的配置页面里提到 swipe 这个属性:To enable this feature, you’ll need to include the jQuery.touchSwipe-plugin. 如果 HTML 结构是这样 <div class=”image_carousel”> <ul id=”carousel”> <li><img src=”slier.jpg”/><li> <li><img src=”slider2.jpg”/><li> </ul> </div> 你可以这样使这个幻灯片支持touchswipe <script> $(“#carousel”).carouFredSel({ auto : false, prev : ‘#c-prev’, next : ‘#c-next’, swipe : { onTouch : true, onMouse : true } }); </script> 倘若这个幻灯片的图片带来链接: <ul id=”carousel”> <li><a href=”foo.html”><img…