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 …

定制 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 …

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().”‘”; …

wpml translate blogroll Link categories

我没有找到更好的办法,后来想了另一个办法: 由于WPML 是可以翻译widget title 的,所以我新建一个 blogFoll 的widget,可以填写标题,选择想要显示的分类。 直接粘贴到主题文件的functon.php 里即可。 if (!class_exists(‘LinksList_Widget’)) : class LinksList_Widget extends WP_Widget { const LANG = ‘yaocms’; function __construct() { $widget_ops = array( ‘classname’ => strtolower(get_class($this)) …

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 = …

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’, …

让 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: …

How to make Popularity Posts Widget compatible with WPML

In table $prefix_PopularityPostsWidget  The view record store here like this: There is WPML function wpml_get_language_information can get the post language information by post id, like this wpml_get_language_information($post->ID)   Array ( [locale] => fr_FR [text_direction] => [display_name] => Français [native_name] => Français [different_language] => ) Array ( [locale] => en_US [text_direction] => [display_name] => …

为WordPress[gallery]短标签里的图片链接添加更多属性

Add rel Attribute to Image Links in WordPress Galleries 如果你想给[ gallery ] 里的图片链接加上而外的属性, rel 或者 class 等等,去配合使用 fancybox、 lightbox 等 jQuery 插件。代码如下: If you want to use either Fancybox or Lightbox scripts for image galleries, …

获取某个分类下所有文章相关的标签

  获取某个分类(Category)下所有文章相关的标签(TAGS) 首先获取分类下的所有文章: query_posts(array( ‘post_type’ => ‘portfolio’, ‘showposts’ => -1, ‘tax_query’ => array( array( ‘taxonomy’ => ‘portfolio-class’, ‘terms’ => $the_taxonomy, ‘field’ => ‘term_id’, ) ), ‘orderby’ => ‘date’, ‘order’ => …

Simple WPML language switch

公司客户老喜欢吧 语言选择器 做成这样~ 麻烦~ function icl_post_languages(){ $languages = icl_get_languages(‘skip_missing=0&orderby=code’); if(1 < count($languages)){ $langs[] = ‘<div class=”languages”>’; foreach($languages as $l){ if($l[‘language_code’] == ‘zh-hans’) $l[‘language_code’] = “中文”; $active = $l[‘active’] == 1?”class=’active_language'”:””; …

WordPress Get Root Page ID

this snipet will show you how to get root page id and title in wordpress! global $post; $parent_id = $post->post_parent; $post_id = $post->ID; $ancestors = get_post_ancestors($post_id); $root_id = (!empty($ancestors) ? …

send_to_editor get audio address and id

这个方法会导致 WordPress 编辑器原本的插入媒体功能失效! /* * To change this template, choose Tools | Templates * and open the template in the editor. */ add_filter(‘media_send_to_editor’, ‘media_editor’, 1, 3); function media_editor($html, $send_id, $attachment …

自动吧上传的第一张图片设置为特色图像

function autoset_featured() { global $post; $already_has_thumb = has_post_thumbnail($post-&gt;ID); if (!$already_has_thumb) { $attached_image = get_children( “post_parent=$post-&gt;ID&amp;post_type=attachment&amp;post_mime_type=image&amp;numberposts=1” ); if ($attached_image) { foreach ($attached_image as $attachment_id =&gt; $attachment) { set_post_thumbnail($post-&gt;ID, $attachment_id); } } …

WordPress add a theme options page

<?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ add_action(‘admin_menu’, ‘my_theme_options_menu’); function my_theme_options_menu() { add_action(‘admin_print_scripts’, ‘my_options_admin_scripts’); add_action(‘admin_print_styles’, ‘my_options__admin_styles’); add_theme_page(‘My …

创建带有编辑器的字段,调整模块顺序。

国际惯例,效果: First: 创建custom post type ‘slider’ 和 slider 的分类 ‘city’ function yao_codex_custom_init() { $labels = array( ‘name’ => ‘Sliders’, ‘singular_name’ => ‘Slider’, ‘add_new’ => ‘Add New’, ‘add_new_item’ => ‘Add New …

Wordpres add meta box within duplicate image fields

这段代码可以实现在 meta box 里加入一个图片组(使用wordpress uploader)上传图片。 <?php function xxxx_repeat_image_fileds($cnt, $p = null) { if ($p === null) { $a = ”; $existing_image = ”; } else { $a = $p[‘n’]; $existing_image …

获取WordPress循环(loop)里的 key

Get current index position in loop in WordPress 获取当前元素的系列,只需要 $wp_query->current_post while (have_posts()) : the_post(); // Some basic wordpress template tags the_title(); the_content(); // Echo the current index position of the …

TimelineJS in WordPress

下载: https://github.com/VeriteCo/TimelineJS 演示:http://timeline.verite.co/ 首先要建立一个 custom post type 叫 timeline 添加一些测试数据之后,进行下一步。 取出数据生成JSON $timeline_args = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘timeline’ ); $timeline_array = array(); $timeline_list = new WP_Query($timeline_args); $index = …