从页面操作创建WordPress子页面

时间:2011-09-21 作者:Shae

我正在尝试添加一个选项,从wordpress所有页面屏幕创建子页面。我找到了此链接,但无法使其正常工作。这正是我需要的,但我需要帮助修复它

http://sltaylor.co.uk/blog/easy-child-page-creation-wordpress/

function slt_childPageAction( $actions, $page ) {  
    $actions["create-child"] = \'<a href="/wp-admin/post-new.php?post_type=page&amp;parent_id=\' . $page->ID . \'" title="Create a new page with this page as its parent">Create child</a>\';  
    return $actions;  
}  
add_filter( \'page_row_actions\', \'slt_childPageAction\', 10, 2 );  
function slt_setChildPage() {  
    global $post;  
    if ( $post->post_type == "page" && $post->post_parent == 0 && isset( $_GET["parent_id"] ) && is_numeric( $_GET["parent_id"] ) )  
        echo \'<script type="text/javascript">jQuery( document ).ready( function($) { $("#parent_id").val("\' . $_GET["parent_id"] . \'"); } );</script>\';  
}  
add_action( \'edit_page_form\', \'slt_setChildPage\' );  

1 个回复
最合适的回答,由SO网友:onetrickpony 整理而成

如果您是指404错误:

function slt_childPageAction( $actions, $page ) {
    $actions["create-child"] = \'<a href="\'.add_query_arg(array(\'post_type\' => \'page\', \'parent_id\' => $page->ID), admin_url(\'post-new.php\')).\'" title="Create a new page with this page as its parent">Create child</a>\';
    return $actions;
}
add_filter( \'page_row_actions\', \'slt_childPageAction\', 10, 2 );
function slt_setChildPage() {
    global $post;
    if ( $post->post_type === \'page\' && $post->post_parent === 0 && isset( $_GET["parent_id"] ) )
        echo \'<script type="text/javascript">jQuery( document ).ready( function($) { $("#parent_id").val("\' . (int)$_GET["parent_id"] . \'"); } );</script>\';
}
add_action( \'edit_page_form\', \'slt_setChildPage\' );
(指向/wp admin/的url路径已硬编码)

很好的发现顺便说一句:)

结束

相关推荐