我正在开发一个WordPress主题,该主题在管理面板中使用颜色选择器,用户可以在其中选择自定义链接颜色。我希望链接悬停颜色与普通链接颜色相同,但是变暗10%。在LESS中,我可以使用链接颜色作为变量并使用@link-hover: darken(@link-color, 10%);
但是那时它不会与PHP颜色选择器连接。有没有办法让PHP引用LESS或SASS mixin变量?或者也许是其他解决方案可以获得我正在寻找的结果?
使用:PHP 5.4.4 / WordPress 3.5 / LESS 2.7.1
我的WordPress“主题定制器”功能(来自hal gatewood):
function stillcalm_customize_register( $wp_customize )
{
$colors = array();
$colors[] = array( 'slug'=>'content_bg_color', 'default' => '#ffffff', 'label' => __( 'Background Color', 'stillcalm' ) );
$colors[] = array( 'slug'=>'content_text_color', 'default' => '#000000', 'label' => __( 'Text Color', 'stillcalm' ) );
foreach($colors as $color)
{
// SETTINGS
$wp_customize->add_setting( $color['slug'], array( 'default' => $color['default'], 'type' => 'option', 'capability' => 'edit_theme_options' ));
// CONTROLS
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, $color['slug'], array( 'label' => $color['label'], 'section' => 'colors', 'settings' => $color['slug'] )));
}
}
然后在标题中显示:
<?php
$text_color = get_option('text_color');
$background_color = get_option('background_color');
?>
<style>
body {
color: <?php echo $text_color; ?>;
background-color: <?php echo $background_color; ?>;
}
</style>
答案 0 :(得分:1)
如果您使用Javascript解析LESS或SASS,您可以这样做。这是一个描述其工作原理的线程:Parse LESS client side。您可以编写生成LESS的PHP代码,然后使用javascript在客户端解析它。
以下是关于如何使用PHP进行操作的主题:How to generate lighter/darker color with PHP?