我想将我的谷歌地图自定义颜色从我的子主题传递到我的父主题。
So in my Parent Theme\'s functions.php I have
add_filter( \'post_thumbnail_html\', "map_thumbnail" );
function map_thumbnail($html, $color1, $color2) {
       $my_post = get_post($post->ID);
       $water_color=$color1;
       $tree_color=$color2;
       if($my_post->post_name == "contact") {
       $html = \'<img height="100%" width="100%" src="http://maps.googleapis.com/maps/api/staticmap?watercolor=\'.$water_color.\'treecolor=\'.$tree_color.\'">\';
       }
return $html;
}
I just want to pass two colors from my child theme\'s functions.php like so,
$color1 = \'#fb0000\';
$color2 = \'#c0e8e8\';
apply_filters(\'post_thumbnail_html\', $color1, $color2);
 但不幸的是,这不起作用。有人能帮我吗?我有3个孩子的主题,他们都有相同的地图,只是树的颜色和水的颜色是不同的。我想在父主题中保留主map\\u缩略图功能,并只传递子主题中的各个颜色。如果可能的话,请帮助我。
 
                    最合适的回答,由SO网友:majick 整理而成
                    坚持一次过滤一个值以保持简单,并为子主题使用的颜色添加过滤器:
add_filter( \'post_thumbnail_html\', \'map_thumbnail\');
function map_thumbnail($html) {
   $my_post = get_post($post->ID);
   $defaultcolor1 = "#??????"; // parent theme default
   $defaultcolor2 = "#??????"; // parent theme default
   $water_color = apply_filters(\'water_color\',$defaultcolor1);
   $tree_color = apply_filters(\'tree_color\',$defaultcolor2);
   if($my_post->post_name == "contact") {
       $html = \'<img height="100%" width="100%" src="http://maps.googleapis.com/maps/api/staticmap?watercolor=\'.$water_color.\'treecolor=\'.$tree_color.\'">\';  
   }
   return $html;
}
 因此,在子主题中,您可以使用:
add_filter(\'water_color\',\'custom_water_color\');
add_filter(\'tree_color\',\'custom_tree_color\');
function custom_water_color() {return \'#fb0000\';}
function custom_tree_color() {return \'#c0e8e8\';}
 
                     
                
                
                SO网友:tillinberlin
                没有亲自尝试过,我建议您为孩子的主题编写一个小函数,然后像这样调用家长的主题函数:
add_filter( \'post_thumbnail_html\', "child_map_thumbnail", 11 );
function child_map_thumbnail($html) {
    $color1 = \'#fb0000\';
    $color2 = \'#c0e8e8\';
    map_thumbnail($html, $color1, $color2);
    return $html;
}
 正如我所说:我自己还没有尝试过这一点,但我认为父主题的函数应该是可用的,所以基本上我的建议是调用该函数,而不是传递变量