1

有没有可能我可以从编辑标签页面中引入"Archive Headline""Archive Intro Text"进入。"Quick Edit" (inline-edit)

我没有尝试创建新的自定义输入或文本区域字段

我只是在谈论是否有任何机会或方式可以使用编辑页面选项"Quick Edit"。我已经阅读了很多教程,manage_posts_custom_column quick_edit_custom_box但他们并没有告诉我可以做到这一点。

正如我告诉你的,我试图在快速编辑标签上添加字段,所以帖子类型是post_tag.

在此处输入图像描述

这就是我想要做的。

在此处输入图像描述

4

1 回答 1

1

是的,你可以这样做。

WP 表的工作方式 - 有一个类 'WP_List_Table' ( /wp-admin/includes/class-wp-list-table.php) 用作所有表(帖子、类别、用户、媒体等)的基础,然后为其创建扩展器以制作这些表. 在class-wp-terms-list-table.php,在inline_edit()函数中,有一个action你需要挂钩的。

第 356+ 行读取 -

foreach ( $columns as $column_name => $column_display_name ) {
    if ( isset( $core_columns[$column_name] ) )
        continue;

    do_action( 'quick_edit_custom_box', $column_name, 'edit-tags', $tax->name );
}

这样做的好处是,如果您愿意,您可以为您的自定义内容创建看起来像 WP 标准表格的表格。这对于插件开发人员或网站管理员特别有用,因为用户不是那么先进并且只使用一种表格格式感到“舒适”。

要将框添加到快速编辑中,您需要如下所示。顶部的三个变量需要更改为您自己的设置,您应该在将字段添加到“编辑”分类屏幕时定义这些设置 -

/**
 * Adds columns to quick edit
 *
 * @param $column_name string The name of the column that is currently being actioned
 * @param $screen string The screen that is currently being viewed
 * @param $tax string The name of the Taxonomy whose Terms are being listed
 * @return string Current value of the sort_order setting
 */
function my_custom_box( $column_name, $screen, $name ) {

    $my_fields = array(
        array(
            'column_name' => 'archive_headline',
            'field_title' => 'Archive Headline',
            'field_name' => 'archive_headline',
        ),
        array(
            'column_name' => 'archive_intro_text',
            'field_title' => 'Archive Intro Text',
            'field_name' => 'archive_intro_text',
        )
    );

    foreach ($my_fields as $field) :

        if ( $column_name === $field['column_name'] && $screen === 'edit-tags' ) :

            print( '<fieldset><div class="inline-edit-col">' );
            print( '<label>' );
            printf( '<span class="title">%1$s</span>', _e( $field['field_title'] ) );
            printf( '<span class="input-text-wrap"><input type="text" name="%1$s" class="ptitle" value=""></span>', $field['field_name'] );
            print( '</label>' );
            print( '</div></fieldset>' );

        endif;

    endforeach;

}
add_action( 'quick_edit_custom_box', 'my_custom_box', 10, 3 );

编辑

您已经提到您希望这些值位于表的“快速编辑”部分中,而不是表本身。这是可能的,但您必须隐藏数据。由于快速编辑部分是通过 AJAX 使用表格中的数据填充的,因此它必须存在。

您可以使用下面的代码添加列(您应该只需要修改实际获取数据的位,因为我不知道它来自哪里)。

/**
 * Add custom data to tables with a low priority, so that post types and taxonomies have already been added
 */
add_action('init', 'add_custom_columns', 110, 0);
function add_custom_columns(){

    $taxonomy = 'post_tag';

    /** Add the column */
    add_filter("manage_edit-{$taxonomy}_columns", 'show_custom_tag_columns', 5);

    /** Populate the column */
    add_action("manage_{$taxonomy}_custom_column", 'fill_custom_tag_columns_by_return', 5, 3);

}

/**
 * Shows custom columns and removes built-in ones based on the page being shown
 *
 * @param required array $columns The current columns for the table
 * @return array $columns The updated columns array
 */
function show_custom_tag_columns($columns){

    if($pagenow === 'edit-tags.php' && !isset($_GET['post_type'])) :

        $columns['archive_headline'] = __('Archive Headline');
        $columns['archive_intro_text'] = __('Archive Intro Text');

    endif;

}

/**
 * Adds the IDs to the ID column where data must be returned
 *
 * @param required array $value Not sure what this is...
 * @param required array $column_name The name of the current column
 * @param required array $object_id The object ID
 * @return array $defaults Updated list of table columns
 */
function fill_custom_tag_columns_by_return($column_values, $column_name, $object_id){

    global $wpdb;

    echo $column_values; // Output any pre-existing column values so they don't get over written

    if($column_name === 'archive_headline') :
        // Do what ever you do to get the data for this column
        return $archive_headline;
    endif;
    if($column_name === 'archive_intro_text') :
        // Do what ever you do to get the data for this column
        return $archive_intro_text;
    endif;

}

并隐藏列,添加以下 CSS -

table.widefat th.column-archive_headline,
table.widefat th.column-archive_intro_text{
    display: none;
}
于 2012-11-02T11:40:22.760 回答