Node relativity view childen in parent node

You can use node relativity to attach nodes to other nodes. In this case, I am using it to attach reviews to product nodes, where the reviews are nodes in their own right. I want to be able to view the reviews (children) within the product node (parent).

There is a view (views.module) to control the display of the review nodes. Then, within the node.tpl template, add the 2nd part of the snippet (following //SNIPPET FOR NODE.TPL)

  1. //VIEWS EXPORT
  2. $view = new stdClass();
  3. $view->name = 'reviews_of_node';
  4. $view->description = '';
  5. $view->access = array (
  6. );
  7. $view->view_args_php = '';
  8. $view->page = TRUE;
  9. $view->page_title = '';
  10. $view->page_header = '';
  11. $view->page_header_format = '3';
  12. $view->page_footer = '';
  13. $view->page_footer_format = '3';
  14. $view->page_empty = '<p>No reviews found.</p>';
  15. $view->page_empty_format = '3';
  16. $view->page_type = 'node';
  17. $view->url = 'review';
  18. $view->use_pager = TRUE;
  19. $view->nodes_per_page = '10';
  20. $view->block = TRUE;
  21. $view->block_title = '';
  22. $view->block_header = '';
  23. $view->block_header_format = '3';
  24. $view->block_footer = '';
  25. $view->block_footer_format = '3';
  26. $view->block_empty = '';
  27. $view->block_empty_format = '3';
  28. $view->block_type = 'node';
  29. $view->nodes_per_block = '100';
  30. $view->block_more = FALSE;
  31. $view->block_use_page_header = FALSE;
  32. $view->block_use_page_footer = FALSE;
  33. $view->block_use_page_empty = FALSE;
  34. $view->sort = array (
  35. 'tablename' => 'node',
  36. 'field' => 'changed',
  37. 'sortorder' => 'DESC',
  38. 'options' => 'normal',
  39. ),
  40. );
  41. $view->argument = array (
  42. 'type' => 'relativity_parent',
  43. 'argdefault' => '7',
  44. 'title' => '%1 Review',
  45. 'options' => '',
  46. 'wildcard' => '',
  47. 'wildcard_substitution' => '',
  48. ),
  49. );
  50. $view->field = array (
  51. );
  52. $view->filter = array (
  53. 'tablename' => 'node',
  54. 'field' => 'status',
  55. 'operator' => '=',
  56. 'options' => '',
  57. 'value' => '1',
  58. ),
  59. );
  60. $view->exposed_filter = array (
  61. );
  62. $view->requires = array(node);
  63. $views[$view->name] = $view;
  1. <div class="review-link">
  2. <?php
  3. print l("Add your review of the $model","node/add/review/parent/$node->nid");
  4. ?>
  5. </div>
  6. <?php
  7. // Retrieve the view
  8. $view = views_get_view('reviews_of_node');
  9.  
  10. // Build the view into the $reviews variable with paging on and nodes per page set to 20
  11. $reviews = views_build_view('block', $view, array(strval($node->nid)), true, 20);
  12.  
  13. // Get the number of reviews
  14. global $pager_total_items;
  15. $numreviews = $pager_total_items[0];
  16.  
  17. // Print the reviews
  18. echo "<h3>Customer Reviews for the $model</h3>";
  19. if ($numreviews != 0) {
  20. print "Number of reviews: $numreviews";
  21. print $reviews;
  22. print "<p>Read all: ".l("$model reviews", "review/$node->nid")."</p>";
  23. }else{
  24. print "<p>There are currently no reviews for the $model. Be the first: ".l("Add a Review for the $model","node/add/review/parent/$node->nid")."</p>";
  25. }
  26. }
  27. }
  28. ?>

Comments

i can not understand since there s no query in views where does content come from ?

Add new comment