Organic Groups首页节点的drupal主题化(代码)

 

<?php
  if (arg(0) == 'node' && is_numeric(arg(1))) {
    $url_alias = drupal_get_path_alias('node/'.arg(1));
  } elseif (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
    $url_alias = drupal_get_path_alias('taxonomy/term/'.arg(2));
  }

  // We need to only take the first argument of the aliased path, so define the separator
  $slash = '/';

  // find out if the separator exists in the returned alias
  $pos = strpos($url_alias, $slash);

  // if the separator is not present, then just look at the URL alias; if it is present, strip the first argument only
  if ($pos === false) {
  $string = $url_alias;
  } else {
  $string = substr($url_alias, 0, $pos);
  }
 
  // if the first argument of the aliased path == 'groups', then we know it's a group home page
  if ($string == 'groups'){ ?>

 

接下来,我们将格式化小组首页面的节点。在这里,我仅需要一个带有链接的标题,以及作者,发表日期,所以代码如下:

<?php if ($page == 0) { ?>
      <div class="content"><a href="<?php print $node_url; ?>"><?php print $title?></a><span class="submitted"><?php print " ".$user_name. " " . $date; ?></span></div>
    <?php }; ?>

 

 

接下来,如果别名不是'groups'的话,我将提供一个普通的teaser视图(view):

<?php
  // if the first argument of the aliased path wasn't 'groups', then it's a normal teaser view
  }else{ ?>
    <div class="node<?php if ($sticky) { print " sticky"; } ?><?php if (!$status) { print " node-unpublished"; } ?>">
    <?php if ($picture) { print $picture; }?>
    <?php if ($page == 0) { ?>
      <h2 class="title"><a href="<?php print $node_url; ?>"><?php print $title?></a></h2>
    <?php }; ?>
    <span class="submitted"><?php print $submitted?></span> <span class="taxonomy"><?php print $terms?></span>
    <div class="content"><?php print $content?></div>
    <div class="clr">
    <?php if ($links): ?>
      <div class="links"><?php print $links; ?></div>
    <?php endif; ?>
    </div>
    </div>
  <?php } ?>

 

 

接着,让我们添加独立的节点视图(view),从而完成我们的node.tpl.php文件。

 

下面是完整的可用的代码

(你可以根据需要自己定制外观):

<?php if ($teaser): ?>

  <?php
  // we just get the drupal path args so that we can look up the path alias
  if (arg(0) == 'node' && is_numeric(arg(1))) {
    $url_alias = drupal_get_path_alias('node/'.arg(1));
  } elseif (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
    $url_alias = drupal_get_path_alias('taxonomy/term/'.arg(2));
  }

  // We need to only take the first argument of the aliased path, so define the separator
  $slash = '/';

  // find out if the separator exists in the returned alias
  $pos = strpos($url_alias, $slash);

  // if the separator is not present, then just look at the URL alias; if it is present, strip the first argument only
  if ($pos === false) {
  $string = $url_alias;
  } else {
  $string = substr($url_alias, 0, $pos);
  }
 
  // if the first argument of the aliased path == 'groups', then we know it's a group home page
  if ($string == 'groups'){
  // below this is where you need to put your node formatting for the og home page ?>

    <?php if ($page == 0) { ?>
      <div class="content"><a href="<?php print $node_url; ?>"><?php print $title?></a><span class="submitted"><?php print " ".$user_name. " " . $date; ?></span></div>
    <?php }; ?>
 
  <?php
  // if the first argument of the aliased path wasn't 'groups', then it's a normal teaser view
  }else{
  // below this is where you need to put your normal node teaser formatting ?>
    <div class="node<?php if ($sticky) { print " sticky"; } ?><?php if (!$status) { print " node-unpublished"; } ?>">
    <?php if ($picture) { print $picture; }?>
    <?php if ($page == 0) { ?>
      <h2 class="title"><a href="<?php print $node_url; ?>"><?php print $title?></a></h2>
    <?php }; ?>
    <span class="submitted"><?php print $submitted?></span> <span class="taxonomy"><?php print $terms?></span>
    <div class="content"><?php print $content?></div>
    <div class="clr">
    <?php if ($links): ?>
      <div class="links"><?php print $links; ?></div>
    <?php endif; ?>
    </div>
    </div>
  <?php } ?>

<?php else:
// here is where your full node formatting goes ?>

<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?> clear-block">

<?php print $picture ?>

<?php if ($page == 0): ?>
  <h2><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>
<?php endif; ?>

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

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

  <div class="content">
    <?php print $content ?>
  </div>

<?php
  if ($links) {
    print $links;
  }
?>

</div>

<?php endif; ?>

Hopefully that will help save somebody time.

希望本文对读者能有所帮助。

 相关联接:http://drupal.org/node/293906Think in Drupal

 

Drupal版本: