0

I have block view that should be rendered in the node details page. i.e /node/*. The block should render latest 6 nodes published under the Category category_field that the node has its value.

However, the URL is rewritten and the category id tid is not available. The URL is looks like the following:

http://example.com/Category/world/the-node-title

So the contextual filter is not available in the URL. So, I created the following PHP code, shown in the screen shot, to get the category tid and return it:

enter image description here

In the node.tpl.php when I try to var_dump($node->field_category['und'][0]['tid']); it returns the number of tid of the current node. However, the above demonstrated code seems to be not work in the PHP filter code. When I try to return any available value for an category id such as 19 for example, it works.

In other words, how could I return the current node's category field id to the filter?

1 Answer 1

1

I found the cause of the problem from this resource and I have to define the $node variable by:

$node = node_load(arg(1));

Then I use the $node as shown in the question above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.