根据用户的选择更改 Drupal 页面的背景图像...?
我试图为我的用户提供更改页面上使用的背景图像的功能。
背景图像列表的数量很少,不会真正改变。
我想我可以添加一些分类术语...每个背景类型一个...然后在查看页面时将一个类应用于正文标记。
这听起来可行吗?如果可行,我将如何去做?
谢谢萨姆
I'm trying to give my users the functionality to change what the background image used on a page is.
The list of background images will be a small number that won't really change.
I thought I could add a few Taxonomy terms...one for each background type...then apply a class to the body tag when the page is viewed.
Does this sound feasible and if so how would I go about doing it?
Thanks
Sam
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:澄清我对问题的误解后修改答案
如果要为每个(节点)页面定义背景图像,那么您通过分类词汇表的方法听起来是正确的方法。要使这些术语可用于 CSS,最简单的方法是将它们作为 node.tpl.php 文件中的类输出/使用,您可以在其中直接访问
$node
变量。但在这种情况下,它们在某种程度上被隐藏在生成的标记的中间,这使得正确使用它们有点困难。为了将它们添加到 page.tpl.php 中的
$body_classes
变量中,您还必须操作zen_preprocess_page()
函数来添加它们,或者(更好的方法)将它们添加到您自己的模块/主题preprocess_page()
函数中,以 zen 函数为例:注意:未经测试的代码,可能包含拼写错误和其他疏忽。
(编辑前的原始答案 - 基于对OP意图的误解,离开她以防其他人也误解它:)
基本想法听起来可行,但我建议稍作修改:
由于您希望每个用户都可以调整设置,因此您必须跳过一些环节才能允许用户使用分类术语“标记”自己。我认为启用(核心,但可选) 个人资料模块 会容易得多在那里配置一个“背景”字段(类型为“列表选择”)。该字段将显示在用户页面上(或者该页面上的单独选项卡,如果您给它一个类别),并且稍后可以很容易地从代码中获得用户选择,例如为页面模板派生一个类:
EDIT: revised answer after clarification of my misunderstanding of the question
If the background image is to be defined per (node) page, your approach via a taxonomy vocabulary sounds like the right way to go. To make the terms available for CSS, the easiest way would be to just output/use them as classes in the node.tpl.php file(s), where you have direct access to the
$node
variable. But in that case, they are somewhat buried in the middle of the resulting markup, which makes it a bit difficult to use them properly.In order to add them to the
$body_classes
variable in the page.tpl.php, you'd have to either manipulate thezen_preprocess_page()
function to add them as well, or (better approach) add them to your own modules/themespreprocess_page()
function, using the zen function as an example:NOTE: Untested code, might contain typos and other oversights.
(Original answer before edit - based on a misunderstanding of the OPs intent, left her in case other misunderstand it as well :)
The basic idea sounds feasible, but I'd suggest a minor variation:
Since you want the setting to be adjustable per user, you would have to jump through some hoops to allow users to 'tag' themselves with a taxonomy term. I think it would be far easier to just enable the (core, but optional) profile module and configure a 'background' field there (with type 'list selection'). The field will show up on the user page (or a separate tab on that page, if you give it a category), and the user selection will be available from code later on quite easily, e.g. to derive a class for the page template: