[wp-hackers] styling a plugins widget in a theme

"Matthias P. Würfl" mpw at taquiri.de
Thu Jul 5 14:04:53 UTC 2012


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



More information about the wp-hackers mailing list