- b2evolution CMS User Manual
- Developer Reference
- How to... (Customize)
- How to turn a Skin into a Template
How to 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 the 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. It should look something like this:
<?php
/**
* This file will display a blog, WITHOUT using skins.
*
* This file will set some display parameters and then display the blog in a template.
*
* Note: You only need to use this file for advanced use/customization of b2evolution.
* Most of the time, calling your blog through index.php with a skin will be enough.
* You should try to customize a skin before thrying to use this fle.
*<br /> * Same display without using skins: a_stub.php<br /> *
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
* @copyright (c)2003-2004 by Francois PLANQUE - {@link http://fplanque.net/}<br /> *
* @package evoskins<br /> * @subpackage noskin<br /> */<br />
# First, select which blog you want to display here!<br />
# You can find these numbers in the back-office under the Blogs section.<br />
# You can also create new blogs over there. If you do, you may duplicate this file for the new blog.<br />
$blog = 2; // 2 is for "demo blog A" or your upgraded blog (depends on your install)<br />
# Tell b2evolution you don't want to use evoSkins for this template:<br />$skin = '';<br />
# This setting retricts posts to those published, thus hiding drafts.<br />
# You should not have to change this.<br />$show_statuses = array();<br />
# You could *force* a specific link blog here with this setting: (otherwise, default will be used)<br />
# $linkblog = 4;<br /># This is the list of categories to restrict the linkblog to (cats will be displayed recursively)<br />
# Example: $linkblog_cat = '4,6,7';<br />$linkblog_cat = '';<br />
# This is the array if categories to restrict the linkblog to (non recursive)<br />
# Example: $linkblog_catsel = array( 4, 6, 7 );<br />
$linkblog_catsel = array( );
# Here you can set a limit before which posts will be ignored
# You can use a unix timestamp value or 'now' which will hide all posts in the past
$timestamp_min = '';
# Here you can set a limit after which posts will be ignored
# You can use a unix timestamp value or 'now' which will hide all posts in the future
$timestamp_max = 'now';
# Additionnaly, you can set other values (see URL params in the manual)...
# $order = 'ASC'; // This for example would display the blog in chronological order...
/**
* Let b2evolution handle the query string and load the blog data:
*/
require(dirname(__FILE__).'/b2evocore/_blog_main.php');
# Now, below you'll find the main template...
?>
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, <em>before any other text in the file</em>.
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
<br /><base href="<?php skinbase(); // Base URL for this skin. You need this to fix relative links! ?>" />
with
<br /><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!