如何在wordpress中为自定义内容类型创建自定义表单?

时间:2010-07-20 09:47:34

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

有没有办法为特定内容类型创建表单并从站点本身提交表单。我在Wordpress中创建了2种内容类型,我想创建一个表单以发布到特定的内容类型。还可以在WordPress中将表单创建为页面吗?

问候 - dj

2 个答案:

答案 0 :(得分:1)

我使用以下方法来实现此目的:

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

关于dj

答案 1 :(得分:0)

您必须在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