Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: [MOD] Multiple layouts (templates) for sNews 1.7 only  (Read 3330 times)

H.A.C

  • Jr. Member
  • **
  • Karma: 20
  • Posts: 86
  • i love snews community for its great members
    • Chasoft Corporation
[MOD] Multiple layouts (templates) for sNews 1.7 only
« on: December 28, 2008, 05:07:53 AM »

Updated! 02/01/2009

Hi everybody! Happy sunny sunday!

I'm trying to update my website at http://www.chasoft.net to sNews 1.7. But I faced to many obstacles. 'cause I have a lot of modification in sNews 1.6 that uncompatible with 1.7.

Firstly, my website has multi-layout based on "MOD Multiple layouts" coded by codetwist. With sNews 1.7, that MOD is uncompatible. So I have based on that idea to code a new Multilayout MOD for sNews 1.7

Here is my works. Hope it useful to some one.

and sorry for my bad coding!

-------------- (note: this is based on Codetwist MOD)

Steps to follow in order to create site with different layout for pages (as in sNews pages):

0) Backup index.php and all (or just say something like 'hells bells' if U are true macho)

1) Create in the site root the layout folder and name it ... layouts

2) Create the copy of index.php, name it default.php and move it to yet another new folder - layouts/default/

3) A lot to do if You want this big example Wink
- Create the copy of index.php, name it page.php and move it to yet another new folder folder - layouts/page (made changes to it as needed)
- Create the copy of index.php, name it article.php and move it to yet another new folder folder - layouts/article (made changes to it as needed)
- Create the copy of index.php, name it special.php and move it to yet another new folder folder - layouts/special (made changes to it as needed)
- Copy of style from site root to folder layouts/special (made changes to it as needed)

By now You should have something like this:

Code: [Select]
.htaccess
index.php
style.css
readme.html
layouts/page/page.php
layouts/default/default.php
layouts/article/article.php
layouts/special/special.php
layouts/special/style.css

4) Tear the belly of index.php ... errr, edit in Your favorite editor to achieve following:

Code: [Select]
<?php
include('snews.php');
$curLayoutName   getlayoutdata();

// Contains used layout definitions
// Note:
//    $layoutFolder - full folder path from site root, followed by slash
//    $layoutFile - file name without any paths (supposed that files are at $layoutFolder)
//    $layoutStyleFolder - full folder path from site root, followed by slash

global $layoutStyleFolder;

switch ( 
$curLayoutName['type'] ) {
    case ( 
'category' ) :
      
$layoutFolder      'layouts/category/';
      
$layoutFile        'category.php';
      
$layoutStyleFolder '';
      break; 
   case ( 
'article' ) :
      
$layoutFolder      'layouts/article/';
      
$layoutFile        'article.php';
      
$layoutStyleFolder '';
      break;
    
// case ( 'built-in' ) :
      // $layoutFolder      = 'layouts/built-in/';
      // $layoutFile        = 'built-in.php';
      // $layoutStyleFolder = 'layouts/built-in/'; 
      // break;
    // case ( 'page' ) :
      // $layoutFolder      = 'layouts/page/';
      // $layoutFile        = 'page.php';
      // $layoutStyleFolder = ''; 
      // break; 
    // case ( '404' ) :
      // $layoutFolder      = 'layouts/404/';
      // $layoutFile        = '404.php';
      // $layoutStyleFolder = ''; 
      // break;    
   
default :
      
$layoutFolder      'layouts/default/';
      
$layoutFile        'default.php';
      
$layoutStyleFolder '';
      break;
}
 
include( 
$layoutFolder $layoutFile );
?>

And this is all there should be in index.php for site with multiple layouts Tongue

5) Now look into default.php:

Code: [Select]
<?php include('snews.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

and change the beginning of it to look like this:


Code: [Select]
<?php $styleFolder $layoutStyleFolder <> '' $layoutStyleFolder '../../'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

6) Repeat step 5 for page.php, only here You might want to add some changes in layout as well Wink Might help to see the difference between default and page layouts Tongue

7) Create function getlayoutdata() that returns name of layout suitable for content to display (You can place it either in snews.php, index.php or in separate file to be included)

Code: [Select]
<?php
// MultiLayout by H.A.C (www.chasoft.net)
function getlayoutdata() {
global $categorySEF$subcatSEF$articleSEF$_ID$_POS$_catID;

$arrResult = array();
if (($_catID == '0') && ($_POS == '')){ //BUILT-IN
$arrResult['type'] = "built-in";
$arrResult['name'] = $categorySEF;
else
if ($_catID == ''){
if ($categorySEF == '404'){
$arrResult['type'] = "error404";
$arrResult['name'] = "error404";
} else
if ($_POS == ''){ //HOME
$arrResult['type'] = "default";
$arrResult['name'] = "home";

else { //PAGE
$arrResult['type'] = "page";
$arrResult['name'] = $categorySEF;
}
}
else if ($_catID <> '') {
if ($_POS == ''){ //CATEGORY
$arrResult['type'] = "category";
$arrResult['name'] = ($subcatSEF <> "") ? $subcatSEF $categorySEF;
} else { //ARTICLE
$arrResult['type'] = "article";
if ($articleSEF <> '') {
$arrResult['name'] = $articleSEF;
} else $arrResult['name'] = ($subcatSEF <> "") ? $subcatSEF $categorySEF;
}
}
//print_r($arrResult);
return $arrResult;
}
?>



Credits to codetwist

I've just recode with his idea!

I'm upgrading my website to sNews 1.7. I must recode all the MODs that I applied in sNews 1.6. I'll post them all in this 1.7 forum
« Last Edit: January 02, 2009, 01:58:16 PM by H.A.C »
Logged
I'm not available ....until the end of the year 2009!
----------------------------
The largest website powered by sNews is in its way to become the biggest!
My great personal website powered by sNews 1.6
http://www.chasoft.net
Come to see how it's great!

mdj

  • Full Member
  • ***
  • Karma: 44
  • Posts: 226
    • mdj.us
Re: [MOD] Multiple layouts (templates) for sNews 1.7 only
« Reply #1 on: December 29, 2008, 02:27:48 AM »

That's good stuff.

I'm actually planning on making a "theme switcher" mod along similar lines as this.. though much more simple, i.e. one default index.php that calls the default theme index.php unless there's another theme set by a cookie.

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: [MOD] Multiple layouts (templates) for sNews 1.7 only
« Reply #2 on: December 29, 2008, 06:43:06 PM »

Well Done HAC. Codetwist's theme switcher was the first one I used with sNews 1.6, and I appreciated its simplicity at the time.  :)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

ha100

  • Newbie
  • *
  • Karma: 7
  • Posts: 19
    • ha100
Re: [MOD] Multiple layouts (templates) for sNews 1.7 only
« Reply #3 on: November 10, 2011, 04:29:04 PM »

Thank you for your code after a slight modification it well suited my purpose. K+
Logged