简体   繁体   中英

Can I use LESS/SASS mixin colors with PHP?

I am developing a WordPress theme that uses a color picker in the admin panel in which users can pick a custom link color. I want the link hover color to be the same as the normal link color, but darkened 10%. In LESS I can use the link color as a variable and use @link-hover: darken(@link-color, 10%); but then that doesn't connect with the PHP color picker. Is there a way to get PHP to refer to a LESS or SASS mixin variable? Or maybe some other solution that gets the result I'm looking for?

Using: PHP 5.4.4 / WordPress 3.5 / LESS 2.7.1

My function for the WordPress "Theme Customizer" (from 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'] )));
  }

}

and then this in the header:

<?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>

If you use Javascript to parse LESS or SASS you could do it that way. Here's a thread describing how that works: Parse LESS client side . You would write PHP code that generated LESS and then use javascript to parse it on the client side.

Here's a thread on how to do it with PHP: How to generate lighter/darker color with PHP?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM