包含 1 个以上内容项的内容块
以下代码是用 php 制作的 Drupal 块。
1)我如何实现多个项目?现在我有 test1,但我想要 test1、test2、test3 和 test5。
2)我如何将标题(例如 test1)链接到我的管理/设置/菜单?我想将一个项目链接到 Drupal 中的 node_import。
function planning_block($op='list', $delta=0, $edit=array()) {
switch ($op) {
case 'list':
$blocks[0]['info'] = t('Stage administration block');
return $blocks;
case 'view':
$blocks['subject'] = t('Stage administratie');
$blocks['content'] = 'test';
return $blocks;
}
}
The following code is a Drupal block made in php.
1) How can I implement more then one item? now i have test1 but i want test1, test2, test3 and test5.
2) how can i link a title for example test1 to my admin/settings/ menu? I want to link an item to node_import in Drupal.
function planning_block($op='list', $delta=0, $edit=array()) {
switch ($op) {
case 'list':
$blocks[0]['info'] = t('Stage administration block');
return $blocks;
case 'view':
$blocks['subject'] = t('Stage administratie');
$blocks['content'] = 'test';
return $blocks;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您参考 hook_block 的文档< /a>,你可以在一个钩子内声明多个块。
$delta 参数可以帮助您区分正在渲染的块。
关于标题中的链接,只需在设置 $block['subject'] 值时使用 l() 函数即可。
例子:
If you refer to the documentation of hook_block, you can declare several block inside one hook.
The $delta argument is here to help you differenciate which block your are rendering.
About your links in the title, just use the l() function when you are setting the $block['subject'] value.
Example:
您可以创建多个块,如 Artusamak 的答案所示,或者如果您希望将更多内容添加到单个块中,也可以简单地将更多内容添加到 $blocks['content'] 中。
请注意,如果您只需要固定链接的列表,可以通过创建菜单并向其添加链接来实现。每个菜单都会自动显示为一个块。无需自定义代码。
You can either create multiple blocks as shown in Artusamak's answer, or you can simply add more content to $blocks['content'] if you want it in a single block.
Note, if you just want a list of fixed links, you can do that by creating a menu and adding links to it. Every menu is automatically exposed as a block. No custom code required.