duanchuo7741 2010-07-21 07:01
浏览 62
已采纳

如果它已经不存在,如何以编程方式在WordPress中创建页面?

how do I programically create a page in WordPress if it doesn’t exist already?

  • 写回答

3条回答 默认 最新

  • dpxyfa4718 2010-07-21 12:19
    关注

    I want to write a plugin and to put some html controls in a page which will automatically create when user install the plug in

    Based on that comment, you want to hook a function to your plugin's activation hook, which inserts a WordPress post object into the database;

    function my_plugin_activate()
    {
        wp_insert_post(array(
            'post_type' => 'page',
            'post_title' => 'Page Title',
            'post_content' => 'Page Content',
            'post_name' => 'page-slug',
        ));
    }
    register_activation_hook(__FILE__, 'my_plugin_activate');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?