An example of view block with related nodes based on 'tags'.
1. Create a block (take a look at screenshots below)
2. Add a relationship: Taxonomy term: Content using: Tags
3. Add contextual filter: (field_tags) Content: Nid
When the filter value is NOT available
Provide default value -> Content ID from URL
MORE
check: Exclude
this contextual filter will remove current node from the view
4. Add contextual filter: Taxonomy term: Term ID
When the filter value is NOT available
Provide default value -> Taxonomy term ID from URL
check: Load default filter from term page
check: Load default filter from node page, that's good for related taxonomy blocks
choose the vocabulary (tags in this case)
Multiple-value handling -> Filter to items that share any term
When the filter value IS available or a default is provided
Specify validation criteria -> Basic validation
MORE
check: Allow multiple values
5. Define the fields (only titles in this case)
6. Make the view display only distinct items
Other -> Query settings:
check: Distinct
check: Pure distinct
参考:http://drupal.stackexchange.com/questions/79746/recommend-nodes-based-o…
评论2
试了一下,这个方法不行。不知道是不是有什么地方设置错了…
试了一下,这个方法不行。不知道是不是有什么地方设置错了。我越来越发现,调试View比自己写PHP代码费时多了。
自己写代码实现
把下面代码放到自定义的模块目录里的src/Plugin/Block/SimilarContentBlock.php可实现等价功能: