Shorcode

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras eget eros eget est pharetra elementum. Etiam et est varius, iaculis ipsum at, elementum lorem. Donec hendrerit, orci non gravida fermentum, nibh risus vestibulum dui, in gravida leo elit id mi. Ut tincidunt neque nec suscipit consectetur. Pellentesque semper, ipsum non convallis venenatis, ipsum lacus cursus orci, ac ultricies erat massa ut massa. Aenean lacinia pretium interdum. Sed vel ultricies lacus. Vestibulum ac vulputate erat, vel tempor libero. Duis aliquet accumsan mauris, et semper nisi posuere vel. Mauris ac rhoncus felis, at tempus tortor. Etiam consequat vestibulum felis, id tincidunt libero condimentum faucibus. Aenean sit amet volutpat tortor. Donec ipsum felis, hendrerit vitae dui at, ultricies ultricies felis. Nam tempor, felis a blandit porttitor, felis ipsum mattis neque, vel blandit orci odio et arcu.

Sed et urna lacinia, lobortis tellus nec, venenatis ipsum. Nam iaculis accumsan neque in bibendum. Interdum et malesuada fames ac ante ipsum primis in faucibus. Phasellus eget interdum magna. Nullam interdum cursus rhoncus. Aenean volutpat a justo sit amet posuere. Praesent est odio, faucibus id lacus quis, consectetur ornare dolor. Vestibulum orci urna, pellentesque sit amet egestas eget, blandit rutrum risus.

WP怎样修改maximum upload file size等参数

有三种方法可以修改。

通过.htaccess文件:

php_value upload_max_filesize 128M
php_value post_max_size 128M
php_value memory_limit 256M
//php_value max_excecution_time 300
//php_value max_input_time 300

通过wp-config.php文件:


@ini_set('upload_max_filesize','128M');
@ini_set('post_max_size','128M');
@ini_set('memory_limit','256M');
@ini_set('max_execution_time','300');
@ini_set('max_input_time','300');

通过插件:

https://import.wp-migration.com

WP超强免费后台框架kirki详细解说

WordPress后台框架有很多,如codestar之类的。虽然说本身theme option和metabox 也不是很难,但是用框架的话开发会迅速很多。

我们一个博客主题的自带后台框架开发功能非常全面,下次我们会进行详细解释,本次我们来介绍wordpress一个功能全面的customize api框架,也叫toolkit。官网是https://kirki.org/

kirki简化了wp的customizer api, 并自带30多个控制器。

要使用kirki,首先去官网上下载。目前kirki没有收费版,点击免费版,随便填写注册信息即可。

集成主题方式

Kirki有二种方式可以集成到你的主题当中。一种是作为插件,一种是与主题并入。

如果你用tgmpa或者merlinwp来创建引导页的话,你可以把kirki的插件安装到推荐必须的插件里面去。如果你没用上面的脚本的话,你可以把这段脚本添加到你的网站中来来要求主题强制安装kirki.

脚本用法:从这段脚本复制出来然后创建inc/class-kirki-installer-section.php,然后在functions.php里面加上这段:

include_once get_theme_file_path( 'inc/class-kirki-installer-section.php' );

如何并入到你的主题当中

把kirki文件夹安装到你的主题文件夹当中,然后在functions.php里面引入kirki文件夹下面的插件主要文件kirki.php就可以了。这种方式的话缺少了灵活性。

接下来我们要进行kirki的配置。

当你创建了一个项目之后,你第一件事情要做的就是创建一个配置文件。配置文件允许每一个项目可以使用不一样的设置就像标识符一样。属于配置的字段将继承配置属性。

Kirki::add_config( $config_id, $args );

例子:

Kirki::add_config( 'theme_config_id', array(
	'capability'    => 'edit_theme_options',
	'option_type'   => 'theme_mod',
) );

字段解释:

Arguments

  • capability: any valid WordPress capability. See the WordPress Codex for details.
  • option_type: can be either option or theme_mod. We recommend using theme_mod. If however you choose to use option you need to understand how your data will be saved, and in most cases you will also have to use the option_name argument as well.
  • option_name: If you’re using options instead of theme mods then you can use this to specify an option name. All your fields will then be saved as an array under that option in the WordPress database.
  • disable_output: Set to true if you don’t want Kirki to automatically output any CSS for your config (defaults to false).

创建属于这个配置的字段的方式:

Kirki::add_field( 'theme_config_id', $field_args );

创建panel和section的方式

panel是section的容器,可以群组section,点击这里查看customizer api的介绍。

用kirki创建panel的方式:

Kirki::add_panel( 'panel_id', array(
    'priority'    => 10,
    'title'       => esc_html__( 'My Panel', 'kirki' ),
    'description' => esc_html__( 'My panel description', 'kirki' ),
) );

Kirki::add_panel()method函数跟customizer api的add panel一样的时态。

Section是controls的wrapper,用来群组各类controls. 所有的字段一定要属于这个section.

Kirki::add_section( 'section_id', array(
    'title'          => esc_html__( 'My Section', 'kirki' ),
    'description'    => esc_html__( 'My section description.', 'kirki' ),
    'panel'          => 'panel_id',
    'priority'       => 160,
) );

Kirki::add_section()method函数跟customizer api里面是一样的时态。

Controls

kirki目前提供了30多个controls可以进行创建,是以add field形式。详细点击这里。https://kirki.org/docs/controls/

Kirki创建实例

1、将kirki文件夹复制到你自定义主题的文件夹下,然后在functions.php里面引入 kirki/kirki.php。

2、然后在inc文件夹下创建属于自定义class的文件,例如theme-customizer.php。 添加以下代码:并在functions.php里面引入


// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
  exit;
}

/**
 * This is a wrapper class for Kirki.
 * If the Kirki plugin is installed, then all CSS & Google fonts
 * will be handled by the plugin.
 * In case the plugin is not installed, this acts as a fallback
 * ensuring that all CSS & fonts still work.
 * It does not handle the customizer options, simply the frontend CSS.
 */
class Abt_Option {

  /**
   * @static
   * @access protected
   * @var array
   */
  protected static $config = array();

  /**
   * @static
   * @access protected
   * @var array
   */
  protected static $fields = array();

  /**
   * The class constructor
   */
  public function __construct() {
    // If Kirki exists then there's no reason to procedd
    if ( class_exists( 'Kirki' ) ) {
      return;
    }
  }

  /**
   * Create a new panel
   *
   * @param   string      the ID for this panel
   * @param   array       the panel arguments
   */
  public static function add_panel( $id = '', $args = array() ) {


    if ( class_exists( 'Kirki' ) ) {
      Kirki::add_panel( $id, $args );
    }
    // If Kirki does not exist then there's no reason to add any panels.
  }

  /**
   * Create a new section
   *
   * @param   string      the ID for this section
   * @param   array       the section arguments
   */
  public static function add_section( $id, $args ) {

    if ( class_exists( 'Kirki' ) ) {
      Kirki::add_section( $id, $args );
    }
    // If Kirki does not exist then there's no reason to add any sections.
  }


  /**
   * Sets the configuration options.
   *
   * @param    string    $config_id    The configuration ID
   * @param    array     $args         The configuration arguments
   */
  public static function add_config( $config_id, $args = array() ) {
    if ( class_exists( 'Kirki' ) ) {
      Kirki::add_config( $config_id, $args );
      return;
    }
  }

  /**
   * Create a new field
   *
   * @param    string    $config_id    The configuration ID
   * @param    array     $args         The field's arguments
   */
  public static function add_field( $config_id, $args ) {
    if($config_id == '') $config_id = $args['settings'];
    
    // if Kirki exists, use it.
    if ( class_exists( 'Kirki' ) ) {
      Kirki::add_field( $config_id, $args );
      return;
    }
  }
}
new Abt_Option();

3、然后创建customizer文件夹,名字可以自定义,存放每个部位的自定义文件。如header、style、fonts、css等。

4、然后创建options-panel.php文件,导入你创建的各个部分的自定义样式php文件,最后在functions.php里面导入options-panel.php文件。

section和control创建实例:

Abt_Option::add_panel( 'other_options_extra', array(
  'title'       => __( 'Other Options', 'Abt' ),
  'description' => __( 'Abt Other Options.', 'Abt' ),
  'priority' => '9',
) );

Abt_Option::add_section( 'social_options_all', array(
  'title'       => __( 'Social Options', 'Abt' ),
  'panel'       => 'other_options_extra',

) );

Abt_Option::add_section( 'disable_extra_features', array(
  'title'       => __( 'Advanced Features', 'Abt' ),
  'panel'       => 'other_options_extra',

) );

Abt_Option::add_section( 'sticky_notification_bar', array(
  'title'       => __( 'Sticky Notification Bar', 'Abt' ),
  'panel'       => 'other_options_extra',

) );



Abt_Option::add_field( 'mayo_config',  array(
  'type'     => 'link',
  'settings' => 'facebook_url',
  'label'    => __( 'Facebook URL', 'Abt' ),
  'section'  => 'social_options_all',
  'default'  => 'https://facebook.com/',
));

5、如果要去除掉原先存在的theme_mod,将下面的代码粘贴到functions.php就可以:

function mayosis_customize_register( $wp_customize ) {
    //All our sections, settings, and controls will be added here

    $wp_customize->remove_section( 'title_tagline');
    $wp_customize->remove_section( 'colors');
    $wp_customize->remove_section( 'header_image');
    $wp_customize->remove_section( 'background_image');
    $wp_customize->remove_section( 'static_front_page');


}
add_action( 'customize_register', 'mayosis_customize_register',50 );


/**
 * Removes the core 'Menus' panel from the Customizer.
 *
 * @param array $components Core Customizer components list.
 * @return array (Maybe) modified components list.
 */
function mayosis_remove_nav_menus_panel( $components ) {
    $i = array_search( 'nav_menus', $components );
    if ( false !== $i ) {
        unset( $components[ $i ] );
    }
    return $components;
}
add_filter( 'customize_loaded_components', 'mayosis_remove_nav_menus_panel' );

WordPress免费插件实现付费阅读功能

WP付费阅读的功能无需付费购买国内的各种插件,其实利用woocommerce就可以实现。

首先我们下载woocommerce插件,并配置好货币以及付款方式,需要支付宝支付的需要单独安装woocommerce的支付宝网关插件。

然后我们在插件市场搜索pay per post插件,这个是woocommerce基础上的衍生插件,可以实现post和page以及任何custom post type的付费阅读。

点击左侧菜单栏上的pay per post 管理面板,可以在setting那里添加需要付费阅读时候的提示语以及短代码。

然后,去woocomerce的product类型当中新增产品,设置为虚拟产品,添加标题,和任何你想要的内容,添加价格,保存。

然后新增post,在post下面的字段里,选择product为你新增的那个虚拟物品即可。接下来是和woo一样的操作。

PHP应知必会的提示和技巧系列

Whenever it comes to web development, many developers want tips to improve the website. Web development in PHP is pretty easy for newbies. All you need is PHP tutorials for beginners and the easiest way to optimize PHP website.

PHP is one of the most loved and widely used languages that developers loves to build their website from. The best part of PHP development is that developers can find Guide for PHP developers and best PHP tips and tricks on the official site of PHP. Another advantage of PHP is that as a PHP developer you can find good frameworks and CMSs to work on. Many people tend to ask, ‘how can I improve my PHP code?’ The answer to this lies in practice and being capable of build your own confidence in creating a project and releasing it. You can also learn PHP by building web applications

This blog post is all about the best PHP tips and tricks for Web development in PHP so that you can develop your website in PHP without any hassle and you can enjoy your professional life.

Develop with error reporting enabled

Error reporting feature, an important feature in PHP website, is one of the best Useful PHP trick for Developers. The best thing to cope with errors is to set the system to display errors. To set the settings you have to alter the php.ini file when you develop your site. Include these two lines in the beginning.

error_reporting ( E_ALL ) ;
ini_set ( 'display_errors' , 1 ) ;

The following code helps you to see both types of errors whether the fatal errors that produce the dreaded white screen as warnings and notices that may be bugs to fix.

Prevents SQL injection

Security holes are the biggest cause of the bad reputation of PHP but PHP tips for website development are here.

There are many ways to avoid SQL injection but the simplest one escapes any variable that we will use in the database. The code should look like this:

$query_result = mysql_query ( "SELECT * FROM WHERE Ex_table ex_field = \" " . mysql_real_escape_string( $ ex_field ) . " \ " " ) ;

Use the _once() function with caution

PHP developers prefer using include() or function require() to call other files, libraries or classes, but using the  include_eleven() and require_eleven(), are the  PHP tricks for web developer.  Both the functions have the same functionality but the advantage is that it prevents the files, classes or loaded libraries to be loaded again which causes duplication and undesired states in the code.

Learn to handle ternary operators

The best PHP tips and trick for good performance is to use ternary operators as an alternative to simple IF constructions. For instance:

$age = ( !empty ( $ _ GET [ 'age ] ) ? $ _ GET [ 'age' ] : 58 ) ;

This would help your code to get lighter and can be nested without problems.

Retire the MySQL driver

This is 2017 and the technology that we are using is advanced now this is the time for PHP7. A high time to retire your MySQL database and start using PDO. A PHP extension that helps you to connect with different other managers databases.

A very important feature of MySQL driver is MySQL Connector/Python that supports almost all features provided by MySQL version 5.7. Designed specifically to MySQL, MySQL Connector/Python lets you translate the parameter’s value between Python and MySQL data types. Obviously, PHP works other than MySQL too. As a PHP web developer, this tip is one of the best PHP tips and tricks for me for website development with PHP. The code to connect with databases is:

try {
$conn = new PDO ( "mysql: host = localhost; dbname = database ' , $ user , $ pass ) ;
$conn -> setAttribute ( PDO :: ATTR_ERRMODE , PDO :: ERRMODE_EXCEPTION ) ;
} Catch ( PDOException $e ) {
Echo "ERROR:" . $e -> getMessage ( ) ;
}

Use single quotes rather than double

Are you a speedy programmer who can type code fastly?

Well here’s a trick for you! Just use single quote (“) other than double (” “). Trust me! it saves you a lot of time and the performance of your server. Best PHP tips and tricks code! ha?

Clean URLs quickly with .htaccess

The file .htaccess – the best yet simple way to make the URLs more simpler for human eye as well as for SEO. A hidden file that serves a lot with Apache directives. The services that this file provides are performing redirection and clean URLs do not cease to be redirected to after all. One of the best tip and trick for PHP based application improvements.

RewriteEngine On
RewriteRule ^ ( [ a - zA - Z0 - 9 ] + ) $ index . Php? Page = $ 1

This code is the life saver for many PHP developers that can prevent horrible URLs and make it sleek and simple, phew!

Know all the Problems of isset()

One of the PHP tricks for web developer is to understand what isset() function do. Make sure that you know at what time isset() function returns false and on which time it answers true. This function returns True if the variable is not NULL. Yes you read it not NULL.

Just like so, if NULL can be a valid value of the variable,We surely have a problem sire!

$foo = null ;
if ( isset( $ foo ) ) // returns false
And the solution is: Use  get_defined_vars( );
$foo = NULL ;
$vars = get_defined_vars( );
if ( array_key_exists ( 'foo' , $ vars ) ) // returns True

Use a switch instead of stringing If Statements

The useful PHP trick for Developers- use Switch instead of crazy Ifs. Advantage? The code will execute faster thus performance is increased. The usage of Switch statements allows you to go beyond the use of if-else if-else chains.

switch ($color ) {
case 'white' :
echo "The color is White" ;
break ;
case 'blue' :
echo "The color is Blue" ;
break ;
case 'green' :
echo "The color is Green" ;
break ;
case 'black' :
echo "Color is black" ;
break ;
}

Take up cURL

The method to retrieve a file from another server is to use the powerful way cURL, instead of using file_get_contents() function which is easy to use but come on, it’s like having death on your computer. The following code is the example of the use cURL:

$c = curl_init ( ) ;
curl_setopt ( $c , CURLOPT_URL , $URL ) ;
curl_setopt ( $c , CURLOPT_TIMEOUT , 15 ) ;
curl_setopt ( $c , CURLOPT_RETURNTRANSFER , true ) ;
$content = curl_exec ( $c ) ;
$status = curl_getinfo ( $c , CURLINFO_HTTP_CODE ) ;
curl_close ( $c ) ;

Password Encryption

Often developers ask Tips to improve the website, well here is one, PHP is always on your side and it encrypts your passwords for you. I am talking about the PHP 5.5+ versions, Just store the passwords in your database as.

$enc_pass = password_hash ( $submitted_pass , PASSWORD_DEFAULT ) ;

To check if password is correct or not:

if ( password_verify ( $submitted_pass , $stored_pass ) )
{ 
// User successfully authenticated
}

Advanced PHP Tips to Improve Your Programming

Typically used for web development, PHP is the server-side scripting language. Invented in 1994 by Rasmus Lerdorf, PHP has done a remarkable job in the technology-based world and made the whole work of web development extremely easy for developers.

There’s little doubt that working knowledge of PHP is too important to sustain in today’s cut-throat technology sphere. Here are the 5 advanced PHP tips to learn PHP programming.

I. Object-Oriented Programming (OOP) is the Rudimentary Requirement

OOP is the basic requirement of PHP that every developer should know. PHP follows object-oriented programming and therefore items and programs link things together for developing a program. Using OOP approaches, you can skip the replication of code and can complete the code in a much simpler way. Objects are demarcated under the programs and then you can reclaim this purpose again and again in the whole programming. OOP is faster, easy to correct, and uses slighter server resources, less code and quicker loading process to evade long events. Going with OOP, you can make your coding style more effective and simpler.

II. Intrinsic Functions of PHP are Extremely Usable

PHP language is extremely easy to learn and adjustable for a developer to develop the best websites. Using the inbuilt advanced PHP techniques, you will get the concealed benefits which are very valuable throughout the coding process. If you are doing a custom PHP development or web development, the need for displays and functions is very significant. For example, if you want to count the numbers then you can use count() and like that PHP has a number of built-in functions that are very beneficial for making the coding procedure easy and quick.

III. Keep the Database Secure

The first thing prior to starting any PHP project is that you should use mysl_real_escape_string() for all the database. Doing this will help you keep all the strings safe from any kind of unwelcome threats that may have some malicious code. This should be your first step to protect your database. The other vital thing is that never use $_REQUEST – instead, go with POST or GET strings for submitting the data into the database query.

IV. Always Use POST and Never GET

A good programmer is well aware of the difference between these two. Get method displays the address in the URL and gives simpler ways for the hacker to totally hack your entire project. Going with POST, you can face a secure journey throughout your coding and development procedure.

V. Make a Copy Before Going for CODE

Before you explore the real platform, just stop for a few minutes and make a coarse draught of your whole coding. This will give you better comprehension and will clear your opinions for developing the website. Also, you will discover the main glitches that you will face in the future journey of the coding.

Wrapping things Up

One of the best programming language to develop websites is PHP, which is open-source. Although it is easy to use it’s normal when it takes the time to learn but if you know all the advanced PHP tips and tricks for good performance and for Website development in PHP then you are a champ!

Whatever it takes you to use PHP based frameworks and CMSs consider, use it over Core PHP, as it can give a better performance, a lightweight website and yes you can develop your website in PHP more faster.

30个必须记住的css选择器

CSS Selectors

So you learned the base idclass, and descendant selectors—and then called it a day? If so, you’re missing out on an enormous level of flexibility. You owe it to yourself to commit these advanced CSS and CSS3 selectors to memory.

Basic Selectors

1. *

* {
 margin: 0;
 padding: 0;
}

Let’s knock the obvious ones out, for the beginners, before we move on to the more advanced selectors.

The star symbol will target every single element on the page. Many developers will use this trick to zero out the margins and padding. While this is certainly fine for quick tests, I’d advise you never to use this in production code. It adds too much weight on the browser, and is unnecessary.

The * can also be used with child selectors.

#container * {
 border: 1px solid black;
}

This will target every single element that is a child of the #container div. Again, try not to use this technique very much, if ever.

2. #X

#container {
   width: 960px;
   margin: auto;
}

Prefixing the hash symbol to a selector allows us to target by id. This is easily the most common usage; however, be cautious when using id selectors.

Ask yourself: do I absolutely need to apply an id to this element in order to target it?

id selectors are rigid and don’t allow for reuse. If possible, first try to use a tag name, one of the new HTML5 elements, or even a pseudo-class.

3. .X

.error {
  color: red;
}

This is a class selector. The difference between ids and classes is that, with the latter, you can target multiple elements. Use classes when you want your styling to apply to a group of elements. Alternatively, use ids to find a needle in a haystack, and style only that specific element.

4. X

a { color: red; }
ul { margin-left: 0; }

What if you want to target all elements on a page, according to their type, rather than an id or classname? Keep it simple, and use a type selector. If you need to target all unordered lists, use ul {}.

Combinator Selectors

5. X Y

li a {
  text-decoration: none;
}

The next most common selector is the descendant selector. When you need to be more specific with your selectors, you use these. For example, what if, rather than targeting all anchor tags, you only need to target the anchors which are within an unordered list? This is specifically when you’d use a descendant selector.

Pro-tip: If your selector looks like X Y Z A B.error, you’re doing it wrong. Always ask yourself if it’s absolutely necessary to apply all of that weight.

6. X + Y

ul + p {
   color: red;
}

This is referred to as an adjacent selector. It will select only the element that is immediately preceded by the former element. In this case, only the first paragraph after each ul will have red text.

7. X > Y

div#container > ul {
  border: 1px solid black;
}

The difference between the standard X Y and X > Y is that the latter will only select direct children. For example, consider the following markup.

   <div id="container">
      <ul>
         <li> List Item
           <ul>
              <li> Child </li>
           </ul>
         </li>
         <li> List Item </li>
         <li> List Item </li>
         <li> List Item </li>
      </ul>
   </div>

A selector of #container > ul will only target the uls which are direct children of the div with an id of container. It will not target, for instance, the ul that is a child of the first li.

For this reason, there are performance benefits in using the child combinator. In fact, it’s recommended particularly when working with JavaScript-based CSS selector engines.

8. X ~ Y

ul ~ p {
   color: red;
}

This sibling combinator is similar to X + Y, but it’s less strict. While an adjacent selector (ul + p) will only select the first element that is immediately preceded by the former selector, this one is more generalized. It will select, referring to our example above, any p elements, as long as they follow a ul.

Attribute Selectors

9. X[title]

a[title] {
   color: green;
}

Referred to as an attributes selector, in our example above, this will only select the anchor tags that have a title attribute. Anchor tags which do not will not receive this particular styling. But what if you need to be more specific? Check out the next example!

10. X[href="foo"]

a[href="https://code.tutsplus.com"] {
  color: #83b348; /* Envato green */
}

The snippet above will style all anchor tags which link to https://code.tutsplus.com; they’ll receive our branded green color. All other anchor tags will remain unaffected.

Note that we’re wrapping the value in quotes. Remember to also do this when using a JavaScript CSS selector engine. When possible, always use CSS3 selectors over unofficial methods.

This works well, although it’s a bit rigid. What if the link does indeed direct to Envato Tuts+, but maybe the path is code.tutsplus.com rather than the full URL? In those cases, we can use a bit of the regular expressions syntax.

11. X[href*="foo"]

a[href*="tutsplus"] {
  color: #83b348; /* Envato green */
}

There we go; that’s what we need. The star designates that the proceeding value must appear somewhere in the attribute’s value. That way, this covers tutsplus.comcode.tutsplus.com, and even webdesign.tutsplus.com.

Keep in mind that this is a broad statement. What if the anchor tag linked to some non-Envato site with the string tutsplus in the URL? When you need to be more specific, use ^ and $, to reference the beginning and end of a string, respectively.

12. X[href^="http"]

a[href^="http"] {
   background: url(path/to/external/icon.png) no-repeat;
   padding-left: 10px;
}

Ever wonder how some websites are able to display a little icon next to the links which are external? I’m sure you’ve seen these before; they’re nice reminders that the link will direct you to an entirely different website.

This is a cinch with the carat symbol. It’s most commonly used in regular expressions to designate the beginning of a string. If we want to target all anchor tags that have an href which begins with http, we could use a selector similar to the snippet shown above.

Notice that we’re not searching for https://; that’s unnecessary, and doesn’t account for the URLs that begin with https://.

Now, what if we wanted to instead style all anchors which link to, say, a photo? In those cases, let’s search for the end of the string.

13. X[href$=".jpg"]

a[href$=".jpg"] {
   color: red;
}

Again, we use a regular expressions symbol, $, to refer to the end of a string. In this case, we’re searching for all anchors which link to an image—or at least a URL that ends with .jpg. Keep in mind that this won’t capture GIF and PNG images.

14. X[data-*="foo"]

a[data-filetype="image"] {
   color: red;
}

How do we compensate for all of the various image types? Well, we could create multiple selectors, such as:

a[href$=".jpg"],
a[href$=".jpeg"],
a[href$=".png"],
a[href$=".gif"] {
   color: red;
}

But that’s a pain, and it’s inefficient. Another possible solution is to use custom attributes. What if we added our own data-filetype attribute to each anchor that links to an image?

<a href="path/to/image.jpg" data-filetype="image"> Image Link </a>

Then, with that hook in place, we can use a standard attributes selector to target only those anchors.

a[data-filetype="image"] {
   color: red;
}

15. X[foo~="bar"]

 a[data-info~="external"] {
   color: red;
}

a[data-info~="image"] {
   border: 1px solid black;
}

Here’s a special one that’ll impress your friends. Not too many people know about this trick. The tilde (~) symbol allows us to target an attribute which has a space-separated list of values.

Going along with our custom attribute from number 15, above, we could create a data-info attribute, which can receive a space-separated list of anything we need to make note of. In this case, we’ll make note of external links and links to images—just for the example.

"<a href="path/to/image.jpg" data-info="external image"> Click Me, Fool </a>

With that markup in place, now we can target any tags that have either of those values, by using the ~ attributes selector trick.

/* Target data-info attr that contains the value "external" */
a[data-info~="external"] {
   color: red;
}

/* And which contain the value "image" */
a[data-info~="image"] {
  border: 1px solid black;
}

Pretty nifty, huh?

Pseudo Selectors

16. X:visited and X:link

a:link { color: red; }
a:visited { color: purple; }

We use the :link pseudo-class to target all anchor tags which have yet to be clicked on.

Alternatively, we also have the :visited pseudo class, which, as you’d expect, allows us to apply specific styling to only the anchor tags on the page which have been clicked on, or “visited”.

17. X:checked

input[type=radio]:checked {
   border: 1px solid black;
}

This pseudo class will only target a user interface element that has been checked—like a radio button or checkbox. It’s as simple as that.

18. X:after

The before and after pseudo classes are great. Every day, it seems, people are finding new and creative ways to use them effectively. They simply generate content around the selected element.

Many were first introduced to these classes when they encountered the clear-fix hack.

.clearfix:after {
    content: "";
    display: block;
    clear: both;
    visibility: hidden;
    font-size: 0;
    height: 0;
    }

.clearfix { 
   *display: inline-block; 
   _height: 1%;
}

This hack uses the :after pseudo class to append a space after the element, and then clear it. It’s an excellent trick to have in your tool bag, particularly in the cases when the overflow: hidden; method isn’t possible.

For another creative use of this, refer to my quick tip on creating shadows.

According to the CSS3 Selectors specification, you should technically use the pseudo element syntax of two colons ::. However, to remain compatible, the user-agent will accept a single colon usage as well. 

19. X:hover

div:hover {
  background: #e3e3e3;
}

Oh come on. You know this one. The official term for this is “user action pseudo class”. It sounds confusing, but it really isn’t. Want to apply specific styling when a user hovers over an element? This will get the job done!

Keep in mind that older versions of Internet Explorer don’t respond when the :hover pseudo class is applied to anything other than an anchor tag.

You’ll most often use this selector when applying, for example, a border-bottom to anchor tags, when hovered over.

a:hover {
 border-bottom: 1px solid black;
}

Pro-tipborder-bottom: 1px solid black; looks better than text-decoration: underline;.

20. X:not(selector)

div:not(#container) {
   color: blue;
}

The negation pseudo class is particularly helpful. Let’s say I want to select all divs, except for the one which has an id of container. The snippet above will handle that task perfectly.

Or, if I wanted to select every single element (not advised) except for paragraph tags, we could do:

*:not(p) {
  color: green;
}

21. X::pseudoElement

p::first-line {
   font-weight: bold;
   font-size: 1.2em;
}

We can use pseudo elements (designated by ::) to style fragments of an element, such as the first line or the first letter. Keep in mind that these must be applied to block-level elements in order to take effect.

A pseudo-element is composed of two colons: ::

Target the First Letter of a Paragraph

p::first-letter {
   float: left;
   font-size: 2em;
   font-weight: bold;
   font-family: cursive;
   padding-right: 2px;
}

This snippet is an abstraction that will find all paragraphs on the page, and then sub-target only the first letter of that element.

This is most often used to create newspaper-like styling for the first letter of an article.

Target the First Line of a Paragraph

p::first-line {
   font-weight: bold;
   font-size: 1.2em;
}

Similarly, the ::first-line pseudo element will, as expected, style the first line of the element only.

“For compatibility with existing style sheets, user agents must also accept the previous one-colon notation for pseudo-elements introduced in CSS levels 1 and 2 (namely, :first-line:first-letter:before and :after). This compatibility is not allowed for the new pseudo-elements introduced in this specification.”—W3C Selectors Specs

Nth Child and Type Selectors

22. X:nth-child(n)

li:nth-child(3) {
   color: red;
}

Remember the days when we had no way to target specific elements in a stack? The nth-child pseudo class solves that!

Please note that nth-child accepts an integer as a parameter, but this is not zero-based. If you wish to target the second list item, use li:nth-child(2).

We can even use this to select a variable set of children. For example, we could do li:nth-child(4n) to select every fourth list item.

23. X:nth-last-child(n)

li:nth-last-child(2) {
   color: red;
}

What if you had a huge list of items in a ul, and you only needed to access, say, the third to last item? Rather than doing li:nth-child(397), you could instead use the nth-last-child pseudo class.

This technique works almost identically to number 16 above. The difference is that it begins at the end of the collection, and works its way back.

24. X:nth-of-type(n)

ul:nth-of-type(3) {
   border: 1px solid black;
}

There will be times when, rather than selecting a child, you instead need to select according to the type of element.

Imagine markup that contains five unordered lists. If you wanted to style only the third ul, and didn’t have a unique id to hook into, you could use the nth-of-type(n) pseudo class. In the snippet above, only the third ul will have a border around it.

25. X:nth-last-of-type(n)

ul:nth-last-of-type(3) {
   border: 1px solid black;
}

And yes, to remain consistent, we can also use nth-last-of-type to begin at the end of the selectors list and work our way back to target the desired element.

26. X:first-child

ul li:first-child {
   border-top: none;
}

This structural pseudo class allows us to target only the first child of the element’s parent. You’ll often use this to remove borders from the first and last list items.

For example, let’s say you have a list of rows, and each one has a border-top and a border-bottom. Well, with that arrangement, the first and last item in that set will look a bit odd.

Many designers apply classes of first and last to compensate for this. Instead, you can use these pseudo classes.

27. X:last-child

ul > li:last-child {
   color: green;
}

The opposite of first-childlast-child will target the last item of the element’s parent.

last-child Selector Example

Let’s build a simple example to demonstrate one possible use of these classes. We’ll create a styled list item.

  <ul>
     <li> List Item </li>
     <li> List Item </li>
     <li> List Item </li>
  </ul>

For the markup, there’s nothing special: just a simple list.

Here’s the CSS:

ul {
 width: 200px;
 background: #292929;
 color: white;
 list-style: none;
 padding-left: 0;
}

li {
 padding: 10px;
 border-bottom: 1px solid black;
 border-top: 1px solid #3c3c3c;
}

This styling will set a background, remove the browser default padding on the ul, and apply borders to each li to provide a bit of depth.

Styled List

To add depth to your lists, apply a border-bottom to each li that is a shade or two darker than the li‘s background color. Next, apply a border-top which is a couple of shades lighter.

The only problem, as shown in the image above, is that a border will be applied to the very top and bottom of the unordered list—which looks odd. Let’s use the :first-child and :last-child pseudo classes to fix this.

li:first-child {
    border-top: none;
}

li:last-child {
   border-bottom: none;
}
Fixed

There we go; that fixes it!

28. X:only-child

div p:only-child {
   color: red;
}

Truthfully, you probably won’t find yourself using the only-child pseudo class too often. Nonetheless, it’s available, should you need it.

It allows you to target elements which are the only child of its parent. For example, referencing the snippet above, only the paragraph that is the only child of the div will be colored red.

Let’s assume the following markup.

<div><p> My paragraph here. </p></div>

<div>
   <p> Two paragraphs total. </p>
   <p> Two paragraphs total. </p>
</div>

In this case, the second div‘s paragraphs will not be targeted; only the first div. As soon as you apply more than one child to an element, the only-child pseudo class ceases to take effect.

29. X:only-of-type

li:only-of-type {
   font-weight: bold;
}

This structural pseudo class can be used in some clever ways. It will target elements that do not have any siblings within its parent container. As an example, let’s target all uls which have only a single list item.

First, ask yourself how you would accomplish this task. You could do ul li, but this would target all list items. The only solution is to use only-of-type.

ul > li:only-of-type {
   font-weight: bold;
}

30. X:first-of-type

The first-of-type pseudo class allows you to select the first siblings of its type.

Javascript的method方法详解

1. What is a method

Let’s define and call a regular function:

function greet(who) {
  return `Hello, ${who}!`;
}

greet('World'); // => 'Hello, World!'

The function keyword followed by its name, params, and body: function greet(who) {...} makes a regular function definition.

greet('World') is the regular function invocation. The function greet('World') accepts data from the argument.

What if who is a property of an object? To easily access the properties of an object you can attach the function to that object, in other words, create a method.

Let’s make greet() a method on the object world:

const world = {
  who: 'World',

  greet() {    return `Hello, ${this.who}!`;  }}

world.greet(); // => 'Hello, World!'

greet() { ... } is now a method that belongs to the world object. world.greet() is a method invocation.

Inside of the greet() method this points to the object the method belongs to — world. That’s why this.who expression accesses the property who.

Note that this is also named context.

The context is optional

While in the previous example I’ve used this to access the object the method belongs to — JavaScript, however, doesn’t impose a method to use this.

For this reason you can use an object as a namespace of methods:

const namespace = {
  greet(who) {
    return `Hello, ${who}!`;
  },

  farewell(who) {
    return `Good bye, ${who}!`;
  }
}

namespace.greet('World');    // => 'Hello, World!'
namespace.farewell('World'); // => 'Good bye, World!'

namespace is an object that holds 2 methods: namespace.greet() and namespace.farewell().

The methods do not use this, and namespace serves as a holder of alike methods.

2. Object literal method

As seen in the previous chapter, you can define a method directly in an object literal:

const world = {
  who: 'World',

  greet() {    return `Hello, ${this.who}!`;  }};

world.greet(); // => 'Hello, World!'

greet() { .... } is a method defined on an object literal. Such type of definition is named shorthand method definition (available starting ES2015).

There’s also a longer syntax of methods definition:

const world = {
  who: 'World',

  greet: function() {    return `Hello, ${this.who}!`;  }}

world.greet(); // => 'Hello, World!'

greet: function() { ... } is a method definition. Note the additional presence of a colon and function keyword.

Adding methods dynamically

The method is just a function that is stored as a property on the object. That’s why you can add methods dynamically to an object:

const world = {
  who: 'World',

  greet() {
    return `Hello, ${this.who}!`;
  }
};

// A a new property holding a function
world.farewell = function () {
  return `Good bye, ${this.who}!`;
}

world.farewell(); // => 'Good bye, World!'

world object at first doesn’t have a method farewell. It is added dynamically.

The dynamically added method can be invoked as a method without problems: world.farewell().

3. Class method

In JavaScript, the class syntax defines a class that’s going to serve as a template for its instances.

A class can also have methods:

class Greeter {
  constructor(who) {
    this.who = who;
  }

  greet() {    console.log(this === myGreeter); // logs true    return `Hello, ${this.who}!`;  }}

const myGreeter = new Greeter('World');
myGreeter.greet(); // => 'Hello, World!' 

greet() { ... } is a method defined inside a class.

Every time you create an instance of the class using new operator (e.g. myGreeter = new Greeter('World')), methods are available for invocation on the created instance.

myGreeter.greet() is how you invoke the method greet() on the instance. What’s important is that this inside of the method equals the instance itself: this equals myGreeter inside greet() { ... } method.

4. How to invoke a method

4.1 Method invocation

What’s particularly interesting about JavaScript is that defining a method on an object or class is half of the job. To maintain the method the context, you have to make sure to invoke the method as a… method.

Let me show you why it’s important.

Recall the world object having the method greet() upon it. Let’s check what value has this when greet() is invoked as a method and as a regular function:

const world = {
  who: 'World',

  greet() {
    console.log(this === world);    return `Hello, ${this.who}!`;
  }
};

// Method invocation
world.greet(); // logs true
const greetFunc = world.greet;
// Regular function invocation
greetFunc(); // => logs false

world.greet() is a method invocation. The object world, followed by a dot ., and finally the method itself — that’s what makes the method invocation.

greetFunc is the same function as world.greet. But when invoked as regular function greetFunc()this inside greet() isn’t equal to the world object, but rather to the global object (in a browser this is window).

I name expressions like greetFunc = world.greet separating a method from its object. When later invoking the separated method greetFunc() would make this equal to the global object.

Separating a method from its object can take different forms:

// Method is separated! this is lost!
const myMethodFunc = myObject.myMethod;

// Method is separated! this is lost!
setTimeout(myObject.myMethod, 1000);

// Method is separated! this is lost!
myButton.addEventListener('click', myObject.myMethod)

// Method is separated! this is lost!
<button onClick={myObject.myMethod}>My React Button</button>

To avoid loosing the context of the method, make sure to use the method invocation world.greet() or bind the method manually to the object greetFunc = world.greet.bind(this).

4.2 Indirect function invocation

As stated in the previous section, a regular function invocation has this resolved as the global object. Is there a way for a regular function to have a customizable value of this?

Welcome the indirect function invocation, which can be performed using:

myFunc.call(thisArg, arg1, arg2, ..., argN);
myFunc.apply(thisArg, [arg1, arg2, ..., argN]);

methods available on the function object.

The first argument of myFunc.call(thisArg) and myFunc.apply(thisArg) is the context (the value of this) of the indirect invocation. In other words, you can manually indicate what value this is going to have inside the function.

For example, let’s define greet() as a regular function, and an object aliens having a who property:

function greet() {
  return `Hello, ${this.who}!`;
}

const aliens = {
  who: 'Aliens'
};

greet.call(aliens); // => 'Hello, Aliens!'
greet.apply(aliens); // => 'Hello, Aliens!'

greet.call(aliens) and greet.apply(aliens) are both indirect method invocations. this value inside the greet() function equals aliens object.

The indirect invocation lets you emulate the method invocation on an object!

4.3 Bound function invocation

Finally, here’s the third way how you can make a function be invoked as a method on an object. Specifically, you can bound a function to have a specific context.

You can create a bound function using a special method:

const myBoundFunc = myFunc.bind(thisArg, arg1, arg2, ..., argN);

The first argument of myFunc.bind(thisArg) is the context to which the function is going to be bound to.

For example, let’s reuse the greet() and bind it to aliens context:

function greet() {
  return `Hello, ${this.who}!`;
}

const aliens = {
  who: 'Aliens'
};

const greetAliens = greet.bind(aliens);

greetAliens(); // => 'Hello, Aliens!'

Calling greet.bind(aliens) creates a new function where this is bound to aliens object.

Later, when invoking the bound function greetAliens()this equals aliens inside that function.

Again, using a bound function you can emulate the method invocation.

5. Arrow functions as methods

Using an arrow function as a method isn’t recommended, and here’s why.

Let’s define the greet() method as an arrow function:

const world = {
  who: 'World',

  greet: () => {
    return `Hello, ${this.who}!`;
  }
};

world.greet(); // => 'Hello, undefined!'

Unfortunately, world.greet() returns 'Hello, undefined!' instead of the expected 'Hello, World!'.

The problem is that the value this inside of the arrow function equals this of the outer scope. Always. But what you want is this to equal world object.

That’s why this inside of the arrow function equals the global object: window in a browser. 'Hello, ${this.who}!' evaluates as Hello, ${windows.who}!, which in the end is 'Hello, undefined!'.

I like the arrow functions. But they don’t work as methods.

6. Summary

The method is a function belonging to an object. The context of a method (this value) equals the object the method belongs to.

You can also define methods on classes. this inside of a method of a class equals to the instance.

What’s specific to JavaScript is that it is not enough to define a method. You also need to make sure to use a method invocation. Typically, the method invocation has the following syntax:

// Method invocation
myObject.myMethod('Arg 1', 'Arg 2');

Interestingly is that in JavaScript you can define a regular function, not belonging to an object, but then invoke that function as a method on an arbitrar object. You can do so using an indirect function invocation or bind a function to a particular context:

// Indirect function invocation
myRegularFunc.call(myObject, 'Arg 1', 'Arg 2');
myRegularFunc.apply(myObject, 'Arg 1', 'Arg 2');

// Bound function
const myBoundFunc = myRegularFunc.bind(myObject);
myBoundFunc('Arg 1', 'Arg 2');

Indirect invocation and bounding emulate the method invocation.

To read about all ways you can define functions in JavaScript follow my post 6 Ways to Declare JavaScript Functions.

Confused about how this works in JavaScript? Then I recommend reading my extensive guide Gentle Explanation of “this” in JavaScript .

Quizzzzz: can a method in JavaScript be an asynchronous function?

PS如何去除头发、树叶等复杂团的背景方法

许多人都在学习photoshop的时候都很头疼图像的去背景,今天的教程教大家五个去背景的方法。

一:魔术棒工具

当你遇到一张背景颜色单纯,而且物体轮廓简单的图片时,魔术棒工具就是你最好的帮手。你可以借由鼠标的点击来选取背景,然后解除背景图层的锁定,再按下delete键就可以完成去背。魔术棒最重要的设定,就是所谓的容差。

以这张指尖陀螺的样片为例,当我点击蓝色背景时,你会发现魔术棒并未选取到陀螺旁边的阴影,因此我先按下快速键ctrl+d先取消选中,并且在工具列提高容差,比方说200,如此可以让魔术棒选取到更广的颜色范围。那么陀螺内的三个圆孔,又该如何选取呢?我按住ctrl和空格键不放,再按住鼠标左键向右拖拽,来将画面拉近。(快捷键),接着按住键盘的shift键,启用魔术棒的加选功能,依次点击圆孔内的三个蓝色背景,就可以将这些背景选中。不过你会发现上方的圆孔选区有溢出的情景,对此,我们可以切换到套索工具,同时按住alt不放,启用减去的功能,将勾选到的部分圈选起来,最后,同样解开背景图层锁定,按delete键删除背景。

二:背景橡皮擦

说到橡皮擦工具,大家都不陌生。我们只要将背景解锁,按住alt和鼠标右键不放,左右拖动来调整橡皮擦的大小,就可以擦除图片的背景。

相关的工具还有背景橡皮擦和魔术橡皮擦工具。以背景橡皮擦为例,使用前可以先到工具栏设置取样一次的设定。如此当我们对着背景按住鼠标左键之后,ps会自动避开背景以外的色彩,让你可以放心的进行头发去背景的操作。

而魔术橡皮擦更是结合了以上两者的功能,即使在背景没有解锁情况下,也可以借由鼠标点击,瞬间完成去背。

三:快速选取工具

如果问到哪一个选取工具在ps中使用频率最高的话,那快速选取工具绝对名列前茅。我们只要借着鼠标拖拽的方式就可以毫无困难选取到主体。甚至在新版的ps中还提供了所谓的选取主体的功能,他采用人工AI来自动识别图像中的主体,省去你手工操作的时间。而在初步选取完成之后,我们可以打开选取并遮住的界面,来继续修饰选取范围。

我们可以首先在视图模式中选择叠加模式,来看看选取的范围有没遗漏或溢出的情景。如果有的话,我们可以利用工具列的快速选取工具来将这些范围补上。或是按住alt键减去多余的区域。其次,我们可以切换到黑白模式,并且利用底下的滑杆来使选中主体边缘更加平滑,或是变得模糊,增加边缘对比,以及将选取范围向外扩张或收缩,处理好人物基本轮廓之后,我们可以回到洋葱皮模式来处理托版的去背。我到左侧工具列来启用调整边缘笔刷工具(第二个),笔刷直径不要设置太大,然后借由边缘的涂抹,就可以移除掉头发后面的蓝色背景。不过你会发现当我们切换到黑底或者白底的模式时,发丝的边缘会带有一些残留的蓝色,要改善这个问题最简单的方法是先点击移动边缘下面的输出设置,勾选净化颜色,总量设为100,输出下拉选择新建带有图层蒙版的图层,按下确定,接着我们可以新建一个空白图层,打开鼠标右键点击创建剪贴蒙版。然后选择画笔工具,按住alt不放,创建滴管工具在发丝上点击,来选择发丝色彩。然后将图层混合模式选择为颜色,这是再点击发丝,就可以覆盖掉蓝色的边缘。

四:笔型工具

虽然魔术棒或快速选择工具使用上非常方便,但遇到主体和背景颜色对比不是很明显时,就不能用了。这是要用到钢笔工具来抠图。钢笔工具可以让你用点击鼠标的方式建立直线,拖动鼠标时则可以产生曲线,曲线上的锚点附带了一对控制杆,按住ctrl键不放同时按住锚点时我们可以借由控制杆来调整曲线弧度。而如果按住alt不放,则可以调整单边的控制杆,来产生一个转角。钢笔工具除了自由度高,最大的优势是可以轻松选取圆滑的选取范围。虽然钢笔工具比较难上手,但是熟悉锚点和控制杆之后,许多比较难选取的图像就不成问题。路径绘制完毕之后,打开鼠标右键,选择建立选区,快速键是ctrl+enter,就可以将路径转换为选区,然后再到图层面板内,点击最下面的一排fx旁边的新增蒙版,就完成去背。

五:通道抠图去背景

在ps中有两种类型的通道,一种是rgb,也就是红绿蓝色版本,用来储存色彩资讯;另一种是用来储存透明资讯的alpha色版,也就是rgba.例如新增一个背景色为黑色的图档,将前景色设置为255,0,0的红色,并且建立一个圆形选取范围,再按住快捷键alt+delete来套用前景色。此时你切换到图层旁边的通道面板,你会发现这张图像其实是由红、绿、蓝这三种颜色组合而成的。你把这三个通道想象成红、绿、蓝三个手电筒,而目前红色手电筒色彩为白色,而绿色和蓝色一片漆黑没打开。同样道理,如果今天填上的色彩是r等于255,g等于128,也就是红色全部打开,绿色打开一半,光照在一起的时候,组合起来就会是橙色。所以通道的话看起来就会是红色全亮了,是白色,绿色亮了一半,是灰色,而蓝色全黑,值为0。因此简单来说,通道就是利用灰阶的影像来代表不同颜色的强度,组合起来就变成一张彩色的相片。不同于颜色通道,alpha是透明度通道。假设今天我使用快速选取工具建立的选区,然后执行选取,储存选区,那么这个范围就会有一个alpha的通道。在这个通道中,白色代表已选取区域,黑色代表未选取区域。所以今天,我向要存储这张图片的树木,以便将天空进行去背的话。那么我们只要找一张这个样子的alpha通道,事情就好办了。

然而树木这种复杂的结构,我们很难用复杂的方式来手绘,因为最简单的办法就是借用颜色通道来进行抠图。我们可以切换到通道面板进行比对,哪一个通道看起来最像是我们需要的alpha通道。显而易见的这边蓝色通道对比最为明显。

因此我将蓝色通道拖动到创建新通道按钮复制一份,虽然此时他的名称显示是蓝通道拷贝,但是实际上,他已经从颜色通道转换为alpha通道了。为了让这个alpha通道的外观更接近我们的目标模样,因此我打开菜单栏上的图像选项,点击应用图像,利用颜色加深的混合模式来加深图像,接着我到调整选项中,执行色阶,并且调整亮部和暗部的滑杆,亮度向左调,暗部向右调,使亮部更亮,暗部更暗(色阶调整方法下次单独教),然后启用画笔工具,前景色设为黑色来涂抹草地。至于天空部分,选择减淡工具,范围设置为高光,按住alt和鼠标右键向右拖动来调整笔刷大小,来将浅灰色区域加亮成白色。全部处理完成之后,按下快捷键ctrl+i来反转黑白两色。再按住ctrl键点击缩图来点击alpha通道,也就是蓝拷贝通道的缩略图,来建立选取范围,接着点击rgb通道,再回到图层面板,点击最下面第三个图标添加蒙版,来完成树木的去背。有需要的话你也可以拉入一张天空的图片,并且拖动到树木图层的下方,来测试去背效果。

附件下载:

wp如何设置自定义分类为默认分类

WP在注册custom taxonomy的时候添加default_term就好了。

function abt_register_taxonomy() {
//this code is 
  $args = array(
    'labels' => array(
      'name'  => 'Product Categories',
      'singular_name'  => 'Product Category',
      'all_items'  => 'All Categories',
      'edit_item'  => 'Edit Category',
      'view_item'  => 'View Category',
      'add_new_item'  => 'Add new category',

    ),
    'public'  => true,
    'show_in_rest'  => true,
    'hierarchical'  => true,
    'show_admin_column'  => true,
    'rewrite' => array(
      'slug'  => 'categories'
    ),
    'default_term'  => 'All'
  );
  register_taxonomy('product_category','products',$args);

然后在分类创建All的分类,下次发布的时候会自动选中