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条)

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试