By allen074 on
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
Surround the while loop with a div
Surround the while loop with a div, something like this
Then you can write css rules using
#front-page .nodefor example, to change the background colorand they will only apply to front page nodes. Note these rules need to come after any more general
.noderulesquick one
Hi Allen,
If you just want to do that with blogs, there is another way of doing it...that might be simpler....
blog-teaserblog-teaserclass.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
looks like why don't you add
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, 광진구 구의동.
Regarding my reply
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.
quick one..
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
Thanks! Now I got it - I
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!
Do you mean the popular tags block?
It looks the same on the page you link to and your home page when using firefox.
on the home page, each story
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.
I am a bit confused
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.
ok - let me try again - i
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?
What I think you want
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).nope - on the home page i
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
well done..
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
It would need to be part of node.tpl.php
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.
nevets - any chance you can
nevets - any chance you can post the actual code to edit please?
thanks!
check this
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
Here is an example of using node.tpl.php
Currently you have a node.tpl.php file that looks something like this (assuming you are using a phptemplate).
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.
all of you rock nevets -
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
YAY i got it - i used a
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!!
snippet
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
ok will do! now if you all
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
can u post how you did it?
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