如何使WordPress主题附带页面?

时间:2015-07-29 18:16:40

标签: php wordpress wordpress-theming

我正在开发一个WordPress主题,它会有几页。更具体地说,我想要的是在我的functions.php代码中加入相同的代码,就像我进入GUI的Pages部分并创建一个新页面 Some Page 一样永久链接http://mywebsite.com/somepage.php。我不知道如何做到这一点,因为其API的WordPress文档对于查找如何执行此操作并不是很有帮助。但根据我到目前为止使用WordPress API的经验,我猜测有类似

的东西
add_page('Some Page', 'generate_some_page', 'http://mywebsite.com/somepage.php'); 

function generate_some_page ( ) 
{
    /* 
     echo the HTML that will go inside the <div id="content"> in the layout
        <?php get_header(); ?>
        <div id="main">
            <div id="content">
               <!--  ... -->
            </div>
        </div>
         <?php get_footer(); ?>
    */
} 

你知道我正在寻找什么样的WP API吗?或者我可以阅读相关文档的任何链接?

1 个答案:

答案 0 :(得分:1)

查看 wp_insert_post

https://codex.wordpress.org/Function_Reference/wp_insert_post

$page_data = array(
    'post_name'         => 'my-page-name',
    'post_title'        => 'My Page Name',
    'post_content'      => 'This is the content of my page.',
    'post_excerpt'      => 'This is the excerpt of my page.'
);
$page_id = wp_insert_post( $page_data );
相关问题