自定义帖子类型:带有标题子菜单的自定义列?

时间:2011-06-25 作者:turbonerd

查看非自定义帖子时,您会看到如下子菜单:

submenu

我没有使用标题-我使用的是连接了两个字段的自定义列:

my species profiles

有没有什么简单快捷的方法可以将子菜单添加到我的自定义帖子列中?可能是在我的自定义帖子创建页面上使用“标题”字段,而没有标题输入框,因为我的用户不需要查看/编辑。

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

最后,我决定:

function species_custom_columns($column){
        global $post;

        if (!isset($title)) {
            $title = $this->getValue(\'genus\',$post->ID,TRUE) . \' \' . $this->getValue(\'species\',$post->ID,TRUE);
        }
        if (!isset($post_url)) { $post_url = get_site_url() . "/wp-admin/post.php?post=" . $post->ID . "&action=edit"; }
        if (!isset($post_url_frontend)) { $post_url_frontend = get_site_url() . "/?p=" . $post->ID; }

        $genus_species = <<<EOT
<strong>
<a class="row-title" title="Edit “{$title}”" href="{$post_url}">{$title}</a>
</strong>
<div class="row-actions">
<span class="edit">
<a title="Edit species" href="{$post_url}">Edit</a>
|
</span>
EOT;
        $genus_species .= $this->delete_post_link(\'Trash\', $title, \'<span class="trash">\', \' |</span>\');

        $genus_species .= <<<EOT
<span class="view">
<a rel="permalink" title="View “{$title}”" href="{$post_url_frontend}">View</a>
</span>
</div>
EOT;

        switch ($column) {
            case "genus_species":
                echo $genus_species;
                break;
            case "common_names":
                echo $this->getValue(\'common_names\',$post->ID,TRUE);
                break;
            case "family":
                echo $this->getValue(\'family\',$post->ID,TRUE);
                break;
            case "group":
                if (get_the_terms($post->ID, \'group\')) {
                    $taxonomy_ar = get_the_terms($post->ID, \'group\');

                    $output = \'<ul>\';
                    foreach ($taxonomy_ar as $taxonomy_term) {
                        if ($taxonomy_term->parent) {
                            $output .= \'<li> <span style="font-size:6px;">&gt;</span> \'. $taxonomy_term->name .\'</li>\';
                        } else {
                            $output .= \'<li>\'. $taxonomy_term->name .\'</li>\';
                        }
                    }
                    $output .= \'</ul>\';

                    echo $output;
                }
                break;
            case "excerpt":
                //echo the_excerpt();
                break;
            case "date_modified":
                echo the_modified_date(\'F j, Y @ g:i a\');
                break;
        }
    }
似乎是在耍花招!

SO网友:Chauncey McAskill

我也遇到过类似的情况,我的基础是<;/wp-admin/includes/class-wp-posts-list-table.php>:499人(function single_row {...case \'title\')

复制$actions 创建块和相关变量(如下所示)manage_{post_type}_posts_custom_column 措施:

$post = get_post( $post_id );
setup_postdata( $post );

$title = _draft_or_post_title();
$post_type_object = get_post_type_object( $post->post_type );
$can_edit_post = current_user_can( $post_type_object->cap->edit_post, $post->ID );

$actions = array();
if ( $can_edit_post && \'trash\' != $post->post_status ) {
    $actions[\'edit\'] = \'<a href="\' . get_edit_post_link( $post->ID, true ) . \'" title="\' . esc_attr( __( \'Edit this item\' ) ) . \'">\' . __( \'Edit\' ) . \'</a>\';
    $actions[\'inline hide-if-no-js\'] = \'<a href="#" class="editinline" title="\' . esc_attr( __( \'Edit this item inline\' ) ) . \'">\' . __( \'Quick&nbsp;Edit\' ) . \'</a>\';
}
if ( current_user_can( $post_type_object->cap->delete_post, $post->ID ) ) {
    if ( \'trash\' == $post->post_status )
        $actions[\'untrash\'] = "<a title=\'" . esc_attr( __( \'Restore this item from the Trash\' ) ) . "\' href=\'" . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . \'&amp;action=untrash\', $post->ID ) ), \'untrash-\' . $post->post_type . \'_\' . $post->ID ) . "\'>" . __( \'Restore\' ) . "</a>";
    elseif ( EMPTY_TRASH_DAYS )
        $actions[\'trash\'] = "<a class=\'submitdelete\' title=\'" . esc_attr( __( \'Move this item to the Trash\' ) ) . "\' href=\'" . get_delete_post_link( $post->ID ) . "\'>" . __( \'Trash\' ) . "</a>";
    if ( \'trash\' == $post->post_status || !EMPTY_TRASH_DAYS )
        $actions[\'delete\'] = "<a class=\'submitdelete\' title=\'" . esc_attr( __( \'Delete this item permanently\' ) ) . "\' href=\'" . get_delete_post_link( $post->ID, \'\', true ) . "\'>" . __( \'Delete Permanently\' ) . "</a>";
}
if ( $post_type_object->public ) {
    if ( in_array( $post->post_status, array( \'pending\', \'draft\', \'future\' ) ) ) {
        if ( $can_edit_post )
            $actions[\'view\'] = \'<a href="\' . esc_url( add_query_arg( \'preview\', \'true\', get_permalink( $post->ID ) ) ) . \'" title="\' . esc_attr( sprintf( __( \'Preview &#8220;%s&#8221;\' ), $title ) ) . \'" rel="permalink">\' . __( \'Preview\' ) . \'</a>\';
    } elseif ( \'trash\' != $post->post_status ) {
        $actions[\'view\'] = \'<a href="\' . get_permalink( $post->ID ) . \'" title="\' . esc_attr( sprintf( __( \'View &#8220;%s&#8221;\' ), $title ) ) . \'" rel="permalink">\' . __( \'View\' ) . \'</a>\';
    }
}
修改此行:

$this->row_actions( $actions );          // From this

// This is calling a non static function statically and will throw an error.
// WP_List_Table::row_actions( $actions );

// Correct way, no error.
$WPTables = new WP_List_Table;
$WPTables->row_actions( $actions );
这不是最适合未来的代码,但在他们将其打包成可重用函数之前,这是一个很好的工作解决方案。

干杯

SO网友:Norcross

Joost DeValk在本文中介绍了各种选项/设置:http://yoast.com/custom-post-type-snippets/

结束

相关推荐

title tag function

我正在使用一个函数来显示标题标签上的URL,我对这个函数进行了编码,它可以正常工作,但我想对它进行进一步的自定义。function title_tag() { $a = $_SERVER[\'REQUEST_URI\']; $b = strtoupper($a); $c = str_replace(\'-\', \' \', $b); $d = str_replace(\'/\', \' - \', $c); $e = substr($d, 2);