Hi - I am using the following snippet on my front_page:

<?php
/**
 * This php snippet displays the 10 most recent weblog entries with
 * teaser & info.
 *
 * To increase/decrease the number of weblogs listed
 * change the $listlength field to suit.
 *
 * Works with drupal 4.6
 */
  $listlength=10;
  $result1 = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.status = 1 ORDER BY n.created DESC"), $listlength);
  while ($node = db_fetch_object($result1)) {
    $output .= node_view(node_load(array('nid' => $node->nid)), 1);
  }
print $output;
?>

Basically each block is wrapped with the class=node. I would like to replace that with something else so I can style the results. The issue is that if i style "node" then it also changes the node style interior pages.

Thanks,
Allen

Comments

nevets’s picture

Surround the while loop with a div, something like this

$output = '<div id="front-page">';
while ( ... ) {
  ...
}
$output .= '</div>';
print $output;

Then you can write css rules using #front-page .node for example, to change the background color

#front-page .node {
  background-color: yellow;
}

and they will only apply to front page nodes. Note these rules need to come after any more general .noderules

Dublin Drupaller’s picture

Hi Allen,

If you just want to do that with blogs, there is another way of doing it...that might be simpler....

  1. go to your active theme folder and download node.tpl.php
  2. rename it to be node-blog.tpl.php
  3. open node-blog.tpl.php in a text editor like ps pad or notepad
  4. Edit how the teaser for blogs is wrapped, e.g. change the DIV class to be something like blog-teaser
  5. upload the edited node-blog.tpl.php file to your active theme folder and edit your style.css file with the settings for your new blog-teaser class.

your Drupal site will automatically see the node-$node->type.tpl.php file and apply that layout to blog nodes and you don't need to change the snippet...doing it that way, allows you to vary the layout per theme..

One small advantage of doing it that way is if you have a wireless or mobile theme.....the .tpl.php files in each theme folder has full control over how content is displayed. you can do it using different style.css files, but, I find that editing the tpl.php files gives more granular control over layouts sometimes...

If that doesnt suit your needs..post back up here, there are other ways of doing it...

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

openandout’s picture

I assume that nevets (post 1) is saying add a field to the nodes table and add an "if" clause to check the value of that field and ...........
as for Dublin Drupaller's answer, how can he tell it to load a different template for only a certain node, is a mystery yet, still, no?
(or did i miss the part about playing with blog.module?)
you'd still have to know .... where ...... the call to open that template file is, right?
i think it's pretty complicated in the theming department around here (@ drupal )....

seoul, 광진구 구의동.

nevets’s picture

No, there is nothing about adding a field to the node table, just surrounding the output of the div with a unique ID so that nodes can be themed differently.

Dublin Drupaller’s picture

Drupals phptemplate theme engine will automatically spot the node-$node->type.tpl.php layout file in the theme folder and apply that layout to $node->type nodes e.g.

node-blog.tpl.php will be applied to blog nodes(only)
node-image.tpl.php will be applied to image nodes (only)
node-audio.tpl.php will be applied to audio nodes(only)

hope that makes sense..

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

allen074’s picture

Thanks!

Now I got it - I actually got it while you were typing these replies but thanks!

Now the problem is fixing up the tags pages - like this one:

http://www.centernetworks.com/tag/aol

Any ideas where I edit that? I want the same style I put on the home page.

is it in the tagadelic module?

Thanks!

nevets’s picture

It looks the same on the page you link to and your home page when using firefox.

allen074’s picture

on the home page, each story has a border and a bg graphic (ignore the weird lines on the page left/right), on the tag page, that is not the same, there is no style at all.

nevets’s picture

You started out by asking "Basically each block is wrapped with the class=node. I would like to replace that with something else so I can style the results. The issue is that if i style "node" then it also changes the node style interior pages." which is what you now have :).

For the front page the nodes are in div with a class of 'homepagenode', for the other page the div uses a class of 'node'. There is a css rule for homepagenode that adds the graphic and borders. I do not see a similiar rule for node.

allen074’s picture

ok - let me try again - i never can seem to explain things right

now i have the tag pages wrapping each item with "node" by default - the problem is that if i change "node" in the style, it will change the actual content pages because those too are wrapped with "node"

on the tag pages i want to wrap it with something else or another div in addition say "tagitem" or whatever.

does this make more sense?

nevets’s picture

You have a "homepage" and "tag" pages where you want the look of the nodes to be different than else where on your site. I will define a "tag" page as one where the path starts with "tag". You have also managed to replace 'node' with 'homepagenode' for nodes on the home page so I a guessing you have already edited the node.tpl.php file to to do that. Without seeing the file it is hard to guess exactly what you did but there must be a conditional that picks "homepagenode" or "node". You can add to that conditional by including a check for arg(0) == 'tag' and giving node the same class as for the homepage (or even a different one if you like).

allen074’s picture

nope - on the home page i just edited the snippet i was using...

how would i add that conditional arg(0) part to the node page?

thanks much,
allen

Dublin Drupaller’s picture

Well done allen..is there any chance you can post your edited snippet?

I'm sure others would find it useful.

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

nevets’s picture

It would need to be part of node.tpl.php. While you can use arg(0) in the context of a php node, it will always be the same value.

allen074’s picture

nevets - any chance you can post the actual code to edit please?

thanks!

Phillip Mc’s picture

check dubliners phptemplate snippets section of the handbook where it has a few examples of using arg(n) in tpl.php files.

http://drupal.org/node/46027

phil

nevets’s picture

Currently you have a node.tpl.php file that looks something like this (assuming you are using a phptemplate).

  <div class="node<?php if ($sticky) { print " sticky"; } ?><?php if (!$status) { print " node-unpublished"; } ?>">
    <?php if ($picture) {
      print $picture;
    }?>
    <?php if ($page == 0) { ?><h2 class="title"><a href="<?php print $node_url?>"><?php print $title?></a></h2><?php }; ?>
    <span class="submitted"><?php print $submitted?></span>
    <span class="taxonomy"><?php print $terms?></span>
    <div class="content"><?php print $content?></div>
    <?php if ($links) { ?><div class="links">&raquo; <?php print $links?></div><?php }; ?>
  </div>
<code>
Replace the first line with this (or something similiar)
<code>
<?php
	$node_class = 'node';
	if ( $is_front || arg(0) == 'tag' ) {
		$node_class = 'homepagenode';   // Or what ever you want
	}
?>
<div class="<?php print $node_class; if ($sticky) { print " sticky"; } ?><?php if (!$status) { print " node-unpublished"; } ?>">

The important thing to node instead of hardcoding the class as 'node' we now use the value of $node_class which defaults to 'node' and can be changed on some logic. In this case we change it to homepagenode if it is the frontpage or on a 'tag' page.

allen074’s picture

all of you rock

nevets - that seemed to work for the frontpage, but not for the tag pages... any ideas why?

http://www.centernetworks.com/tag/aol

its still the same.

thanks,
allen

allen074’s picture

YAY i got it - i used a snippet to figure out the args - and this is what it comes back with:

Arg(0) = taxonomy

Arg(1) = term

Arg(2) = 24

Arg(3) =

Arg(4) =

so i just made it say taxonomy and it works

yippee!!

Phillip Mc’s picture

anyone else looking for that snippet, here's the link.

http://drupal.org/node/46027#comment-129853

Allen. Glad you got it sorted, but it would good to get into the habit of saying YIPEEE! *and* THIS IS HOW I DID IT!! so others searching the forums can actually find a solution.

Phil

allen074’s picture

ok will do!

now if you all could help me split the $tags that are returned so I can show both vocab's sep. I would easily give you my 1st born :)

thanks,
allen

Dublin Drupaller’s picture

Hi Allen,

Glad you got it sorted....when you get a chance can you post how you did it, instead of just "I actually got it working"?

I posted the original snippet you used at this handbook page: http://drupal.org/node/23231

If you have the time, it would be useful if you posted a child page underneath that original handbook page that explains how you did what you did.

It's probably not clear to newbies, but, that's the original concept behind the snippets sections of the handbooks..

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate