博文

[WordPress]What the F***! the parent theme is missing?!

There is a very wired problem. I created a child theme named Fatsom Child and I set 'Template: Fatsom' in style.css and the parent theme is Fatsom which had been already installed. It worked perfectly in my local environment. The child theme could be successfully detected by WordPress and activated manually. But, when I uploaded the parent theme and child theme to  my host, a very strange thing happened: In my backend, WordPress threw an error saying "the parent theme 'Fatsom' is missing"! And I could not find 'Fatsom Child' to activate! Why! I was blocked by this problem the whole evening. Finally, I found the solution -- just change 'Template: Fatsom' to 'Template: fatsom' in style.css of the child theme and it works again! I couldn't tell why, but it just happened. If you knows why or encountered the same problem, please comment this blog or email me (wagner@joybin.cn). Have a good day!

[WordPress]Oops, customized query vars make front page missing

There is a very strange thing which may be a bug but not fixed yet in WordPress -- If you add a customized query var, it will make the WordPress lost the static front page and directly point to the post river. (As discussed in https://core.trac.wordpress.org/ticket/25143#comment:36 ) For example, if our static front page is http://www.example.com/ and we add following code to add a query var named 'lang' hoping that we could get 'lang' from the structure of http://www.example.com/%lang% function add_custom_page_variables ( $ public_query_vars ) {         $ public_query_vars [] = ' lang ';         return $ public_query_vars ;     } add_filter ( ' query_vars ', array ( $ this , ' add_custom_page_variables ' ) ) ; It doesn't work. get_query_var will return null and what is worse, the front page will lost if we use http://www.example.com/en. Actually, current parse_query will check $_query after it thinks it is a ho...

[WordPress] About the URL autocompletion function in WordPress

There is an unimpressive URL autocompletion function in WordPress which a lot of the users or developers may not know. This function can find the most similar URL even if the URL input is not exactly right. For example: there is a permalink http://www.example.com/testpost If you mistakenly input http://www.example.com/testp, the WordPress can still help you find the testpost. This sounds nice. But it can cause some problems. For example, I want to add a rewrite rule to make http://www.example.com/en point to http://www.example.com/?lang=en. This autocompletion function will still try to find something similar to 'en' instead of giving me the page of http://www.example.com directly. So we have to turn off this function. Here is the solution: add_action ( ' redirect_canonical ', ' __return_false ' ) ; After adding this action, this autocompletion function will be turned off and the rewrite rules will successfully work.

[WordPress API] About the 'count' field of get_terms function

get_terms is a very common function in WordPress. Here is the definition: get_terms(  array|string   $args  =  array() ,   array   $deprecated  =  ''  ) For example: $res = get_terms(term->taxonomy, array('parent' => term->id, 'hide_empty' => false)); var_dump($res); The WordPress will print something like this: array (size=5) 0 => object ( WP_Term )[ 4319 ] public 'term_id' => int 15 public 'name' => string 'Copenhagen S' (length=12) public 'slug' => string 'copenhagen-s' (length=12) public 'term_group' => int 0 public 'term_taxonomy_id' => int 15 public 'taxonomy' => string 'property_city' (length=13) public 'description' => string '' (length=0) public 'parent' => int 37 public 'count' => int 3 public...

[WordPress Plugin] Translator with Baidu Service -- a good alternative to GTranslate to avoid GFW problem

If some of your WordPress site's users are in mainland China, you may need a plugin to translate your site into Chinese. One of the most popular translating plugin is GTranslate which is based on the Google translating service. But the problem is people in mainland China can not access Google. As a result, GTranslate cannot work in mainland China, only if using the VPN -- it's not quiet possible for a potential visitor to buy a VPN account.  Translator with Baidu Service is a similar plugin which is based on Baidu translating service. As Baidu is a big Chinese company, its translating service can be accessed from mainland China. Moreover, because Baidu deploys its servers all over the world,  people can use its services wherever they are.  Baidu translating service is very good at translating different languages into Chinese. Currently Translator with Baidu Service supports 25 languages: Chinese, English, Japanese, Korean, French, Spanish, Thai, Arabic, Russian, Po...

[PHP]Difference between require and include

require: 1.Upon failure it will also produce a fatal E_COMPILE_ERROR. 2.   require() will always read in the target file, even if the line it's on never executes. That means if require() is in 'if', no matter whether the condition is met, the file will be read. include: 1.Upon failure it will only emit a warn ing   E_WARNING. 2.Can conditionally include a file.

How to make a triangle with CSS

Some times we need to make a triangle after some elements in the page, for example, simulating a kind of dropdown menu. The triangle above is made by div and CSS. Here is the code: <div class="example-btn"> </div> <style> .example-btn{ background-color: transparent; height: 0px; width: 0px; padding: 0px; content: " "; border-width:25px 25px 0px 25px; border-color: #000000 transparent; border-style: solid; } </style> The code is very simple, I believe everyone knows CSS can read this code -- it is an empty div with 0 width and 0 height and borders. But how does this form an triangle? If we change the code above like this: <div class="example-btn"> </div> <style> .example-btn{ background-color: transparent; height: 0px; width: 0px; padding: 0px; content: " "; border-width:25px 25px 25px 25px; border-color: #000000; border-style: solid; } </style> We will get t...