I am looking for a way to theme content that is in some ways a lot simpler than themes and a little bit more flexible in one respect. I run a site with several groups and I have to make it instantly clear were content originates from. This can of course be done by using themes, but it seems that this is not entirely what I need for two reasons:
- themes is too powerful: I only want the heading of the node to include a tiny logo, nothing else needs to change
- themes do not seem to work with teaser list, especially on the the frontpage, even using views - it would be very helpful if my user could instantly see that this teaser originates from that group and the other teaser from the other one
What might do the trick is to use the node template, have it check what group the node belong to and then display the group logo for that node, be it teaser or complete view of the node. Is there a way to do this using PHP (if so, what variables would I have to look at), or is there another approach I could try?
Thanks very much for your comments on this!
Comments
theme node templates
I have a site setup where the nodes are themed based on content type (and taxonomy).
This may help: http://drupal.org/node/17565
Thanks for the link! Do you
Thanks for the link! Do you have any idea about how to make node & teaser of the node appear differently not based on content type or taxonomy, but rather according to the organic group the node belongs to? Groups can of course have themes, but that does not seem to affect the teaser on the front page...
Also...
You could use the taxonomy_theme module (http://drupal.org/project/taxonomy_theme).
I didn't use this module because it just adds one more module to the list, and to keep up with. And, to me, it seems there's more control over node theming with the node-$type.tpl.php method.
Cheers,
Carey
I am also not keen on adding
I am also not keen on adding more modules, unless necessary (we already have way too many), so I'd much rather go with the template approach, as indicated in my posting. The only problem I have with this is how to identify which group the node belongs to. I do not want a different appearance based on taxonomy or node type, only based on the group the node belongs to. This works well using themed groups, but this does not affect the teaser on the front page.
I only want to add a tiny logo to the heading of *every* node, be it teaser or full node, frontpage or within the group, but for that I need a PHP variable or something to identify which group the node belongs to...
If by groups you mean organic groups
If by groups you mean organic groups there is a field in $node you can check (I think it is $node->groups). To be sure you can add
to the the top of your template file and it will show all the fields/members available in $node.
yes, OG
I do indeed mean organic groups - sorry, should have made that explicit! The node code you kindly provided gave, among other things, the following output:
So, one of my groups is called Digital Historian, and as you can see the ID of the group node is 38. How would an if statement have to look like that checks for the name of the group? I tried
<?php if ($node->og_groups=="38") { echo "38"; } ?>but that does not seem to do the trick. Unfortunately, my PHP is very limited and as both variables return an array I am not sure how to do this...
You need to look at the elements of the array
You do not say if the node can be more than one group, in the code that follows we always use the "first" group to determine what to do
You would add one case per group (in the snippet is assumes there is a group 37 and 38), you will need to tailor this to your need. The default case handles nodes not in a known group (no case statement) and nodes not in any group.
excellent
Thank you very much, that is extremely helpful!
Yes, nodes can be in more than one group. How do you think this could best be handled from the php/code side of things? I would like it to display the logo (this is what the print statement does, it includes a logo before the heading) of the group that the node was put in first - I don't think that there would be any other easy solution. If this is to complicated it would also be OK to have all the logos there (not too many groups and the logos are smallish).
Thanks again!
Logo for each group
I am not aware of a way to tell which group the node was placed in first. You could use something like the following to show the logo for all the groups the node belongs to.
From the previous example this version looks at each of the groups (the foreach loop) the node belongs to.
Invalid argument
Thanks! Unfortunately, the code returns this:
warning: Invalid argument supplied for foreach()There must be some way - earlier on I had different themes for different groups and Drupal automatically choose the group a node was placed in first as the group relevant for the theme, so I suspect it simple takes the first group ID it finds in the database...
This should help
Try changing
to
Excellent! I am really
Excellent!
I am really impressed by how supportive this community is!
Please let us know when you
Please let us know when you get this working, and what and how you implemented the solution so others who come across this thread will benefit as well. :)
Cheers,
Carey
You will find the answer in
You will find the answer in the other thread :)