• 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) ? array_pop($ancestors): $post_id); $child_of = $root_id; $widget_title = get_the_title($root_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 ){ //get the media’s guid and append it to the…

  • a simple jQuery plugin that allows you to add a dynamically-resized, slideshow-capable background image to any page or element Uncaught TypeError: Object function (e,t){return new v.fn.init(e,t,n)} has no method ‘backstretch’ maybe many guys got this error Maybe the issue is ’cause…

  • Slide Up Menu / jQuery 向上弹出式菜单 The jQuery Slide Up Menu it’s a good alternative to other existing menus giving the possibility to position the menu on the bottom of your header image or at the bottom of the window,…

  • 在创建页面选择某个页面模板后,在 metabox 里会出现下面的模块,带有 tinyMCE 的文本域。 点击 add new,即可以添加一个新的文本域,点击 remove 可以删除对应的文本域。 对于某个页面里有很对相同小模块的比较有用。 效果如下图: /** * Calls the class on the post edit screen */ function xxxx_repeat_competences_fields($cnt, $p = null) { if ($p === null) { $a = ”; $i = ”;…

  • <?php echo get_option(‘page_on_front’); //home page ID echo get_option(‘page_for_posts’); ?>  

  • 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); } } } } add_action(‘the_post’, ‘autoset_featured’); add_action(‘save_post’, ‘autoset_featured’); add_action(‘draft_to_publish’, ‘autoset_featured’); add_action(‘new_to_publish’, ‘autoset_featured’);…

  • <?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 Plugin Theme’, ‘My Theme Options’, ‘administrator’, ‘my-theme-options’, ‘my_theme_options_function’); add_action(‘admin_init’, ‘register_mysettings’);…

  • 国际惯例,效果: 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 Slider’, ‘edit_item’ => ‘Edit Slider’, ‘new_item’ => ‘New Slider’, ‘all_items’…

  • 这段代码可以实现在 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 = ‘<img src=”‘ . $a . ‘” width=”100″ />’; }…

  • 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 loop (0,1,2,3..etc) echo $wp_query->current_post; endwhile; 或者还有种原始的方法: $key = “”; while…

  • 以前写的一段正则抓取安居客经纪人信息的表达式,但是不确定现在还有么有用了! $url=”http://shanghai.anjuke.com/brokerinfo.php?bid={$i}”; $content= file_get_contents($url); //preg_match_all (‘/(.*)[^

  • 下载: 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 = 0; while ($timeline_list->have_posts()) : $timeline_list->the_post(); $timeline_array[$index][“startDate”] = get_the_date(“Y,m,d”); $timeline_array[$index][“headline”] =…

  • /** * Add the field to the checkout * */ add_action(‘woocommerce_after_checkout_billing_form’, ‘my_custom_checkout_field’); function my_custom_checkout_field($checkout) { echo ” . __(‘Prefered delivery time’, ‘woothemes’) . ”; $tomorrow = date(‘Y-m-d’, strtotime(the_date(‘Y-m-d’, ”,”, FALSE) .’ +1 day’)); $after_tomorrow = date(‘Y-m-d’, strtotime(the_date(‘Y-m-d’, ”,”, FALSE) .’…

  • 这儿以 costom post portfolio 为例, 为 portfolio 列表页加上 两个分类列。删除时间列。 add_filter( ‘manage_edit-portfolio_columns’, ‘set_custom_edit_portfolio_columns’ ); add_action( ‘manage_portfolio_posts_custom_column’ , ‘custom_portfolio_column’, 10, 2 ); function set_custom_edit_portfolio_columns($columns) { unset($columns[‘date’]); //注销不需要的列 return $columns + array(‘portfolio_category’ => __(‘Categories’),’client_category’=>’Client Terms’); } function custom_portfolio_column( $column, $post_id ) { switch…

  • Example usage Example Purpose Produced HTML <?php icl_link_to_element(10); ?> Link to page 10 (support page) <a href=”/support/”>Support</a> <?php icl_link_to_element(10,’post’,__(‘Get help’)); ?> Link to support page with an alternative link text <a href=”/support/”>Get help</a> <?php icl_link_to_element(10,’post’,false, array(‘category’=>’products’,’priority’=>’high’); ?> Link to support…

  • 新旧界面对比,旧界面中的 aim,jabber,yim 被去掉了,加入了时下大家最熟悉的 facebook,twitter …… add_filter( ‘user_contactmethods’ , ‘update_contact_methods’ , 10 , 1 ); function update_contact_methods( $contactmethods ) { // Add new fields $contactmethods[‘phone’] = ‘Phone’; $contactmethods[‘mobile’] = ‘Mobile’; $contactmethods[‘address’] = ‘Address’; // Remove annoying and unwanted default fields unset($contactmethods[‘aim’]);…

  • 老是打不开这些页面,干脆复制到自己的地盘来了。方便自己也方便大家。 神马?WPML 是啥,自己百度吧! WPML offers functions that can be used in your WordPress theme to provide correct support for multilingual themes. Function Purpose Notes do_action(‘icl_language_selector’) Insert the drop down language selector. Described in the language setup section of the getting started guide.…

  • WordPress debug 代码,把它放在function 文件里,就会在每页的页脚出现这个,包括当前模板,重写规则,Query 等等。 add_action( ‘template_include’, ‘_childtheme_print_template_name’ ); function _childtheme_print_template_name( $template_name ) { global $childtheme_template_name; $childtheme_template_name = $template_name; add_action( ‘wp_footer’, ‘childtheme_print_template_name’, 100 ); return $template_name; } function childtheme_print_template_name( ) { global $childtheme_template_name, $wp_query, $wp_options; echo ” <div style=’padding-left:50px’> DEBUG…

  • http://hypercircle.com/customization-of-contact-form-7-plugin.html Additional headers:You can input any header lines into the field and you can insert any tags into any place in each header line, just like other Mail fields. Viz: CC, BCC etc like this: After the form is submitted…