开发者

Drupal List of related views

I need to list all the projects of an advertising company with their pictures and videos grouped by subject. For example, list under "Green Campaigns", all the projects related to that one, and at the same time, under each project show (using a grid) all the pictures and videos of that specific project. My approach was to make a different view for each listing, but I cannot attach a view inside another view.

I created a content type for th开发者_如何学Pythone pictures, the projects and subjects. Each making references to each other. (this part is working)


I won't say this is the easiest/best method but it should work... I assume you are using the node_reference, cck and views modules. I think you should do 2 things:

First, you should not create a new content_type for the subjects. It is better to create a taxonomy "campaigns" and set it up so you can choose a taxonomyitem from the "projects" content-type. You can use this to filter the "subjects" in your view(s).

Second, here's an example of loading a node using the node_reference module: In my example let's say there are 2 content types: event and eventsubscribers an event has a reference to multiple eventsubscribers. For this example I will be theming the content type by using the tpl.php . For more information have a look at: http://drupal.org/node/17565 , http://drupal.org/node/53464 and http://drupal.org/node/266817

  • Create a view with the main item you want to filter on. In my example every event has eventsubscribers attached to it so i create a view filtering on node type (event) and node published (yes).

  • Set the row style to 'node'. This will give you the ability to make a node-[content-type].tpl.php file in your theme map . Create the node-[content-type].tpl.php file in your theme map (node-event.tpl.php)

  • In the tpl.php file you can print all data using (php): print_r($node); this will give you all fields. Among those fields will be the node_reference field.

  • The node_reference field gives you id's from the nodes, so use node_load to load the full node in a variable. eg: $picturenode = node_load($node->field_ref_subscriber[0]['nid']) . for multiple picture, use a foreach loop around it.

  • After the node_load, you will have all fields from the node_reference in the variable (you can use print_r again to see how the array looks).You can use this variable to print out the picture. eg: print($picturenode->field_image[0]['view']);

In your specific case, the node_load will give you values instead of views. So use the imagecache function to theme the pictures (no idea what to do with videos though). To make it a bit easier, here's some example code:

<?php
// $Id: node.tpl.php,v 1.7 2007/08/07 08:39:36 goba Exp $
?>
  <div class="node<?php if ($sticky) { print " sticky"; } ?><?php if (!$status) { print " node-unpublished"; } ?>">
    <?php if (!$page) { ?>
        <h2 class="nodetitle"><a href="<?php print $node_url?>"><?php print $title?></a></h2>
    <?php }; ?>
    <div class="content"><?php print $node->content['body']['#value']; ?></div>
    <div class="subscribers"><?php //this will load all subscribers to the event
    foreach((array)$node->node_ref_subscribers as $subscriber){ 
        $subscriberdata = node_load($subscriber['nid']); //load the subscriber values in $subscriberdata
        print($subscriberdata->field_subscriber_body[0]['value'];); //print subscriber field
    }
    ?></div>
    <?php if ($links) { ?><div class="links">&raquo; <?php print $links?></div><?php }; ?>
  </div>
<?php
//print_r($node);
?>

This example has not been tested, and is only to be seen as a rough version of what you could do. Use print_r to see the data which is available in the node (and node_reference after node_load).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜