2

I am looking for a way to hide the "Submitted By: .... on ...." info on certain pages. I am aware that it can be removed from all pages of the 'Basic Page' or 'Article' type through the configuration settings, however I would like the info to appear on all pages unless I turn on a setting whilst creating/editing the page which hides it on that certain page. Does anyone know of a way to do this? Thanks,

1 Answer 1

1

You could add a checkbox field to the content type, and adjust the node.tpl file. If the box is not checked, don't print submitted by.

Add the field to all content types (sounds like thats what you asked for) and remove it from each display under "Manage Display".

Then, in template.php, implement template_preprocess_node:

mythemename_preprocess_node(&$variables) {
  $node = $variables['node'];

  // here we are creating a brand new variable
  // true, unless otherwise set by editors
  $variables['show_authoring'] = TRUE;

  // the field exists on the node object
  // update our custom variable to this field value
  if (isset($node->field_show_authoring)) {
    $variables['show_authoring'] = $node->field_show_authoring[LANGUAGE_NONE][0]['value'];
  }
}

If you want all nodes have this, you can copy in node.tpl.php to your theme or edit the one in your theme if it exists, and do:

<?php if ($display_submitted && $show_authoring): ?>
  <div class="submitted">
    <?php print $submitted; ?>
  </div>
<?php endif; ?>

You could remove $display_submitted if you wanted to, I left that there in case you wanted control in the future to completely disable showing authoring for certain content types, like Webform for example. My syntax should be correct but I did not have a chance to test this in a sandbox.

See more:

11
  • How would I go about doing that? Oct 1, 2016 at 13:11
  • You would add a Boolean field to the content type(s), then write some logic in the node.tpl file of your theme. If the value is FALSE, don't print submitted by. Editors can then check on or off show submitted by on a node by node basis.
    – Kevin
    Oct 1, 2016 at 14:11
  • Ok, I've set up the Boolean field (checkbox) on the content type. Now, what code would I use to control whether the Authoring info is shown depending on the value of the boolean? (Sorry, I have no clue when it comes to PHP) Oct 1, 2016 at 14:31
  • Basically, you are 'hooking in' to the node preprocess function, and adding a variable. This variable holds the truth value of the checkbox field, and then we add to the conditional that displays the submitted information in the template.
    – Kevin
    Oct 1, 2016 at 16:10
  • Thank you @Kevin. I will try this when I get home and let you know how I get on. Oct 1, 2016 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.