If I have a path to a user's image galleries (for example) that is /user/x/galleries, where x is the user ID, how can I enter that into the "Show block on specific pages" of block's visibility settings so that the block will appear on the image gallery listings for each user. Note that I do not want the block on a user's account page (/user).

I tried user/*/galleries, but that doesn't seem to work.

Comments

bojanz’s picture

The magic of PHP! Paste this snippet (and choose PHP for visibility settings, of course):

if (arg(0) == 'user' && is_numeric(arg(1)) && arg(2) == 'galeries') {
  return true;
}

This assumes that the user id is numeric. If it's not, feel free to delete that condition.

For more complicated block visibility usage scenarios, consider Context, or maybe even Panels.

dmetzcher’s picture

You've totally made my day! It is, in fact, magical. Thank you!

Here's the code I'm using, and for those who are interested, the block will still appear on all pages after /user/x/galleries/..., including pages generated when a pager is used in the page view and a user clicks to view the second page, etc. I tested this with...
/user/3/galleries?page=1
...still seems to work.

bojanz: Am I correct about that? If I use your code, anything that comes after the path defined (/user/3/galleries/) will be included? And if I didn't want it to display on /user/3/galleries/somethingHere, what could I do (if anything)?

Now I just have to edit (most of) my blocks so they use this code.

<?php
$match = FALSE;

// DO NOT display on these pages.
if (substr($_SERVER["REQUEST_URI"], 0, 10) == '/admin*')
{ $match = TRUE;}
if (substr($_SERVER["REQUEST_URI"], 0) == "/forums*")
{ $match = FALSE;}
if (substr($_SERVER["REQUEST_URI"], 0) == "/user/*")
{ $match = FALSE;}
if (substr($_SERVER["REQUEST_URI"], 0) == "/forum*")
{ $match = FALSE;}
if (substr($_SERVER["REQUEST_URI"], 0) == "/organization/*")
{ $match = FALSE;}
if (substr($_SERVER["REQUEST_URI"], 0) == "/destination/*")
{ $match = FALSE;}
if (substr($_SERVER["REQUEST_URI"], 0) == "/og")
{ $match = FALSE;}
if (substr($_SERVER["REQUEST_URI"], 0) == "/og/all*")
{ $match = FALSE;}

// Display on these pages.
if (arg(0) == 'user' && is_numeric(arg(1)) && arg(2) == 'images')
{ $match = TRUE;}
if (arg(0) == 'user' && is_numeric(arg(1)) && arg(2) == 'galleries')
{ $match = TRUE;}
if (arg(0) == 'user' && is_numeric(arg(1)) && arg(2) == 'images-of-user')
{ $match = TRUE;}

return $match;
?>
dmetzcher’s picture

I just realized...

The portions of the code where I'm telling it not to display the block are probably not going to work... those asterisks are going to cause issues. I found some other issues with my code as well. Maybe I should look into that module you suggested?

It would be really great if we could use something like...
user/(arg(1)/images
or
user/(arg(1)/images/*
or
user/*/images