Community Documentation

Quick 'edit' link of the nodes

Last updated May 10, 2011. Created by ica on October 8, 2006.
Edited by JmsCrk, Heine, ronald_istos. Log in to edit this page.

Just to give a 'quick edit' link to each and current node on pages with excerpt
edit link next to the '$links' read more' as alternative to the going to the actual node to get edit tab.. saves editors 2 links&load!
for Drupal 4.7.x and 5.x
on node.tpl.php replace

   <?php if ($links): ?>
      <div class="links"><?php print $links; ?></div>
    <?php endif; ?>

with

   <?php if (user_access('administer nodes')): ?>
      <a href="/?q=node/<?php print $node->nid; ?>/edit" title="Edit">edit</a>
   <?php endif; ?>

Comments

Not overwriting existing links, and using l() and $nid

<?php if ($links): ?>
  <div class="links"><?php print $links; ?></div>
<?php endif; ?>

<?php if (user_access('administer nodes')): ?>
  <div><?php print l('Edit', 'node/' . $nid . '/edit'); ?></div>
<?php endif; ?>

PS: we should try as much as possible to not rely on the $node object.

If you do not want any additional db_query, and the only person who'll be able to edit is User 1, use this:

<?php if ($links): ?>
  <div class="links"><?php print $links; ?></div>
<?php endif; ?>

<?php global $user; if ($user->uid == 1): ?>
  <div><?php print l('Edit', 'node/' . $nid . '/edit'); ?></div>
<?php endif; ?>

Not Annonymous?

Another handy code snippet: only print the edit link if the user is logged in.

<?php global $user; if ($user->uid != 0): ?>
  <div><?php print l('Edit', 'node/' . $nid . '/edit'); ?></div>
<?php endif; ?>

New little module that

New little module that doesn't require any file hacking: http://drupal.org/project/admin_links

Redirect back to original page

After you save a node, it takes you to view the node by default. Instead you can redirect after submit by using drupal_get_destination().

Example in Drupal 6:

<?php if (user_access('administer nodes')): ?>
   <div><?php print l('Edit', 'node/' . $nid . '/edit', array('query' => drupal_get_destination())); ?></div>
<?php endif; ?>

—Matt

About this page

Drupal version
Drupal 4.7.x, Drupal 5.x, Drupal 6.x
Audience
Developers and coders, Site administrators, Themers

Theming Guide

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