drupal 一些代码片段收集

论坛: 

显示一个views内容:<?php print views_embed_view('view_name', 'display_name'); ?>


可以输出打印cck字段节点在视图模板或php页面。可以帮助打印(选择列表)cck字段显示值,而不是键调用编程领域。

  1. $node = node_load($nid);
  2. echo field_view_value('node', $node, 'field_YOUR_FIELD', node->field_YOUR_FIELD['und'][0]);



在模板的template.php中添加以下代码
  1. /**
  2.  * Implements hook_html_head_alter().
  3.  *
  4.  * Removes the "Drupal 7" generator metatag.
  5.  */
  6. function YOURTHEME_html_head_alter(&$head_elements) {
  7. $key = 'system_meta_generator'; // If you aren't using the Metatag module.
  8. $key = 'metatag_generator'; // If you have the Metatag module enabled.
  9. unset($head_elements[$key]);
  10. }
dashan 答复于

  1. <?php
  2. $account = menu_get_object($type = 'user'); // first get the $account info from the current page
  3. $profiles = profile2_load_by_user($account->uid, $type_name = 'YOUR_PROFILE_NAME') ; // load the Profile 2 fields
  4. // note: YOUR_PROFILE_NAME can be set NULL to get all the profile types
  5.  
  6. print render($user_profile['YOUR_PROFILE_NAME']['view']['profile2'][$profiles->pid]['YOUR_PROFIEL2_FIELD_1']);
  7. print render($user_profile['YOUR_PROFILE_NAME']['view']['profile2'][$profiles->pid]['YOUR_PROFIEL2_FIELD_2']);
  8. print render($user_profile['YOUR_PROFILE_NAME']['view']['profile2'][$profiles->pid]['YOUR_PROFIEL2_FIELD_3']);
  9. print render($user_profile['YOUR_PROFILE_NAME']['view']['profile2'][$profiles->pid]['YOUR_PROFIEL2_FIELD_4']);
  10. ...
  11.  
  12. // you can put your own div and classes to this page to make your profile look nice.
  13. ?>
dashan 答复于

目标主题的头版
有时候,你不想让page-front.tpl.php只是小的风格变化。相反,你可以尝试在你的page.tpl.php中这样做:
if (drupal_is_front_page()) {
$class = "front";
} else {
$class = "";
}
print "<body class='".$class."'>";
这增加了一个css,你的body,所以现在在CSS中,你可以针对这样的东西:
#header {
background: blue;
}
.front #header {
background: lightBlue;
}
dashan 答复于

Currently there is two ways to do this. More standard way to do it is to add this line to your .info -file in theme.
scripts[] = name_of_script.js
This will automatically load name_of_script.js in your theme in all pages. To add more scripts, just create a new line just like before.
The other way to add it is to write this in your template.php:
function ThemeName_preprocess_html(&$variables) {
$options = array(
'group' => JS_THEME,
);
drupal_add_js(drupal_get_path('theme', 'ThemeName'). '/name_of_script.js', $options);
}
dashan 答复于

&lt;?php

$view = views_get_view('reviews_front');
$view-&gt;render();
$images = array();
$teasers = array()
foreach ($view-&gt;result as $result) {

$node = node_load($result-&gt;nid);
$images[] = $node-&gt;field_image[0]['view'];
$teasers[] = node_teaser($node-&gt;body);

}
echo '';
foreach ($images as $img) {
echo $img;
}
echo '';
//same way for teasers ...

?&gt;

dashan 答复于

<?php
$query = db_select('users', 'u');
    $query->fields('u', array('name'));
    $result = $query->execute();
    while($record = $result->fetchAssoc()) {
         print_r($record['name']);
    }
?>

dashan 答复于

<?php
print $feature_a;
?>

regions[ad_top]        = Ad Top
regions[ad_bottom]     = Ad Bottom
regions[front_sidebar] = Front Sidebar
regions[sidebar_ad]    = Sidebar Ad
regions[content]       = Content
regions[feature_a]     = Feature A
regions[feature_b]     = Feature B
regions[feature_c]     = Feature C
regions[feature_d]     = Feature D

node.tpl.php
page.tpl.php
page-node.tpl.php
comment.tpl.php
comment-node.tpl.php
comment-wrapper.tpl.php
comment-wrapper-forum.tpl.php
maintenance-page.tpl.php
search-result.tpl.php
search-theme-form.tpl.php
theme-settings.php
views-view.tpl.php
user-picture.tpl.php
user-profile.tpl.php

dashan 答复于