【问题标题】:How to list CCK fields by content type in Drupal如何在 Drupal 中按内容类型列出 CCK 字段
【发布时间】:2010-06-07 18:35:27
【问题描述】:

要获取内容类型的 cck 字段列表,我希望使用:

drupal_get_schema('content_type_mycontenttype');

但这会忽略具有多个值的字段。是否有一个简单的调用来获取这样的列表?

【问题讨论】:

    标签: drupal drupal-6 cck


    【解决方案1】:

    看看content_fields函数,如果没有你需要的信息,有_content_type_info

    另外,一旦你有了字段信息,你就可以使用content_database_info提取表存储和列名。

    【讨论】:

      【解决方案2】:

      对于 Drupal 7,查看 field_info_instances 函数以检索特定节点内容类型的字段列表。

      这是一个示例用法,它将检索节点内容类型的所有字段。

      $my_content_type_fields = field_info_instances("node", "my_node_content_type");

      【讨论】:

        【解决方案3】:

        我以前使用过类似的方法来快速列出内容类型的 CCK 字段信息:

            $mytype = 'article';
            $contentinfo = _content_type_info();
            $output .= "<ul>";
            foreach($contentinfo['fields'] as $field) {
                if ($field['type_name'] == $mytype) {
                    $output .= '<li id="field-' . $field['field_name'] . '">' . $field['widget']['label'] . '<br>';
        
                    if ($field['widget']['description']) {
                        $output .= $field['widget']['description'] . '<br>';
                    }    
        
                    $output .= '<ul>
                            <li>Content Types: ' . $field['type_name'] . '</li>
                            <li>Type: ' . $field['type'] . '</li>
                            <li>' . $field['field_name'] . '</li>
                        </ul>';
                }
            }
            $output .= '</ul>';
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-09-22
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多