wordpress: add custom meta-box to pages overview not only to posts/pages?

天涯浪子 提交于 2021-02-11 01:16:19

问题


I know how to add meta boxes to pages/posts/custom_post_type ($post_type) pages:

$screens = array( 'post', 'page' );

foreach ( $screens as $screen ) {

    add_meta_box(
        'myplugin_sectionid',
        __( 'My Post Section Title', 'myplugin_textdomain' ),
        'myplugin_meta_box_callback',
        $screen
    );
}

but how do i add a meta box to the pages-overview? i need a link-list there to some special pages ...

I know there are plugins who can do this: http://wordpress.org/plugins/meta-box/screenshots/ but only on posts/pages edit screen, like any tutorial i have found.


回答1:


You can add stuff to a column in that screen using the filter "manage_edit-{$cpt}_columns" and the action "manage_{$cpt}_posts_custom_column":

And it is possible to catch form submissions using:

add_action( 'load-edit.php',  'load_edit_so_23561386' );

function load_edit_so_23561386()
{
    global $typenow;
    $cpt = 'post';
    if( $typenow !== $cpt )
        return;

    if( isset( $_POST['YOUR-FORM'] ) )
        do_your_stuff();
}

But as there are multiple posts (virtually 999), it's much better to use AJAX, but that's a whole other story.



来源:https://stackoverflow.com/questions/23561386/wordpress-add-custom-meta-box-to-pages-overview-not-only-to-posts-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!