Drupal: show content only to anonymous / authenticated users

tags: Drupal   php snippets  
drupal tags: users   contents  

Is very easy to show some contents to anonymous AND some other to authenticated users in Drupal. You'll only need to adapt the following few lines of php to output your content:

<?php
global $user;
if (!
$user->uid) { ?>

    <div>anonymous content here</div>
<?php } else { ?>
    <div>authenticated content here</div>
<?php } ?>

Yep, that easy.


Similar:

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <p> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h2> <h3> <h4> <img> <hr>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

Archives

February 2012
SunMonTueWedThuFriSat
1234
567891011
12131415161718
19202122232425
26272829
PureDivs Drupal Themes Conversions
PureDivs Conversione Temi Drupal