Drupal 7-如何为首页制作自定义模块?
所以..我在我的主题目录中创建了 page--front.tpl.php 并且它工作正常。
现在,我如何制作一个可以在页面中使用的变量--front.tpl.php?
我可以在 page--front.tpl.php 中编写我的 php 代码,但我认为有更好的方法。
补充:
在首页上,我将仅查询视频和新闻节点。这就是为什么我想为首页制作一个新模块。
有什么建议吗?
so..I created page--front.tpl.php in my theme directory and it works fine.
now, how do I make a variable that can be used in the page--front.tpl.php?
I can write my php codes inside page--front.tpl.php, but I think there is a better way.
added:
on the front page, I am going to query video and news nodes ONLY. That is why I want to make a new module for only front page.
any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定你想在这里实现什么,但是好吧。你有两个选择:一是你现在正在做的事情。在
page--front.tpl.php
中编写您的自定义 PHP,就可以了。另一种是放弃该文件并仅使用page.tpl.php
。变量
$is_front
告诉您是否位于首页。您可以在条件块中编写自定义 PHP:if ($is_front) { ... }
。此外,您可以创建一个自定义块(可能是一个视图,具体取决于您的需要)并将其显示限制设置为“仅在列出的页面上” - 并在那里列出。您将仅在首页上加载自定义视图。
I'm not sure what you are trying to achieve here, but OK. You have two options: one is what you're doing now. Write your custom PHP in
page--front.tpl.php
and you'll be fine. The other is ditching the file and working only withpage.tpl.php
.The variable
$is_front
tells you whether you're on the front page. You can write custom PHP in a conditional block:if ($is_front) { ... }
.Also, you can create a custom block (a view, perhaps, depending on your needs) and set its display restrictions to "only on the listed pages" - and list there. You'll have a custom view loaded only on the front page.
拥有自定义首页所需要做的就是在站点信息设置(D6 中的 admin/settings/site-information)中配置您的首页。
创建一个模块来显示该内容是完全不同的事情。
我真正建议的是查看视图(如果您不知道的话)已经。这允许您构建事物列表(节点、用户……)并将它们公开为页面、块、RSS 提要等等。您可以创建视频和新闻类型的节点列表,将其公开为页面,然后将首页指向视图的路径。
All you need to do have a custom front page is configure your front page in the site information settins (admin/settings/site-information in D6).
Creating a module to display that content is then a completely different thing.
What I would really suggest is looking at Views if you don't know it already. That allows you to build lists of things (nodes, users, ...) and expose them as pages, blocks, rss feeds and much more. You can create a list of nodes with types video and news, expose that as a page and then just point your front page to the path of your view.
您可以尝试使用视图模块来创建视频和节点列表。您可以在站点设置中将视图页面设置为主页。
you might try using the views module to create your list of videos and nodes. You can set a views page to be your homepage in the site settings.