Category: Wordpress

  • Add delivery date and time for woocommerce

    Add delivery date and time for woocommerce

    /** * 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) .’ +2 day’)); $_3day_now = date(‘Y-m-d’, strtotime(the_date(‘Y-m-d’,”,”, FALSE) .’ +3 day’)); echo ”; woocommerce_form_field(‘prefered_delivery_date’, array( ‘type’…

  • Add Custom Post Type Columns for wordpress

    Add Custom Post Type Columns for wordpress

    这儿以 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 ( $column ) { case ‘portfolio_category’: $terms = get_the_term_list( $post_id , ‘portfolio_category’ , ” ,…

  • icl_link_to_element and icl_object_id

    icl_link_to_element and icl_object_id

    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 page and add two arguments <a href=”/support/?category=products&amp;priority=high”>Support</a> <?php icl_link_to_element(10,’post’,false,’priority’=>’high’,’faq’); ?> <?php icl_link_to_element(3,’tag’); ?> Link to…

  • 修改WordPress里用户页的联系信息(Contact Info)

    修改WordPress里用户页的联系信息(Contact Info)

    新旧界面对比,旧界面中的 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’]); unset($contactmethods[‘jabber’]); unset($contactmethods[‘yim’]); return $contactmethods; }

  • WPML Coding API and Custom Language Switcher

    WPML Coding API and Custom Language Switcher

    老是打不开这些页面,干脆复制到自己的地盘来了。方便自己也方便大家。 神马?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. do_action(‘icl_navigation_menu’) Insert the top navigation menu. Described in the navitaionsection of the getting started guide. do_action(‘icl_navigation_breadcrumb’)…

  • WordPress debug code

    WordPress debug code

    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 INFO: Active Template: “.$childtheme_template_name.”\n”; childtheme_print_matched_rewrite_rule(); echo ‘posts_per_page (default option) = ‘.get_option( ‘posts_per_page’ ).”\n”; echo “\n\nWP_QUERY:…

  • Contact Form 7 的那些事儿

    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 the viewer is able to see the response messages such as “Your message was sent…

  • WordPress 获取附件图片时去除特色图片

    WordPress 获取附件图片时去除特色图片

    获取一篇文章中上传的所有图片,但是不包括 特色图片: ?>

  • WordPress Portfolio work with Isotope and Infinite Scroll

    WordPress Portfolio work with Isotope and Infinite Scroll

    准备:需要的jQuery插件 Isotope: 神奇的布局精致的jQuery插件。演示 Infinite Scroll:无限滚动被称为autopagerize的,unpaginate,无尽的网页。但实质上,它是预取从随后出现的页面上的内容,并直接将其添加到用户的当前页面。http://www.infinite-scroll.com/ 演示 新建文章类型 portfolio 和 Portfolio 分类  function my_post_types() { register_post_type(‘portfolio’, array( ‘label’ => __(‘Portfolio’,’itc’), ‘singular_label’ => __(‘Portfolio’, ‘itc’), ‘_builtin’ => false, //’exclude_from_search’ => false, // Exclude from Search Results ‘capability_type’ => ‘post’, ‘public’ => true, ‘show_ui’ => true, ‘show_in_nav_menus’ => FALSE, ‘menu_position’ => 100, ‘rewrite’ => array( ‘slug’ => ‘portfolio-show’, ‘with_front’ => FALSE,…

  • Get Featured Image with timthumb

    Get Featured Image with timthumb

    $w = ‘350’; $h = ‘200’; if (has_post_thumbnail()) { $large_image_url = wp_get_attachment_image_src(get_post_thumbnail_id(), ‘full’); echo ”; } else { echo ”; }

  • Create wordpress custom widget

    Create wordpress custom widget

    代码放到 functions.php 就可以在小工具里获得该 widget。 class weibo_widget extends WP_Widget { public function __construct() { // widget actual processes //get_popular_resource parent::__construct( ‘weibo_widget’, // Base ID ‘Weibo widget’, // Name array(‘description’ => __(‘Weibo Widget’, ‘affc’),) // Args ); } public function form($instance) { // outputs the options form on admin if (isset($instance[‘weibo_uid’])) { $weibo_uid = $instance[‘weibo_uid’]; } else…

  • Media, Audio, Video Player for wordpress

    Media, Audio, Video Player for wordpress

    function yyy_html5_audio($url) { if (preg_match(‘/Firefox/’, $_SERVER[“HTTP_USER_AGENT”])) { // For religious reasons Firefox does not support MP3 format in HTML5 audio tag, use Flash player instead $embed = ”; } else if (preg_match(‘/Opera/’, $_SERVER[“HTTP_USER_AGENT”])) { // Opera also does not support MP3 format in HTML5 audio tag, use Flash player instead $embed = ”; } else…

  • 修复 next_posts_link & previous_posts_link 与 qTranslate 的兼容问题

    修复 next_posts_link & previous_posts_link 与 qTranslate 的兼容问题

    If your having problems with qTranslate and the next_posts_link / previous_posts_link & next_post_link / previous_post_link template tags then I recommend dropping the following two functions into your theme’s functions.php file. /*************************************************************** * Function qtranslate_next_previous_fix * Ensure that the URL for next_posts_link & previous_posts_link work with qTranslate ***************************************************************/ add_filter(‘get_pagenum_link’, ‘qtranslate_next_previous_fix’); function qtranslate_next_previous_fix($url) { return qtrans_convertURL($url); }…

  • Custom taxonomy 不显示在 “外观”-> “菜单”里

    Custom taxonomy 不显示在 “外观”-> “菜单”里

    I have a custom taxonomy registered for custom post type. It has ‘public’, and ‘show_in_nav_menus’ arguments set to true, but it still doesn’t appear in nav-menus.php. If I set those arguments to custom post type, it works all right… what could be the problem? 我为新文章类型(custom post type)注册了一个新的分类(register_taxonomy),’show_in_nav_menus’ 都设置为 ‘true’,但是在 “外观”-> “菜单” (nav-menus.php)里没有显示出来。可是新文章类型(custom post type)显示了,这是为什么? 好吧,看下图你或许就明白了!…

  • 让Qtranslate 支持 Custom Taxonomy

    让Qtranslate 支持 Custom Taxonomy

    If you wanted to automatically detect taxonomies, and then add translation edit fields here is some code: 如果你想要自动探测 Custom Taxonomy,然后给他们加上翻译字段, 把这段代码放在主题的 function.php 里。 function qtranslate_edit_taxonomies(){ $args=array( ‘public’ => true , ‘_builtin’ => false ); $output = ‘object’; // or objects $operator = ‘and’; // ‘and’ or ‘or’ $taxonomies = get_taxonomies($args,$output,$operator); if ($taxonomies) { foreach ($taxonomies as…

  • 去除 wordpress 链接中的域名

    去除 wordpress 链接中的域名

    上次说到去除一些不必需的 class 和 ID, 从上图看出,这些 domain name 似乎也是不必须的,如果像下图: 这样会不会更好呢,下面的代码可以实现这个效果。 add_filter(‘walker_nav_menu_start_el’ , ‘yao_walker_nav_menu_start_el’ , 10 , 2); function yao_walker_nav_menu_start_el($item_output, $item){ //print_r($item); $home_url = home_url(); $site_url = site_url(); preg_match(“/^(http:\/\/)?([^\/]+)/i”,site_url(), $matches); $domain = $matches[0]; if( $domain == $home_url){ $replace = ”; }else{ $replace = str_replace($matches[0], ”, site_url()); } $item->url = str_replace($home_url,$replace,$item->url); $attributes = ! empty( $item->attr_title ) ?…

  • 清理wordpress菜单里的 id 和 class

    清理wordpress菜单里的 id 和 class

    wordpress 默认的菜单会产生很多 id 和 class 在代码里,打多时候,这些都是不需要的。 通过下面2个滤镜,可以去除那些我们不需要的 class 和 ID add_filter(‘nav_menu_css_class’ , ‘special_nav_class’ , 10 , 2); function special_nav_class($classes, $item){ $current_and_home = array(“current-menu-item”, “menu-item-home”, ‘last’); $classes = array_intersect($item->classes,$current_and_home); //保留有需要的 class return $classes; } add_filter(‘nav_menu_item_id’ , ‘special_nav_item_id’ , 10 , 2); function special_nav_item_id($item_id, $item){ $item_id = “”; //去除 id return $item_id; } 清理之后如: 不过尚有 class=”” 无法除去,主要是在核心代码里,class=””是在附加过滤后面加上得,所以暂时还不可以通过更改滤镜的方法去除,但是…

  • WordPress 只显示当前用户的文章

    WordPress 只显示当前用户的文章

    当Wordpress在一个多用户的贡献者列表管理页面后,他可以看到不仅是他的文章,但也从其他捐助者的文章。即使他不能编辑其他职位,这仍可能是一个问题,如果有很多文章已经和他有搜索一页一页地找到他的文章。如何只显示他自己的文章?这段代码会显示如何做到这一点。 function mypo_parse_query_useronly( $wp_query ) { if ( strpos( $_SERVER[ ‘REQUEST_URI’ ], ‘/wp-admin/edit.php’ ) !== false ) { if ( !current_user_can( ‘level_10’ ) ) { global $current_user; $wp_query->set( ‘author’, $current_user->id ); } } } add_filter(‘parse_query’, ‘mypo_parse_query_useronly’ ); 放在主题的 functions.php 里。

  • 怎么让WordPress自定义菜单在新窗口打开

    怎么让WordPress自定义菜单在新窗口打开

    首先到 blog/wp-admin/nav-menus.php 页面。勾选上 链接目标。 然后在下面的自定义菜单区域,点开单个菜单单元 搞定。 Happy? Rel 属性设置以此类推。