Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of module_invoke_all(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file in /home/.megatoes/geniusy/geniusy/drupal/modules/fuzzysearch/fuzzysearch.module on line 324
api | Geniusy's Blog

api

Drupal常用API函数列表

comment_num_all($nid):调用评论数,$nid为node的ID,当前node可用$node->nid。

taxonomy_get_tree($vid):显示分类(item),vid为category的ID,必须是category,不能是item,也就是说只能显示父层下面的item。

taxonomy_get_children($tid):显示Item下面的item,$tid为父item的id。

menu_get_menu():Return the menu data structure.不带参数,显示系统所有的menu。

menu_primary_links($start_level = 1, $pid = 0):pid可以指定起始层数,start_level貌似意思也差不多,还没实验过,有时间试试再说,下面是英文说明:
$start_level This optional parameter can be used to retrieve a context-sensitive array of links at $start_level levels deep into the Primary links menu. The default is to return the top-level links.

$pid The parent menu ID from which to search for children. Defaults to the menu_primary_menu setting.

menu_overview_tree:Present the menu tree, rendered along with links to edit menu items.

menu_get_item($mid, $path = NULL):Retrieves the menu item specified by $mid, or by $path if $mid is not given.

node_last_viewed:Retrieves the timestamp at which the current user last viewed the specified node.放在首页可以返回用户上次访问网站的时间。

referer_uri:Return the URI of the referring page.可以用来统计来源页面。

request_uri:Since $_SERVER['REQUEST_URI'] is only available on Apache, we generate an equivalent using other environment variables.任何服务器系统下面都可以使用。

sess_count($timestamp = 0, $anonymous = true):Counts how many users have sessions. Can count either anonymous sessions, authenticated sessions, or both.貌似可以分别统计在线会员与游客数了。可以通过指定$timestam来实现15分钟内在线人数效果。

statistics_title_list($dbfield, $dbrows):
Description

Returns all time or today top or last viewed node(s).

Parameters

$dbfield one of

Tags: api, drupal, function, 函数, 功能

Drupal如何调用文章阅读次数和评论次数

初次接触Drupal的新手可能会和我一样手足无措,本来很简单的功能都没办法实现。调用阅读数和评论数真是很简单的功能,如果使用其它CMS或者Blog CMS,这些一般都能从官方默认的模板或者使用帮助中找到,但是Drupal就不同了,什么都得靠自己摸索。

为了调用这两个变量我首先想到的是在数据库里面找,但是非常令我失望,drupal的node表里面根本没记录阅读次数,评论到是可以通过count一下comments表里面每个nid出现的次数得到,但是每次那样也未必烦琐了一点。

在DrupalChina里面提出了这个问题,第一个问题得到了解答:先要在后台,“管理”-“日志”-“访问记录设置”里面启用“页面访问计数”功能,然后就可以通过<?php
print $node->links['statistics_counter']['title']
?>语句调用node阅读次数了。

显示评论数是我自己摸索出来的,在api.drupal.org上面找到了三个函数,comment_num_all,comment_num_new和comment_num_replies,我只用了第一个,后面两个具体什么功能没用过,官方上也没说明。但我要的功能达到了,在需要显示评论数的地方加上<?php print comment_num_all($node->nid) ?>语句就OK了。

上次在api.drupal.org上还找到了一个显示分类的函数,我现在右边的分类就是用taxonomy_get_tree($vid)和taxonomy_get_children($vid)来获取分类(category或者taxonemy),这样就可以不需要自己写SQL语句了,其实这些函数就是由一些SQL语句组成的。有空的时候可以多到api网站上转转,上面可以找到很多好用的函数的。

Tags: api, comment_num_all, drupal, node, statistics_counter, taxonomy_get_tree, 文章, 次数, 评论数, 调用, 阅读