简体   繁体   English

将分类术语列表添加到主页Drupal 8

[英]Add taxonomy terms list to homepage Drupal 8

Please help me to add taxonomy terms from custom taxonomy into home page. 请帮助我将分类术语从自定义分类添加到主页中。 I have no idea how to do this as I'm coming from WordPress. 我不知道该怎么做,因为我来自WordPress。 In WordPress it is easy as calling get_terms(). 在WordPress中,调用get_terms()很容易。 I have following file as my home page: mytheme/templates/page--front.html.twig 我将以下文件作为主页: mytheme/templates/page--front.html.twig

I have more than one taxonomy type and all of them are going to queried in the home page. 我有一个以上的分类法类型,所有这些都将在主页中查询。

How to query the taxonomy terms? 如何查询分类术语?

UPDATE: 更新:

I have created a new region called home_content in my theme.info.yml and I have created a view(block) for getting the taxonomy terms, added it to region in back-end and display it as {{page.home_content}} . 我在theme.info.yml创建了一个名为home_content的新区域,并创建了一个用于获取分类法术语的视图(块),将其添加到后端的区域中并显示为{{page.home_content}} It works but I have few questions. 它有效,但是我有几个问题。

  1. I have fields for logo and text in the taxonomy. 我在分类法中有用于徽标和文本的字段。 I want to list them too. 我也想列出他们。

  2. I need to customize the html. 我需要自定义html。 How can I do that? 我怎样才能做到这一点?

Thanks for the support. 感谢您的支持。

You don't really need to code anything 您真的不需要编写任何代码

  1. Create view with taxonomy terms required. 使用所需的分类术语创建视图。 Structure > Views > Create New View and add block view for taxonomy terms. Structure > Views > Create New View并添加分类视图术语的块视图。 User filter section to select specific terms or dictionaries. 用户filter部分以选择特定的术语或词典。 Save the view. 保存视图。
  2. Go to Structure > Block Layout and insert block with your view into desired region. 转到“ Structure > Block Layout然后将带有视图的块插入所需区域。 In visibility section, pages tab: type <front> in pages and select Show for the listed pages in order to display it on home page only. 在“ visibility部分的“ pages选项卡中:在页面中键入<front> ,然后Show for the listed pages选择“ Show for the listed pages ,以便仅在主页上显示它。

Above steps will display your required terms on home page. 以上步骤将在首页上显示您所需的条款。

To copy and modify template(s) in your theme, follow the instructions on drupal.org: https://www.drupal.org/node/2358785 要复制和修改主题中的模板,请按照drupal.org上的说明进行操作: https : //www.drupal.org/node/2358785

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM