Search code examples
drupal-7taxonomy

Views Content Pane "Related content" by taxonomy


I'm currently developing a Drupal 7 site where I use Page Manager's "node_view" to customize the layout for my "Article" content type. So, whenever viewing an Article I want to show a little box with "Related content". I have a taxonomy vocabulary "Shared category" that I use in all my content types.

For example I also have a "Gallery" content type, so when viewing an article in with the "myTag" term - I want to show a Content Pane with images tagged with "myTag" from the "Shared category" vocabulary.

My question is about setting up the Contextual Filter for the Content Pane. Should the "Argument input" be a Vocabulary or a Term? - I've tried both but can't get it to work.

Also I have another question: Is it possible to use a Content Pane as a block, that is shown with the Panel? - I guess not, sinse the Contextual filter value comes from Page Manager.


Solution

  • You won't want to manually input the argument in the panel, as it will vary for each article. You'll want to set it automatically using a default argument that gets the tid from the node.

    To get the related content block to show content based on the same terms as the node being viewed, you'd need to add a taxonomy term id argument to the view. You can then try the 'Set a default argument' and use 'taxonomy term from URL' ( node option )

    If that doesn't work, you may need to get the relevant tid from node using php code in the default argument area, with something like node_load or menu_get_object to load the node.

    e.g something like

    if($node = menu_get_object()){
      if(isset($node->field_shared_category[$node->language][0]['tid'])){
        return $node->field_shared_category[$node->language][0]['tid'];
      }
    }