Hello!

I have been trying to figure out what is the code to show a block ONLY in the pages of a blog of ONE concrete user. The idea is to use the block to put a picture and profile of the author of the blog, therefore is really needed to show it only in its pages. I kknow how to show it only in blogs, but the concrete user thing is killing me!

Thank you

Comments

kkinfy’s picture

Try if this one works:

1) Go to themes/ folder and copy block.tpl.php to block-block-.tpl.php. By this the new tpl file will affect only the block of your interest. The block id can be found by hovering the mouse over edit tab in the blocks page, when you could figure out the block id from the link that gets displayed in status bar.

2) Now in the new tpl file you could check the current user with the following code

    global $user;
    if($user->uid == "<the id you are going to check for>")
      {
             <show the block>....
       }
    
arh1’s picture

you can achieve this via the block's visibility settings, likely without any PHP.

assuming your URLs are like /blog/username and /blog/username/post-title , set the "Page specific visibility settings" to "Show on only the listed pages." then set the list of Pages to:
blog/username
blog/username/*

if your URLs are not that neat/predictable, then you can use PHP. here's something quick and dirty -- i'm sure there are more efficient ways to do it, and of course it'd need to be adjusted to your data. set the "Page specific visibility settings" to "Show if the following PHP code returns TRUE (PHP-mode, experts only)." then set the list of Pages to:

<?php
// the user ID you're checking for; you'll probably want to determine this programmatically...
$user_id = 60;
// the path for the user's blog list page; you'll probably want to determine this programmatically...
$user_blog_path = 'blog/'.$user_id;

if ($_REQUEST['q'] == $user_blog_path) {
  return true;
}
if (arg(0) == 'node' && is_numeric(arg(1))) {
  $node = node_load(arg(1));
  if ($node->uid == $user_id) {
    return true;
  }
}
?>
dresde’s picture

Thanks to both!

I understand that the first way will work for every user, and in the second way I have to configure the block for everysingle user, right?

I understand better the second way, I'm not a pro with php and it seems way easier, though I guess the first one is more "profesional". So at the momment I will go with the second way, but in order to improve:

What else do I need in the new block-block.tpl? I mean, it's only going to affect the picture block, so I can edit it with new DIVS to make it cool, but then in the block itself, what's the code to show only the user information?

kkinfy’s picture

Hi,

I meant to use block-block-your block id.tpl.php . For example if the block id is 5 then the new tpl would be block-block-5.tpl.php. This would affect only the block of your interest.

dresde’s picture

Ok, thanks, but then:

-1 block template with my design AND the code you gave me. But does will work only for the user ID I set there, and I have to put the picture in the block, right?

Davidking’s picture

Our career community is dedicated to helping Colchester Jobs Professionals like you, connect with local employers and find great career opportunities in the Bay Area. We even provide email alerts to inform you as soon as new opportunities become available and offer the latest information and resources to help you land a great job and advance in your career"

ribakker’s picture

The Context Module does exactly what you need, in a wink!