Recent Topics

1 Aug 23, 2006 01:06    

I'm going to use b2evolution for a non-blog application that'll one day probably actually be a blog. I set up 8 blogs using stub files, and want to change some bits based on the selected blog. For example blog #1 will have fixed text on top of everything. Each blog will have the same overall look (skin) but differences that I can't set via the back office. I had been thinking of using a switch at each point in _main.php where I want to do something different, but have an idea that can get out of hand rather quickly. For example:

switch( $blog ) {
	case '1':
		require( dirname(__FILE__).'/blog1_bit1.php' );
		break;
	case '3':
		require( dirname(__FILE__).'/blog3_bit1.php');
		break;
	case '8':
		require( dirname(__FILE__).'/blog8_bit1.php');
		break;
	default:
		require( dirname(__FILE__).'/generic_bit1.php');
	}


Do that for 2 or 3 bits with 8 blogs and it can easily turn into a mess.

So anyway I had an idea maybe someone knows how to implement: instead of calling skins/skinname/_main.php if I could make b2evolution call _main1.php for blog #1 it'd make maintenance a bit easier. Anyone know how to do that? What files I would have to hack, meaning what file finally decides to call the skin's _main file?

Or maybe I should just make the real _main.php call a blog-specific _main.php?

2 Aug 23, 2006 07:35

same. What I am looking for, though I viewed it as a block-system to minimize file edits.

But if a block-system won't be available (built-in or plugin) then this method will be fine. Right now, just as suggested, I am using switches, but it'll be as EdB said, a mess once there are lots of blogs.

3 Aug 23, 2006 10:43

There's a couple of ways you could achieve this. The first is to copy the skin for each variation of content that you want (you would only need to have a _main.php in each folder and it could grab the rest of the files etc from the original skin folder).

The other way is to use the code I posted in the post about blocks. For your example it would look something like this :-

<?php
if( file_exists( dirname(__FILE__).'/_blog'.$Blog->ID.'_bit1.php' ) )
{
  include dirname(__FILE__).'/_blog'.$Blog->ID.'_bit1.php';
}
elseif ( file_exits( dirname(__FILE__).'/_generic_bit1.php' ) )
{
  include  dirname(__FILE__).'/_generic_bit1.php';
}
?>

If you're going to be using a lot of different 'bits' then I'd suggest making the above a function which would simplify your skin a tad :-

<?php
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );


function get_blog_bit( $bit )
{
  global $Blog;
  if( file_exists( dirname(__FILE__).'/_blog'.$Blog->ID.'_'.$bit.'.php' ) )
  {
    include dirname(__FILE__).'/_blog'.$Blog->ID.'_'.$bit.'.php';
  }
  elseif ( file_exits( dirname(__FILE__).'_generic_'.$bit.'.php' ) )
  {
    include  dirname(__FILE__).'_generic_'.$bit.'.php';
  }
}


.....


get_blog_bit( 'bit1' );


.....

get_blog_bit( 'bit2' );


.....

get_blog_bit( 'bit3' );
?>

¥

4 Aug 24, 2006 18:47

I found a neat little way to get this done. I made an _main.php file for each blog and named them _mainX.php where X is the blog number it's for. I then made the real _main.php be this:

<?php 

if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );

// SELECT THE _MAIN FILE FOR EACH BLOG
require( dirname(__FILE__).'/_main'.$blog.'.php' );

?>

Now I use one skin and one style sheet but can tweak each blog by tweaking it's _main file. Sloppy I guess, but hey - so am I!

5 Aug 24, 2006 19:44

Any answer that works after the sun is over the yardarm has my vote ;)

¥


Form is loading...