[wp-hackers] styling a plugins widget in a theme
Lionel Pointet
lionel.pointet at globalis-ms.com
Thu Jul 5 14:11:04 UTC 2012
That's an idea, you could also provide a filter allowing themes but also
plugins to set a template file path like this:
if($template = apply_filters('my_widget_template_filter',
'/my/default/template') && file_exists($template)) {
include($template);
}
That way, you don't force the template path and name and let plugin
authors provide their templates too.
You could also put your normal output into an "else" section and let the
"/my/default/template" string empty, it's up to you...
Le 05/07/2012 16:04, "Matthias P. Würfl" a écrit :
> Am 05.07.2012 15:06, schrieb Mike Little:
>> My first thought would be to just change the CSS to style it how you
>> want
>> in your themes' style.css. Widgets have unique ID and easily
>> identifiable
>> classes, so you should be able to address a lot of look and layout
>> issues
>> with no need to modify code.
>
> Thanks for your reply.
>
> I looked at the code and it doesn't offer any hooks. Styling with CSS
> is not an option because i want to change date formats, change the
> order, etc.
>
> If you were the author of the plugin, what would be the best way to
> offer custom templates? I thought of something like this:
>
>> function widget(){
>>
>> // some stuff at beginning snipped
>>
>> // templates to search for
>> $search_for_templates = array(
>> get_stylesheet_directory() . "/" . $tpl . "-" . $slug . ".php",
>> get_stylesheet_directory() . "/" . $tpl . "-" . $id . ".php",
>> get_template_directory() . "/" . $tpl . "-" . $slug . ".php",
>> get_template_directory() . "/" . $tpl . "-" . $id . ".php",
>> get_stylesheet_directory() . "/" . $tpl . ".php",
>> get_template_directory() . "/" . $tpl . ".php",
>> );
>>
>> // see if we have a template
>> $i_already_did_output = false;
>> foreach($search_for_templates as $template){
>> if(file_exists($template) AND !$i_already_did_output){
>> include($template);
>> $i_already_did_output = true;
>> }
>> }
>> if(!$i_already_did_output){
>>
>> // normal output goes here (in case there's no template)
>>
>> }
>>
>> // some stuff at the end snipped
>> }
>
> Is this the best way or is there a better way to achieve this?
>
> Matthias
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
More information about the wp-hackers
mailing list