【问题标题】:Add a page to wordpress将页面添加到 wordpress
【发布时间】:2014-03-02 22:49:25
【问题描述】:

我目前正在构建自己的 WordPress 插件。所以我需要创建一个新页面(或帖子),当插件被激活时,它会自动添加到 wordpress 中。当插件时,这将被删除已停用。页面中的内容是我在插件中输入的内容。 我该怎么做?

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    您可以使用 wp_insert_post 函数创建页面或发布检查此http://codex.wordpress.org/Function_Reference/wp_insert_post

    例如

    // Create post object
    $my_post = array(
      'post_title'    => 'My post',
      'post_content'  => 'This is my post.',
      'post_status'   => 'publish',
      'post_author'   => 1,
      'post_category' => array(8,39)
    );
    
    // Insert the post into the database
    $post_id = wp_insert_post( $my_post);
    

    您可以在 add_post_meta 或 update_post_meta 中使用 $post_id 或使用 post_meta 变量来安装和卸载页面。

    【讨论】:

      【解决方案2】:

      类似this?链接的帖子中引用了一些用于处理页面创建的代码。还有codex

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-16
        • 2016-05-02
        • 2011-02-18
        • 2021-11-29
        • 1970-01-01
        相关资源
        最近更新 更多