Hi,

I've been working on a new site (4.7 using phpTemplate) which has a fairly standard layout with a Blog/Articles section and a forum. But I've been wanting the forum to have a different layout, the FlatForum module got me halfway there, but I need the forum page template to be different too.

So I made a little script in the page.tpl.php file to detect if the user was on the a forum page and deliver a different template if they were. Here is the code I'm using, it basically uses the url to detect if it is a forum page or if the node type is 'forum':


<?php

//////////////////////
// DETECT FORUM PAGE //
//////////////////////

$ukf_url_expode = explode('/', url($_GET['q'], NULL, NULL, NULL)); 
$ukf_url_expode_rev = array_reverse($ukf_url_expode); 


$ukf_url_nid = $ukf_url_expode_rev[0];

$sql = "SELECT vocabulary_node_types.vid
		FROM node, vocabulary_node_types
		WHERE $ukf_url_nid = node.nid 
		AND node.type = vocabulary_node_types.type";

$result = mysql_query($sql);
$row = mysql_fetch_row($result);

if ($ukf_url_expode[0] == 'forum' or $row[0] == '1' ):


//////////////////////
// START FORUM PAGE //
//////////////////////
?> 

**Forum Template Code**

<?php 
///////////////////////
// START NORMAL PAGE //
///////////////////////

**Normal Template code**

<?php
 endif;
?>
else: 
?> 

So far it is working fine, but I'm a designer really, not a programmer (I just learn what I need to as I go along) so I'd like the opinion of someone more versed in PHP as to whether it is a good idea to use this system on a production site or if it is a horrible hack that'll cause me problems later.

Also on my local server (easyPHP) it is giving me the error: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in ... But the code itself is working fine and I can't see a problem, so I someone can point out what I've got wrong that would be great.

Thanks for any help,

Ed.

(ps. Is there and easier/better way to do this that I've overlooked?)

Comments

rout’s picture

...is designed to do this. You can find it here:
http://cvs.drupal.org/viewcvs/drupal/contributions/modules/sections/

From the readme.txt:

This module allows you to create sections. Each section has an installed template, theme or style attached to it. Each section also contains a path setting similar to the new blocks admin.
You can then assign themes to a list (regexped) paths.

For example, if you want another style for your site admin, all you have to do, is create a section with:
name: Adminstration Section
path: admin*
and select (a customade) theme "admintheme" to that section.

______’s picture

Thanks for the reply. I've had a look act the Sections module, but doesn't that require a whole new theme for each section.

If possible I'd rather not have to maintain two themes when most of the changes can be made by re-arranging a few blocks and another CSS file.

schwa’s picture

New at this, but for what it's worth, here's the code I'm using to detect a specific node type and redirect via phptemplate into a node-x.tpl.php:

<?php
if (arg(0) == 'admin') {
  include('admin.tpl.php');
  return;
}
?>

The above, for instance, redirects into a custom node-admin.tpl.php, where I've made my design tweaks using a foundation of the standard node.tpl.php. I believe this works for any node (if a forum is technically a node?).

(edit)
On the other hand, if you're way ahead of me (=probable) & your code can handle the issue of replies/comments *not* being recognized as forum pages, I'd be happy to steal it for the same issue I'm having using a custom blog theme. :)

______’s picture

Thanks, I'm aware of that technique to change the node template, but I want to change the page template for the forum. To change the comments to look like a forum you should look at the FlatForum module which is working well for me.

My code above works as a switch from within the page.tpl.php file to provide a different layout for forum pages. (The blog/articles and forum on this site will handle different information so need to be treated differently.)

I've posted it here firstly to share it but mostly to get feedback on whether this sort of thing is an acceptable use of templates or if will cause problems for me when the site is in a live environment (and hopefully someone can help fix that pesky error... ).

schwa’s picture

for kinda winging into your thread. Thanks for your time; I'll look into FlatForum & see if it can apply to blogs. I believe my issue here:
http://drupal.org/node/43387
is answered by your solution in this thread - although I'm using 4.6 - if I can get my newbie head around it adequately. (I don't need to theme blog nodes, I need to theme the pages that are blog nodes upon which comments appear, & blog.tpl.php doesn't cover all those page types.)

Good luck & I'm curious to hear if this solution is viable for production.