How to show teaser but hide full article from anonymous users Drupal

Posted 20 March 2010 in the web-design category

Below code tested with Drupal 5, not sure if it works on Drupal 6, please let me know if you try it!

Just replace your $content variable with the code below, which is in your node.tpl.php file located in your themes folder. Apologies if anyone finds fault with the below, it works, and I couldn’t find any code on the internet for it, being not a programmer it could be a little ugly, but it does work ;)

<?php if ($teaser): ?>

<?php
global $user;
// if visitor is not logged in
if (!$user->uid) {
// print the teaser
print $content;
} else {
// if user is logged in print the teaser
print $content;
}
?>

<?php elseif (!$teaser): ?>

<?php
global $user;
// if anonymous visitor and content type is all except blog or page
if (!$user->uid && $node->type != 'blog' && $node->type != 'page') {
// lock anonymous visitors out of the full article
print("<div class='messages'>Please <a href='/user/register'>register</a> or <a href='/user'>login</a> to view images!</div>");
} else {
// show all content for all content types to logged in users
print $content;
}
?>

<?php endif;?>

Done!

Add to social bookmarks: del.icio.us | Tweet this: |


Leave a Comment!
















Just click preview first, then submit after image verification and your comment will appear instantly!