SLB: Registering Themes

Progress continues on enabling themes (née templates) in Simple Lightbox.  After a quick finalization of the theme structure, I moved onto adding the necessary API hooks to allow anyone to register a theme to be used by SLB.

What does this mean?

In short, it means that users will be able to create and share new themes just like WordPress plugins (in fact, they will be distributed as WP plugins).  In addition, templates will also be able to register custom themes so that the lightbox will integrate perfectly with the theme.

Nice.

How is it done?

I couldn’t keep the Simple in the name if using SLB wasn’t simple, and registering themes is no exception.  2 simple steps is all it takes:

  1. Hook into slb_init_themes– This ensures that SLB is activated and ready for themes to be registered
    add_action('slb_init_themes', 'my_custom_theme');
  2. Register the theme using slb_register_theme()
    slb_register_theme($name, $title, $stylesheet_url, $layout);

All together now:

add_action('slb_init_themes', 'my_custom_theme');

function my_custom_theme() {
    $name = 'cool_theme';
    $title = 'Cool';
    $stylesheet_url = '[URL to CSS file goes here]';
    $layout = '[layout html goes here]';
    slb_register_theme($name, $title, $stylesheet_url, $layout);
}

Once a theme is registered, it will be selectable from the admin options.  This is the final part that I will be wiring up tomorrow, so if all goes well, I’m hoping to have a new version to release by tomorrow!

So go make some themes!  (Check out yesterday’s post for more information on theme layouts).

Discuss

11

mo

April 13, 2011 4:10 am

Hi!

I just put together a quick plugin with the code provided above,…
It show’s up in my plugins, can be activated and is then available in the theme list of SLB.

For some reason it’s not working then…
It’s just the code above linked to a css and html file – not working. :(

Sol

April 13, 2011 6:50 am

@mo: Just for clarification, are you using a URL or the actual HTML for $layout? It should be the HTML for the layout, not a URL.

alexo05

August 28, 2011 2:32 pm

This might get into actual PHP programming territory but how to I make a call to the location of my CSS file without actually hard-coding the URI?

Thanks for a great plugin!

Sol

August 28, 2011 3:16 pm

@alexo05: You can use WP functions such as get_bloginfo() and plugins_url() to build most of the URI for you. Then you just have to provide the relative path to your CSS file.

eaglejohn

May 8, 2012 9:25 am

I registered my own theme and selected it in the WP Admin panel. After clicking a link, the layover pops up, but no content is shown. Any suggestions?

eaglejohn

May 8, 2012 9:51 am

I checked the URL and both the CSS and HTML files are linked correctly. I copied the default CSS and HTML file from the plugin directory.

Sol

May 8, 2012 9:59 am

@eaglejohn: Can you provide link so that I can investigate your issue further?

Also, just to be sure, you’re specifying a URL for the CSS file and the actual HTML markup (not a URL) for the layout right?

Pix

June 15, 2012 11:46 am

Hi,

Great plugin, really, but I’m sorry, I’m good in code but I can’t understand your method. Where is slb_init_themes ??? I can’t find this (I have upload the plugin file and no slb_init_themes inside, anywhere) so I can’t do the rest… I must be dummy but after 1 hour trying to figure out, I ask ;) Thanks for any help, Best regards,

Pix

Sol

June 25, 2012 12:53 pm

@Pix: SLB uses an internal handler for hooks (actions/filters), so you won’t find slb_init_themes if you’re doing a text search. Rest assured that the hook is fired though.

I would suggest making sure that you have the latest version of SLB installed before following the steps outlined above.

Let me know if you’re still having problems after that.

Dmitry

August 2, 2012 11:50 pm

Can you make an example of external theme?

Sol

August 3, 2012 4:32 pm

@Dmitry: Yes, very good thinking. Additional themes will be released soon after the release of SLB 2.0. Among these will be a “starter” theme that will help designers and developers create custom themes for SLB.

Leave a comment