Posted by Randy74158 on November 20, 2012 at 7:38pm
First of all, I did everything by this guide:
- Create a block view
- Add Contextual filter -> Content: Nid -> Provide default value -> Content ID from URL
- Add Relationship -> Content: Taxonomy terms on node -> specify the appropriate vocabulary
- Add Relationship -> Taxonomy term: Content using vocabulary as specified above -> Check off Require this relationship
- Turn on Views aggregation
- Assuming you are listing title only, edit the title field to use the Relationship you set up in #4 above.
- Add new sort criteria of Content: Nid. In aggregation settings, select Count. Use relationship from #4 and sort descending
- Add Contextual filter -> Content: Nid -> Use relationship from #4 -> Provide default value - Content ID from URL -> Scroll down and expand "More" then check "Exclude" to remove current node from the view
And it works like a charm. However I have no idea how to exclude some of the taxonomy terms (by id or name) here, because I use some of them in my all posts (kinda related to category) and now it makes a little mess in related content block.
I also tried Contextual filter > Has taxonomy term ID > Provide default value > PHP Code:
<?php
$node = @node_load(arg(1));
if(@isset($node->field_tags)) {
foreach($node->field_tags['und'] as $term) {
if($term['tid'] != 6 && $term['tid'] != 8) { $terms[] = $term['tid']; }
}
return implode('+', $terms);
} else {
return;
}
?>Unfortunately, then the related content block doesn't show anything.
Any ideas?
Comments
A way to exclude
Just create another vocabulary for the universal terms.
Oliver "Andrew" McCloud
http://queryblitz.com
Quick and easy feedback for your websites.