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; ?>
Caroline
11 heavens.com
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
Senior Drupal Engineer for Palantir.net | www.davereid.net | certifiedtorock.com/u/53892
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