Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Less Plugin
#1
Less plugin:

This plugin helps you to use LESS to write your style sheets instead of CSS.
(see http://leafo.net/lessphp/ for information on the syntax of LESS)
The performance impact is minimal, as CSS files are generated when first needed and afterwards served directly to the site user.

Just write a LESS file (e.g. here background.less with a variable color):
Code:
body { background-color: @color; }
Of course your file will probably be longer and use each variable multiple times.

Then you can use this file within your template:
  • Either your LESS file is recompiled every time it or the parameters change, which makes sense, if you want to keep your CSS file untouched and just set the variables in your template file (or from some other site-wide setting):
Code:
<link rel="stylesheet" type="text/css" href="<?php get_less_css('background.less', array('color'=>'green')); ?>" />
  • Or you want to set the parameters depending on the page (or time of date, etc.), thus using multiple CSS files generated from one less file at the same time. The following example shows, how to set the background color based on a custom field color in the page (white as default, note the last parameter true):
Code:
<link rel="stylesheet" type="text/css" href="<?php get_less_css('background.less', array('color'=>return_custom_field('color', 'white')), true); ?>" />

API:
Code:
function return_less_css($themeRelativeLessFile, $params=null, $multipleCSS=false)
Compiles a LESS file to a css file, if the less file is newer or the parameters are changed ($multipleCSS = false).
Compiles a LESS file to a parameter specific css file, if the less file is newer ($multipleCSS = true).
The first parameter is the name of the LESS file, e.g. "default.less" (if it's directly in the theme directory) or "css/default.less".
The second parameter is an associative array with the parameters for the LESS file and the last parameter must be true, if for each parameter set a new CSS file should be compiled and all these CSS files should be available at the same time.
Returns the full URL of the generated CSS file.

Code:
function get_less_css($themeRelativeLessFile, $params=null, $multipleCSS=false) {
The same as above but outputs the CSS file URL.


For yet another CSS like syntax see the SCSS plugin.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply


Messages In This Thread
Less Plugin - by mvlcek - 2014-03-26, 07:04:48
RE: Less Plugin - by Oleg06 - 2014-03-26, 17:42:03
RE: Less Plugin - by mvlcek - 2014-03-26, 18:51:42
RE: Less Plugin - by Oleg06 - 2014-03-26, 20:28:15
RE: Less Plugin - by mvlcek - 2014-03-26, 20:41:40
RE: Less Plugin - by Oleg06 - 2014-03-26, 21:12:55
RE: Less Plugin - by Oleg06 - 2014-03-26, 23:54:11
RE: Less Plugin - by mvlcek - 2014-03-27, 04:20:20
RE: Less Plugin - by morvy - 2014-04-04, 23:14:15
RE: Less Plugin - by mvlcek - 2014-04-05, 01:09:55
RE: Less Plugin - by mvlcek - 2014-07-12, 18:21:11
RE: Less Plugin - by cvrglj - 2015-07-10, 21:42:01
RE: Less Plugin 2022 PHP8.1 - by jofer - 2022-12-19, 03:08:10



Users browsing this thread: 1 Guest(s)