Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

When viewing non-custom Posts, you get the likes of this submenu:

submenu

I'm not using a title - I'm using custom columns with two fields concatenated:

my species profiles

Is there any quick and easy way of adding the submenu to my custom post columns? Possibly by actually using the 'title' field on my custom post creation page - without having the title input box, as it's unnecessary for my users to see/edit.

share|improve this question
    
Anybody have any ideas? –  dunc Jun 25 '11 at 17:01
add comment

3 Answers

up vote 1 down vote accepted

In the end, I went for this:

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;
        }
    }

Seems to do the trick!

share|improve this answer
    
Thanks for posting this, it was a real bear to solve, you helped me out a lot! –  mcleodm3 Dec 4 '11 at 1:59
add comment

Joost DeValk walked through the various options / setup in this post here: http://yoast.com/custom-post-type-snippets/

share|improve this answer
    
Thanks for that. It's a great article - I used it for my answer - but doesn't cover changing the "title" functionality, i.e. the submenu. I've got it all now though. –  dunc Jun 26 '11 at 21:34
    
Good deal. Wasn't sure what you meant by "submenu". I had assumed it was a taxonomy –  Norcross Jun 26 '11 at 23:08
add comment

I had a similar situation and I based myself on </wp-admin/includes/class-wp-posts-list-table.php>:499 (function single_row {...case 'title')

Copy the $actions creation block, and associated variables, (which looks something like this) to your manage_{post_type}_posts_custom_column action:

$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>';
    }
}

Modify this line:

$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 );

Not the most futureproof of code but until they wrap it up in a reusable function, its a good working solution.

Cheers,

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.