I have a question about the ul class in class-eo-event-list-widget.php. I use the shortcode [eo_events] to display a list of events on my site. Since I wanted it to fit the style of my site, I changed <ul class="%2$s">%1$s</ul>
to <ul class="zebra">%1$s</ul>
. Works like a charm!
But now I would like to display the same list somewhere else on my site is a different style.
I have two questions:
– what means the %2$s
in the original file?
– is there a way to display [eo_events] with different ul classes? Can I implement it in the shortcode for example?
Sorry if the answers are logical, but I’m not so good (yet) in php… Thanks!
Ties
Hi,
The %2$s
is used inside a sprintf
or printf
function (see this page). It acts a placeholder. The first argument of those functions takes a string (which will contain those placeholders), subsequent arguments are used as the values of those placeholders. So %1$s
will be replaced by the next and %2$s
by the following argument. The ‘s’ means string – it can also be ‘f’ for float or ‘d’ for digit.
E.g.
$num = 5;
$location = 'tree';
$format = 'There are %2$d monkeys in the %1$s';
echo sprintf($format, $location, $num );
//Prints There are 5 monkeys in the tree
In the particular instance you reference it used as follows;
$html = sprintf($container, $html, esc_attr($args['class']) );
Where $args['class']
contains class name(s) as set here.
Currently there isn’t a way of adding custom classes (but I’m planning on major improvements to template handling in 1.7 – including ‘templates’ for shortcodes, and widgets etc.).
I’d suggest wrapping the shortcode in div
element with a certain class and apply the styling that way. In any case – I’d recommend avoiding making any changes to the plug-in code as this will be lost in an update.
Stephen Harris