Hi,

I've done a pretty good search and do not understand quite how to have content in a block that is related to a user on their page.

Show author content (for all visitors) only when visiting the specific user page.

Is it a block argument I've tried :

<?php
global $user;
return arg(0) == 'user' && arg(1) == $user->uid && !arg(2);?>

but that only shows the block to the author/user of the page.

I want all visitors to see content that is related to that user on their specific user page. It could be used for latest nodes, galleries, etc.

Look so forward to any reply, and thank you.
Lilian

Comments

liliplanet’s picture

* bump * sorry.

Is it possible to show a block on a users page (user/*) that shows content related to that specific user (the user that you are viewing)?

Would most appreciate any reply, and thank you.
Lilian

caschbre’s picture

I've never tried this but remember reading a post that talked about Views w/ arguments.

I believe what you can do is create a view that lists the title of all content types and pass the user to the view as an argument. I can't find the post but look around for how to use arguments in views. I'm guessing that would get you in the right direction.

liliplanet’s picture

* bump again .. sorry *

Please, is it possible to pass an argument in a block that shows content only related to the current user page.

For instance, you are looking at user X, and now a block with user X content appears on that specific page, for instance a gallery or nodes created by user X.

Is it a php argument in the block itself, or if I create a view, what would the arguments be in the view?

Have done an extensive search, to no avail. Would most appreciate any help, and thank you.

Lilian

m13’s picture

it's a block visibility issue.

GO here and choose the snippet that suits you

http://drupal.org/node/64135

don't forget to check the book contents on the left sidebar. You will find more block php snippets there :)

liliplanet’s picture

Thank you m13 for your reply.

Yes, I've gone through all the snippets, but there is not one for :

show the block content related to the current user page you are viewing

In other words it would be related content to the author of the page you are viewing.

There are 'if you are the author, by role, etc etc', but not the one as mentioned above.

Would most appreciate any assistance, as have been trying for weeks, and cannot find it on the book pages.

Looking forward to getting this right :)

m13’s picture

http://www.chromaticsites.com/blog/drupal-tutorial-adding-a-related-post...

and then go to the block you created, click on "configure" and choose "appear only on listed pages" and then enter the url (user/10) for example so that the block appears only on the user page.

if this is not what you need then please clarify what you wish to do and we will be more than happy to help :)

liliplanet’s picture

Thank you again m13.

I think it's a little more complicated than that.

Let me try to be more clear as an example.

You (visitor 1) visit my (user 2) user page on a website. In the blocks on my (user 2) page, you will see content that has been posted by me (user 2), for instance a gallery, or nodes, etc.

You (visitor 1) visit another user page (user 3), on that page blocks will show content only posted by (user 3).

Hope this makes a little more clear.

Look forward to your reply and again, thank you m13.

UPDATE: Your explanation on http://www.chromaticsites.com looks fabulous, will try that now :)

m13’s picture

I know you wish to automate this procedure but I don't think you can pass such an argument via block visibility settings.
I mean there is NO way you can create a view, display it as a block and then use php to call that block with arguments. The only way would be to pass the default arguments within the views.

That is, create a view as described in the tutorial I pointed previously and pass it some arguments. If I were you, I would comment the guys article and ask him for the answer. He is more than happy to help :)

anyway, these are the steps in order to achieve what you wish (and it IS complicated :) ).

(silly question but why don't you use TRACKER do achieve the same result? OK, it will not be displayed in a block but in a page, however, it is the only difference between what you wish to do and tracker).

Sorry I can't help you more on this one (today that is), I have more than 250 views to edit atm :S for a site I have to hand in tomorrow.

good luck!!!

liliplanet’s picture

m13, I had a look at your tutorial and it is so close to what we need.

The problem is we want related content to the user page (using content profile), thus user/*, and not related to a node.

When you visit the user/* page the author's content is in the block.

Is that at all possible please?

Fabulous tutorial, thank you!

m13’s picture

it is possible.

You create the view as described in the tutorial. Display the view as a block and then go to
admin--> blocks --> view_displayed_as_block_NAME --> configure --> php visibility settings --> appear on only the listed pages --> user/4 (for example).

Now if you have 5,000 users this would be a problem since you would have to manually set the block visibility for each user page!

here is were php snippets are really handy. Based on the author and URL (user/10 e.g.) you can set block visibility according to your needs.

Basically you will use php to tell the system something like
"make this block visible when the url one visits is equal to the user id"

liliplanet’s picture

Thank you m13.

Yip, as thought, it's not possible. I actually have over 12 000 users and was hoping to automate content on their user pages.

If I understand correctly, there is no argument (snippet) that I can put in a block that will pull content of the user on the user pages?

Thank you very much for your input and wishing you a great week.

Lilian

m13’s picture

there is no way to do that. Calling a block with arguments is not possible.

but you can pass the argument in the view I suppose.

caschbre’s picture

I happened across this module today...

Views Attach

Sounds like this module makes values from the current node available as arguments to pass to a block view. I haven't used this mod but it sounds like it -may- provide the argument options you need.

kevster111’s picture

Sure this is possible, I don't think its even that difficult, Ill see if I can figure it out but it would be done in the same manner as the groups module and how it has a block that shows only posts by members of the group within the group itself. I believe a combination of relationships and arguments.

Online Batman fan site and Community http://www.batmantrailer.net

kevster111’s picture

Ok I got it and i did an example on a site I am doing. Check out http://www.batman-trailer.com/users/freeze

You will see he has done a review on something, the block on the right shows latest reviews.

Now check out http://www.batman-trailer.com/users/therookie
You will see a page that has the latest reviews block on the left with nothing under it at least if you check now, because that user hasn't done any reviews.

To do this make your view and add your block display with the fields and content and sort criteria just like you want.
Then add an argument -- user -- user id then under action to take if argument is not present click the provide default argument.
check user id from url ---- then you can check validator options --- user ---- Allow both numeric UIDs and string usernames ( I think you could leave it as basic validation but its nice to check for a name or a id.)

Then you save. Go to your block that you created and make it visible on only
user
user/*
users
users/*

Or provide another php argument.

If you don't want the block to show if there is nothing in it (like my example the reviews) Try messing with the empty text and show empty text if arg doesnt validate or something like that.

Or just add a empty text message saying this user hasnt added any reviews (or whatever).

Hope this helps.

Online Batman fan site and Community http://www.batmantrailer.net