I want to display a block on the user/* page. I checked "only the listed pages" and entered "user/" but the block also appears on "user//relationships" for example.
How can I keep the block on just the first path?
If you want more control on this, you can choose the option "Pages on which this PHP code returns TRUE (experts only)" and you can write the following similar code snippet the the box.
<?php
if( arg(0) == 'user' /* && you may add more conditions here by checking arg(1), arg(2) */) {
return TRUE; // will display the block
}
return FALSE; // will not display the block
?>
The alternative way is to check the path with regular expression:
<?php
if( preg_match('/^user\/[[:digit:]]$/', current_path()) ) {
return TRUE; // will display the block
}
return FALSE; // will not display the block
?>
This will show your block only at the path user/*.
Check "Pages on which this PHP code returns TRUE (experts only) in block settings" and paste:
<?php
if ((arg(0) == 'user') && is_numeric(arg(1)) && (arg(2) == NULL)) {
return TRUE;
}
else {
return FALSE;
}
?>
arg(0) == 'user' /* && you may add more conditions here by checking arg(1), arg(2) */
:)
user/*
is supposed to show all pages such asuser/relationships
/user/mycustompath
etc., because*
is a wildcard. Where exactly do you want to show the block?&& you may add more conditions here by checking arg(1), arg(2)
which is what you are trying to achieve.