【问题标题】:How to create custom forms for custom content type in wordpress?如何在 wordpress 中为自定义内容类型创建自定义表单?
【发布时间】:2010-07-20 09:47:33
【问题描述】:

有什么方法可以为特定内容类型创建表单并从网站本身提交。我在我的 Wordpress 中创建了 2 种内容类型,我想创建一个表单来发布到特定的内容类型。也可以在wordpress中将表单创建为页面吗?

问候 - DJ

【问题讨论】:

  • 您能否给我们一些您所描述的“内容类型”的示例...
  • 在 wordpress 中有几种类型,如“帖子”、“页面”等。在 wordpress 3.0 中,它们支持自定义内容类型。我希望这能说清楚!

标签: php wordpress forms content-management-system content-type


【解决方案1】:

我使用了以下方法来实现:

我已使用简码功能在网站中创建表单。在这里你可以看到添加shortcodes的文档。提交页面也是一个带有简码的“页面”。所以我收集了简码函数中的值,并使用 wp_insert_post 函数将内容添加到 wp_posts 表中。您可以查看有关 wp_insert_post() here 的文档。我希望这会有所帮助:)

问候 DJ

【讨论】:

    【解决方案2】:

    您必须向您的functions.php 文件添加一个函数。像这样的例子:

    add_action(‘init’, ‘mycustomcontent_init’);     //enable custom content types
    
    function mycustomcontent_init() {
        // create content type Crafts
        $args = array(
            ‘label’ => __(‘Crafts’),      //content type name to be displayed in the wordpress dashboard
            ‘singular_label’ => __(‘Crafts’),      //content type name to be displayed in the wordpress dashboard
            ‘public’ => true,
            ‘show_ui’ => true,      // show the user interface for this content type? true=yes false=no
            ‘_builtin’ => false,      //declartion to the system that it’s a custom content type and not a built in content type
            ‘_edit_link’ => ‘post.php?post=%d’,
            ‘capability_type’ => ‘post’,     //set the content type features, here we setting it to the features of a standard post
            ‘hierarchical’ => false,
            ‘rewrite’ => array(“slug” => “crafts”),     //prefix to the url alias for this content type, eg: mysite.org/crafts/model-ships
            ‘supports’ => array(‘title’, ‘editor’, ‘thumbnail’)
        );
        register_post_type( ‘crafts’ , $args );
    }
    

    取自here

    另外,阅读Wordpress Documentation for Custom Post Types

    【讨论】:

    • 感谢您的回复。但是我已经创建了内容类型,我想在网站中创建一个表单来将内容发布到特定的内容类型。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-06
    • 1970-01-01
    • 2015-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多