2014-10-30 65 views
1

我搜索了很多如何自定義自定義信息列表, 我設法增加一個新的列與manage_commercial_cpi_posts_columns, 但是,我需要從列表中刪除「標題」 ,並且仍然具有編輯,刪除選項。 我該怎麼辦?WordPress的變化自定義後類型標題

+0

什麼是你的列表頁的權利嗎?你可以改變標題嗎? – 2014-10-30 06:10:23

回答

2

您可以隱藏CSS或JS的標題鏈接,但這裏有一個PHP方法。首先去掉標題欄,並添加自定義一個:

add_filter('manage_commercial_cpi_posts_columns', 'manage_commercial_cpi_posts_columns', 25, 1); 
function manage_commercial_cpi_posts_columns($cols) 
{ 
    // remove title column 
    unset($cols['title']); 

    // add custom column 
    $cols['ccpi_links'] = __('Edit', 'textdomain'); 

    // return columns 
    return $cols; 
} 

然後,使用WP_List_Table類的row_actions方法生成的鏈接。代碼從WP_Posts_List_Table類複製而來。一個重要的細節是添加true作爲row_actions方法的第二個參數,確保鏈接始終可見。

add_action('manage_commercial_cpi_posts_custom_column', 'manage_commercial_cpi_custom_column', 10, 2); 
function manage_commercial_cpi_custom_column($col, $post_id) 
{ 
    switch($col) : 

    case 'ccpi_links' : 

     // variables 
     $post    = get_post($post_id); 
     $title    = _draft_or_post_title(); 
     $post_type_object = get_post_type_object($post->post_type); 
     $can_edit_post  = current_user_can('edit_post', $post->ID); 

     // set up row actions 
     $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('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->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) { 
        $preview_link = set_url_scheme(get_permalink($post->ID)); 
        /** This filter is documented in wp-admin/includes/meta-boxes.php */ 
        $preview_link = apply_filters('preview_post_link', add_query_arg('preview', 'true', $preview_link), $post); 
        $actions['view'] = '<a href="' . esc_url($preview_link) . '" 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>'; 
      } 
     } 

     // invoke row actions 
     $table = new WP_Posts_List_Table; 
     echo $table->row_actions($actions, true); 

     break; 

    endswitch; 
} 

結果

enter image description here

+0

謝謝,非常有幫助 – dvircn 2014-11-22 19:10:37

相關問題