- b2evolution CMS User Manual
- Developer Reference
- How to... (Customize)
- Turn A Skin Into A Template
Turn A Skin Into A Template
This man page refers to b2evolution version 0.9.0.10, but should be applicable to most versions that support evoSkins
This is useful if you want to integrate b2evolution into an existing site, and keep the same "look and feel" throughout. It also will allow you to use the bloglist navigation to go to pages that might not be "actual" blogs. (Note: This is ‘'’not”’ the best way to prevent someone from switching skins! That can be set quite easily in the "Blogs" tab.) You might have a few blogs detailing the recent activities of your group, and a few static pages that state your mission statement or something. This allows you to integrate the two.
First, make your evoSkin the way you want it. That means, make sure that you’ve tweaked it how you want it tweaked, and it looks the way that you want them to. Once you go through this procedure, you’ll be stuck modifying things in two places if you want to change anything, which can be a bit of a pain. (Those of you who use stub files may notice that we’re basically taking a stub file and a skin and mooshing them together into one.)
This procedure could be done with any skin, but I’m going to refer to the "custom" skin, since that’s the one that most people use. If you want to do this with a different evoSkin, just replace "custom" with the name of your skin in each step.
Create the file
- Copy (don’t move!) the _main.php file from …/skins/custom/ to the base folder. We’re actually going to be transforming that into a template.
- Rename the new _main.php in your base folder to "template.php" (You can also use any other name that you prefer, of course, but I’ll be using template.php in this example.)
Make it a template
Open up the "noskin" template file that comes with the b2evolution installation. Copy out the top part, between the <?php and ?> tags, or use this code :
<?php
$blog = 2; //select the blog you want to display
$skin = ''; //Tell b2evolution you don't want to use evoSkins for this template:
$show_statuses = array(); //This setting retricts posts to those published, thus hiding drafts.
require(dirname(__FILE__).'/b2evocore/_blog_main.php');
?>
Of course, you may want to customize those values to make them more appropriate.
Open up template.php, and paste all that good stuff at the very top, before any other text in the file.
Transform the relativity
Now the tricky part. You’ll have to go through template.php and correct a few things, to account for the fact that we’re not using skins.
Fix the base href
Replace
<base href="<?php skinbase(); // Base URL for this skin. You need this to fix relative links! ?>" />
with
<base href="<?php skinbase(); ?>/skins/custom" />
This will ensure that the links to your CSS files and images will remain intact, by pointing the browser at …/skins/custom/ by default.
Fix relative includes
The file has a bunch of links like this:
require( dirname(__FILE__) . '/_linkblog.php' );
That says, "Take a file that’s in the same directory as this one, named _linkblog.php, and process it now."
However, template.php is no longer in the same folder as _linkblog.php! (Same goes for all the other skin files: _bloglist.php, _lastcomments.php, etc.)
Change that to something like this:
require( get_path('skins') . '/custom/_linkblog.php' );
(The same goes for require_once, include, and include_once function calls, as well.)
Tell b2evolution where your template is
Create a new blog (in the blogs tab.)
Set the access type for this new blog to "Other blog through stub file."
Set the stub name to template.php. (Also make sure that the blog folder and everything else is set up properly.)
If you include it in the public blog list, then on every blog, there will be a link to your new snazzy static template.
Finishing Touches
Now it’s time to think, "Why did I do this?"
Maybe you have a static page that you want to integrate into your site, but you want it to have the same stuff on the sidebars. That means, there won’t be any blog posts in this blog, since it’s just a static page. Maybe you do want this to be a blog, but only show a single post, and underneath that, a bunch of static content. You can open up template.php, and remove/add/change whatever you like to get it just right. You can replace the whole blog loop with a collection of pictures, or a resume, or anything else you want, and still keep the dynamic content all around it.
The other advantage is that you can now use b2evo’s hitlogging features to track the statistics on your static page, too!