我有一个视图,有一个过滤器只能从2种内容类型中拉出结果。我希望每个视图条目都有一个显示节点内容类型的类。我该怎么做?
我有一个视图,有一个过滤器只能从2种内容类型中拉出结果。我希望每个视图条目都有一个显示节点内容类型的类。我该怎么做?
I have a view that has a filter to only pull results from 2 content types. I would like each views entry to have a class that shows the content type of the node. How can I do it?
您可以将其添加到该行的视图字段模板中,或者您可以将节点类型字段添加到视图中,并确保它是您要将类添加到的字段中的第一个或之前,并禁用其显示。然后,您可以转到要添加类型类的字段,选择重写输出,并使用本第一个字段的内容作为包装元素类中的替换值。
只是重新划伤,上面只需在行中包装一个字段。要将该类放入行的HTML中,可以编辑 views-view-fields.tpl.php
为您的特定视图,并在其中添加DIV包装器(将其删除提供给提供的$行变量)。保留在那里的节点类型字段,但没有显示它。
所以,例如,如果您的视图命名为foo,则可以在其中创建 views-view-fields--foo.tpl.php
:
<div class="<?php print $row->node_type; ?>"> <?php foreach ($fields as $id => $field): ?> <?php if (!empty($field->separator)): ?> <?php print $field->separator; ?> <?php endif; ?> <?php print $field->wrapper_prefix; ?> <?php print $field->label_html; ?> <?php print $field->content; ?> <?php print $field->wrapper_suffix; ?> <?php endforeach; ?> </div>
在哪里,如果我今天切割并粘贴,我唯一添加的是开幕者和关闭div。然后,在您自己的DIV中用一类Nodetype包装整个行。
您可以在视图样式信息区域中找到所有这些模板(确保您的视图代码匹配地址)。只需将它们保存在您的主题目录下。
加法:
如果要在 <div class="views-row views-row-2 views-row-even....">
中包含类,而不是添加另一个 99887664
内部,您可以将 views-view-unformatted.tpl.php
复制到一个适当命名的一个名为您的视图和抓取节点类型所需的信息在其中的 $view
变量中所需的信息。您还可以使用视图_preprocess()函数来执行它,虽然是这样的东西,但我喜欢在模板中看到它,但这只是我。该函数应该是 mythemeormodulename_preprocess_views_view_unformatted(&$vars)
,你可以添加或修改所需的任何var,因为它再次出现$ View,视图的所有信息也是如此。有关想法,请查看 sites/all/modules/views/theme/theme.inc,
中的视图代码,或者在您的计算机上存储了模块代码的位置。
You can add that into the views fields template for the row or you can add a node type field to your view, and make sure it's first or before the field you want to add the class to, and disable its display. Then, you can go to the field you want to add the type class to, select rewrite output, and use the contents of this first field as a replacement value in the class of the wrapper element.
Just rereading, the above just wraps a field in your row. To put that class in the row's html, you could edit up views-view-fields.tpl.php
for your specific view and add a div wrapper yourself with that information in it (grab it all out of the $row variable provided). Keep the node type field in there but have it not displayed.
So, for example, if your view is named foo, you could create a views-view-fields--foo.tpl.php
with this in it:
<div class="<?php print $row->node_type; ?>"> <?php foreach ($fields as $id => $field): ?> <?php if (!empty($field->separator)): ?> <?php print $field->separator; ?> <?php endif; ?> <?php print $field->wrapper_prefix; ?> <?php print $field->label_html; ?> <?php print $field->content; ?> <?php print $field->wrapper_suffix; ?> <?php endforeach; ?> </div>
where, if I am cutting and pasting right today, the only thing I've added is the opening div and closing div. This then wraps your whole row in your own div with class of nodetype.
You can find all of these templates in the views style information area (make sure your views code matches mine). Just save them in or under your theme directory.
ADDITION:
If you want to have the class in <div class="views-row views-row-2 views-row-even....">
instead of adding another <div class="....">
inside it, you can copy views-view-unformatted.tpl.php
to one appropriately named for your view and grab the information needed for the node-type out of the $view
variable there. You could also use a views_preprocess() function to do it, although for stuff like this I like seeing it in the template, but that's just me. The function should be mythemeormodulename_preprocess_views_view_unformatted(&$vars)
and you can add or modify any of the vars you want, once again, since $view is present, all the information about the view is as well. For ideas, check out the views code in sites/all/modules/views/theme/theme.inc,
or where ever module code is stored on your machine.
© 2022 it.wenda123.org All Rights Reserved. 问答之家 版权所有