开发者

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 开发者_JS百科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.


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'];
  }
}


Related content can be shown by using contextual filter in block views. This block view will contain content which are associated with the current content viewed by a user.

You can goto "Create related content block view based on terms in Drupal 7" blog post to get step by step instruction to create this block view.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜