0

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?

3
  • "Just the first path" is which path? user/* is supposed to show all pages such as user/relationships /user/mycustompath etc., because * is a wildcard. Where exactly do you want to show the block? Commented Feb 7, 2013 at 2:30
  • Just on the individual user's profiles, and not on the accompanying tabs associated with it.
    – rborgeous
    Commented Feb 7, 2013 at 3:13
  • @user12763, you copied my code into your question. This is not irrelevant. Thus, I edited your question to get it back to the original state. I wonder why you did not understand what I said in the code: && you may add more conditions here by checking arg(1), arg(2) which is what you are trying to achieve.
    – Sithu
    Commented Feb 14, 2013 at 5:28

2 Answers 2

3

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/*.

1
  • I tried it out and is still displays on user/*/edit i just want it on the user's main profile. nothing else.
    – rborgeous
    Commented Feb 14, 2013 at 0:56
1

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;
}
?>
1
  • This is what I mentioned in my answer - arg(0) == 'user' /* && you may add more conditions here by checking arg(1), arg(2) */ :)
    – Sithu
    Commented Feb 14, 2013 at 2:55

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.