By dan_no_yes on
I created a block that shows nodes of type 'answer' with a given taxonomy term displayed in a sidebar, using Views. I want to filter this block output to exclude the current node - so that you don't see a particular answer in the block when this answer is itself the node being accessed. Any suggestsions?
Thanks!
Comments
.
You can have node id of current node like( and know if it is a node):
check in your if what you're writting is the same node:
<?
if( !( $is_node && $node_id == $node->id) ){
//code if is not the same node
}
else{
//code if is the same node
}
I haven't tried, but maybe it would help
Good luck!
Clean URLs
Ok,
it may work. But what if I use clean URLs with explicit paths ?
I won't be able to get the node ID from the URL...
.
As far as i know, it doesn't matter.
But if you try and it doesn't work, please tell me to research a bit more about it
If you use the arg()
If you use the arg() function it always returns the parts of the unaliased path. So given node/123, arg(0) returns 'node' and arg(1) returns 123.
better :)
better :)
Great - thanks all!
Great - thanks all!
Views argument
I would like to get the current node ID in a view in order to exclude this current node.
How can I do this ? In my block processing or in my view ? Should I use the Views arguments ?
I'm using Views 2 and Drupal 6.6. The module PHPfilter does not work.
Use views arguments,
Use views arguments, assuming this is a block view
So simple
Perfect.
Many thanks !
D7 - "See Also" these nodes. Taxonomy Term Block View
I'm still bungling my way through this, but thanks to the tips above, I've had success modifying the Taxonomy Term View by creating a custom See Also: Block which is visible only on node pages. It lists other nodes similarly tagged, but excludes the current node.
For your Block, override the Contextual Filters (Arguments) from the defaults.
Add these filters and arrange them in this order;
Content: Nid
Content: Has taxonomy term ID (with depth)
Content: Has taxonomy term ID depth modifier
For Content: Nid
For Content: Has taxonomy term ID (with depth)
This PHP creates a string like 7+74+23 depending on how many terms you've tagged the node with.
Your Block can't be tested in the Preview window, but on visiting a relevant node page with taxonomy, it should list all other nodes with any of the same tags, and exclude the current node from that list.