newest of newbies, trying to customize forums

gttygrl - November 6, 2009 - 19:41

I'm working on my first real Drupal site, so the answer could be really simple, but googling and experimentation aren't getting me my answer, so I need help.

All I'm trying to do is make the right promo column disappear for the forums so they'll have more room.

My current code (in page.tpl.php) is:

<?php if ($is_forum): ?>
<td valign="top" width="663"><div id="content-hope-mid-forum">
<?php print $tabs; ?>
<?php print $content ?>
</div>&nbsp;</td>
<?php else: ?>
<td valign="top" width="452"><div id="content-hope-mid">
<?php print $tabs; ?>
<?php print $content ?>
</div>&nbsp;</td>
<td width="1" bgcolor="#b1b7b3"><img src="images/ghost.gif" width="1" height="1" border="0" vspace="0" hspace="0" /></td>
<td valign="top" width="210"><div id="content-hope-right">
<?php if ($right): ?>
        <div id="sidebar-right" class="sidebar"><?php print $right ?></div>
        <?php endif; ?>

</div>&nbsp;</td>
<?php endif; ?>

I'm also totally new to php, so I've tried ($is_forums) and ($forums_defined), not knowing if I'm just using the wrong variable, but those aren't working either. Nothing's breaking, fortunately, but it's still using the else code.

Can anyone tell me what I'm doing wrong?

I think...

seaneffel - November 6, 2009 - 20:00

You could hand this between your page.tpl.php file and your block visibility admin area. As long as I understand that you are trying to not render a blocks region in your display. Try this:

In your page.tpl.php, wrap your blocks region in a little IF, something to the tune of this:

<?php if ($sidebar_left): ?>
  <div id="sidebar-left">
    <?php print $sidebar_left ?>
  </div>
<?php endif; ?>

This means if there are no blocks assigned to $sidebar_left on this page then it will not even draw the DIV that contains them. Then you can manage your block visibility, per block, so that no blocks are visible on the forum pages and then there is no column to cramp your style.

If you need to hide blocks from certain content types, check these snippets:
http://drupal.org/node/134425
http://drupal.org/node/502480

Also, you should use your styles.css file better. Then you aren't embedding column widths in your template files.

In styles.css, set the content column to have a width of "auto" and set the sidebar-left to have your choice of width value. Then your content column is flexible.

There are a lot of ways to do it, this is just my two cents. Good luck.

Oh yes, there are a lot of

FanisTsiros - November 6, 2009 - 20:18

Oh yes, there are a lot of ways to do it...

i would prefer the block visibility system... but if you want to play:

for availiable variables in YOUR node.tpl.php file see default node.tpl.php file in \modules\node\node.tpl.php
(not in sites\all\modules\...etc)

I just copied them here:

* @file node.tpl.php
*
* Theme implementation to display a node.
*
* Available variables:
* - $title: the (sanitized) title of the node.
* - $content: Node body or teaser depending on $teaser flag.
* - $picture: The authors picture of the node output from
*   theme_user_picture().
* - $date: Formatted creation date (use $created to reformat with
*   format_date()).
* - $links: Themed links like "Read more", "Add new comment", etc. output
*   from theme_links().
* - $name: Themed username of node author output from theme_user().
* - $node_url: Direct url of the current node.
* - $terms: the themed list of taxonomy term links output from theme_links().
* - $submitted: themed submission information output from
*   theme_node_submitted().
*
* Other variables:
* - $node: Full node object. Contains data that may not be safe.
* - $type: Node type, i.e. story, page, blog, etc.
* - $comment_count: Number of comments attached to the node.
* - $uid: User ID of the node author.
* - $created: Time the node was published formatted in Unix timestamp.
* - $zebra: Outputs either "even" or "odd". Useful for zebra striping in
*   teaser listings.
* - $id: Position of the node. Increments each time it's output.
*
* Node status variables:
* - $teaser: Flag for the teaser state.
* - $page: Flag for the full page state.
* - $promote: Flag for front page promotion state.
* - $sticky: Flags for sticky post setting.
* - $status: Flag for published status.
* - $comment: State of comment settings for the node.
* - $readmore: Flags true if the teaser content of the node cannot hold the
*   main body content.
* - $is_front: Flags true when presented in the front page.
* - $logged_in: Flags true when the current user is a logged-in member.
* - $is_admin: Flags true when the current user is an administrator.
...
...
...
..

The right variable is $type or $node->type

<?php if ($type=='forum'): ?>  .......

Hope this helps...

ReliabilityConsistencyFeedback ------ NeverAchievable -------

halfway there

gttygrl - November 6, 2009 - 22:09

Thanks, this is helping! But so far the only parts of the forum section that this is working for are the nodes that have actual posts. The parts of the forum that list containers and topics are not registering as type=forum, and I can't even find them listed in the 'content' list to figure out what they're 'type' might be, even though "/?q=forum" appears in the url path. Any ideas?

Fanis laid out the IF code to

seaneffel - November 7, 2009 - 05:35

Fanis laid out the IF code to determine the node type of a single node. But this won't help you on the forums container layouts because they aren't nodes, rather they are collections of many nodes at once. You can't really detect the node type of a batch of nodes. This distinction is causing your pain.

Head to Drupal's block admin area and check the visibility settings for each block you don't want to appear on your forum container layouts. For each block, mark it as "visible on all pages EXCEPT for the pages listed below" and enter "*forum*" (the asterisks are wildcards). Now on every URL that contains the term "forum", that block will not appear.

You can take it a step further by switching the selection to the last option, "only show pages if the PHP returns TRUE" and try entering in some custom PHP snippets that I quoted above.

I don't recommend hand coding block visibility into your theme files when Drupal gives you such a nice system to administer it. Your hard coded visibility settings aren't included in other themes, whereas the block visibility configuration settings are there no matter what theme you use.

forums container layouts aren't nodes...

FanisTsiros - November 7, 2009 - 08:46

forums container layouts aren't nodes, rather they are collections of many nodes at once. You can't really detect the node type of a batch of nodes

Sorry i missed that ! Sean, thanks this is a really usefull info.

I've never digg in theming forums so far...

And yes i agree with using drupal's block visibility system for this situation. I use this system with some php code commbination (see Sean's links above) and works fine for me.

ReliabilityConsistencyFeedback ------ NeverAchievable -------

Thank you! *forum* is exactly

gttygrl - November 7, 2009 - 22:55

Thank you! *forum* is exactly the silver bullet I couldn't find yesterday. And thanks for explaining about nodes vs. collections of nodes, I suspect that's going to come in handy when I tackle the the multiple blogs section.

 
 

Drupal is a registered trademark of Dries Buytaert.