Community Documentation

Add a status message indicating if a node has not yet been published

Last updated October 18, 2011. Created by ugerhard on January 21, 2006.
Edited by MGParisi, SLIU, jhodgdon, Zen. Log in to edit this page.

Situation: When a node is not published, you have no visual indication that this is the case. So, frequently, while you are under the impression that the page/blog is fine, the rest of your users will be met with a "Page Not Found" or "Access Denied" page.

Solution: The following simple snippet adds a little banner only for unpublished nodes, stating that the node is yet to be published. This will not be visible during preview either.

Applies to: PHPTemplate themes only. 4.7.0 and possibly earlier.

File: node.tpl.php in your theme directory - The following block of code can be added right at the top if need be:

  <?php
   
//Check if status = 0 (not published) and the current page is not a preview page.
   
if (!$status && !$preview) {
     
//$type in the message below adds the type of node [blog/story etc.]
     
$status_message = '<div class="messages status">This '. $type .' node has not been published.</div>';
    }
    else {
     
//This is not an unpublished node -> no status message to display.
     
$status_message = '';
    }
 
?>

Now that we know what to print and when to print it, we just need the where ...

File: node.tpl.php [Same file as above] - The following line of code is best added directly above the line that prints the node content [ $content ]:

  <?php print $status_message; ?>

About this page

Drupal version
Drupal 4.7.x

Archive

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here