As the site administrator, when I create content for the main page I do not want my user name and the date I created that content to appear. I tried removing the code from the node.php file, but it takes an all or nothing approach (either everyone has that information posted, or no one does). I also tried to alter the theme code to read:

 <?php if ($display_submitted): ?>
  <?php if ($name != "myusername"): ?>
    <span class="submitted"><?php print $date; ?> - <?php print $name; ?></span>
  <?php endif; ?>
  <?php endif; ?>

hoping that if it identified my user name as being equal to the $name variable it would not print anything under it. This did not work because for some reason it always registers $name as not being equal to my user name and prints my name and the date anyway. I want it to print the date and user name for all other users. Any ideas out there?

Comments

nevets’s picture

I would add this to my themes template.php file (or create a module)

function YOURTHEMENAME_preprocess_node(&$variables) {
  $uid = $variables['uid'];
  if ( $uid == YOUR_USER_ID ) {
     $variables['display_submitted'] = FALSE;
  }
}

Changing YOURTHEMENAME to your themes actual name and YOUR_USER_ID to the numeric user id for your account.

(You if probably fails because $name is themed and is not simply your user name).

m_i_c_h_a_e_l’s picture

Why not create a new content-type (story-admin), and set your theme to not display the submitted by line for that content type. Only you would use that type. And whenever you want the line to appear, just use the standard story type.

No code necessary.

15dk51’s picture

In your code use $user->name instead of $name. $name does not contain user name. Object $user contains the user name.

 <?php if ($display_submitted): ?>
  <?php if ($user->name != "myusername"): ?>
    <span class="submitted"><?php print $date; ?> - <?php print $name; ?></span>
  <?php endif; ?>
  <?php endif; ?>
sagar ramgade’s picture

Hi,
You can try any of the below codes :
First method :
You active theme's Node.tpl.php

<?php if ($display_submitted): ?>
  <?php global $user ; 
      $userids = array(2, 3, 4, 5); // uids of users for which you want to hide it
      if(in_array($user->name, $userids): ?>
    <span class="submitted"><?php print $submitted; ?></span>
  <?php endif; ?>
  <?php endif; ?>

Second Method :
In you are active theme's template .php :

function YOURTHEMENAME_preprocess_node(&$variables) {
  global $user;
  $userids = array(2, 3, 4, 5);
  if (in_array($user->uid, $userids)) {
     $variables['display_submitted'] = FALSE;
  }
}

Hope this helps.

Regards
Sagar

Acquia certified Developer, Back end and Front specialist
Need help? Please use my contact form

Peng.Pif’s picture

Hello All,

I've been searching for some time and am unable to find a way to hide the submitted by information based on user roles.

I would only like to show the submitted by information to authenticated users. Can someone please help me modify the above code?

Many thanks in advance!

nevets’s picture

Using the second method above you can use

function YOURTHEMENAME_preprocess_node(&$variables) {

  if ( !user_is_logged_in() )  {
     $variables['display_submitted'] = FALSE;
  }
}

Remember to replace YOURTHEMENAME with your actual themes name. If using an existing theme it may already have the function in which case you would add the code in the example to the existing function.

[EDIT: fix call to user_logged_in()]

Peng.Pif’s picture

Thanks for your help nevets, unfortunatley I am receiving the following error:

Parse error: syntax error, unexpected T_STRING in C:\wamp\www\test\sites\all\themes\fusion\fusion_starter\template.php on line 5

I have created a new template file in my sub theme (fusion starter) and am using the following:


<?php
function fusion_starter_preprocess_node(&$variables) {

  if (!call user_is_logged_in())  {
     $variables['display_submitted'] = FALSE;
  }
}

Also, would it be possible to provide a snippet that lets me select which roles that the post information should be visible to?

Many thanks for you help!

nevets’s picture

Fixed my earlier post (the 'call' should not be there). As for "lets me select which roles that the post information should be visible to" the original snippet with one small change (a '!' before in_array()) will work

function YOURTHEMENAME_preprocess_node(&$variables) {
  global $user;
  // List of user roles we want to able to see the submitted information from
  $userids = array(2, 3, 4, 5);
  if (!in_array($user->uid, $userids)) {
     $variables['display_submitted'] = FALSE;
  }
}
Peng.Pif’s picture

Thanks so much nevets! That worked perfectly.

I had to make one minor change, using the Fusion theme. I had to replace 'display_submitted' with 'submitted' in order for it to work.