简体   繁体   English

Drupal:列出内容类型和内容计数

[英]Drupal: listing content types with content count

I'm new to Drupal. 我是Drupal的新手。

I have a couple of Content Types and some of them have a special field called Foo. 我有几种内容类型,其中一些有一个特殊的字段,称为Foo。 This field has value 1 for some Contents and 2 for others. 对于某些内容,此字段的值为1;对于其他内容,此字段的值为2。

I need to create a page that will list all the Content Types which have Contents with Foo equals 2. In this list, each item must be linked to 'some-page/$s', where $s is the Content Type. 我需要创建一个页面,列出所有具有Foo等于2的内容类型的内容类型。在此列表中,每个项目都必须链接到“ some-page / $ s”,其中$ s是内容类型。

Initially I thought about creating a module and writing raw SQL, but since I don't know te Drupal database structure yet, I decided to try a solution with Views. 最初,我考虑过创建模块并编写原始SQL,但是由于我还不了解Drupal数据库结构,因此我决定尝试使用Views解决方案。 I ended up with almost exactly what I need, but I can't create the link right, because the Content Type is being printed with underscores in the place of hiphens. 我最终获得的正是我所需要的,但是我无法正确创建链接,因为在Content Type上打印的是带有下划线的内容类型,而不是hiphens。

Any help? 有什么帮助吗? If you know a different solution (with no Views), please post it. 如果您知道其他解决方案(无视图),请发布它。

Thanks. 谢谢。

views is definitely the right path. 意见绝对是正确的道路。 you're probably better off with an exposed filter. 使用裸露的滤光片可能会更好。 you can also try the summary option in argument, that way you can see what arguments they are expecting (like somepage/blog-post). 您还可以尝试使用arguments中的summary选项,这样就可以查看他们期望的参数(例如somepage / blog-post)。 if it expects somepage/blog_post, but you need somepage/blog-post to work, try aliasing it with the core 'path' module. 如果它需要somepage / blog_post,但您需要somepage / blog-post才能工作,请尝试使用核心“路径”模块为它别名。

You make the url somepage/content_type but instead wants the url somepage/content-type . 您将网址somepage/content_type但要使用网址somepage/content-type

The solution to this problem depends a bit on what it is you want to do and why you want to have the - . 该问题的解决方案在某种程度上取决于您要执行的操作以及为什么要使用- Drupal has the path module (a part of drupal core) which will allow you to change the appearance of urls. Drupal具有路径模块(drupal核心的一部分),该模块将允许您更改url的外观。 So drupal can make the first url look like the last url. 因此drupal可以使第一个URL看起来像最后一个URL。 Now if you have already made this url, and want to map to it, I'm not sure what exactly would happen if you make use of path alias'. 现在,如果您已经创建了该URL,并且想要映射到该URL,那么我不确定如果您使用路径别名会发生什么。 It might fix the problem, but since Drupal internally knows the difference, you might not get to the page you want. 它可能会解决问题,但是由于Drupal内部知道差异,因此您可能无法进入所需的页面。

AFAIK the fact that you're limited to using underscores is due to restrictions placed on the naming of content types. AFAIK您只能使用下划线这一事实是由于内容类型命名受到限制。

As the solution you have goes a long way to solving your problem, it might be worth trying to create a path alias pointing from somepage/content_type to somepage/content-type using the pathauto module. 由于您所采用的解决方案可以解决您的问题,因此很值得尝试使用pathauto模块创建从somepage/content_type指向somepage somepage/content-type的路径别名。

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

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