2012-12-11 66 views
6

我有一個「產品」自定義帖子類型。通常,這個自定義的帖子類型有一個「添加新的」按鈕。我想添加另一個按鈕調用「從提供程序更新」。如何將按鈕添加到Wordpress中的自定義帖子類型?

目前,我修改了WordPress的代碼(在「wordpress \ wp-admin \ includes \ class-wp-list-table.php」)添加該按鈕。在這種情況下,當我更新Wordpress時,我的修改後的代碼將被刪除。因此,我需要將該按鈕移至我的插件代碼。

在這種情況下,請幫助我如何將該按鈕移動到我的插件代碼。

enter image description here

+0

可以共享同一個屏幕截圖嗎? –

+0

@ sunil221請看屏幕截圖。 謝謝。 –

+0

@LeapBun按鈕點擊後我們如何調用代碼? – Celik

回答

14

好吧,如果你打開你看到有一個在它不採取行動,我們可以掛鉤的核心文件。

只有幾個過濾器。我們可以使用以下命令:

add_filter('views_edit-movies', 'so_13813805_add_button_to_views'); 
function so_13813805_add_button_to_views($views) 
{ 
    $views['my-button'] = '<button id="update-from-provider" type="button" title="Update from Provider" style="margin:5px">Update from Provider</button>'; 
    return $views; 
} 

它產生這樣的:

custom button in cpt

爲了把它的大致位置,從你想在哪裏,使用以下命令:

add_action('admin_head-edit.php', 'so_13813805_move_custom_button'); 

function so_13813805_move_custom_button() 
{ 
    global $current_screen; 
    // Not our post type, exit earlier 
    if('movies' != $current_screen->post_type) 
     return; 
    ?> 
    <script type="text/javascript"> 
     jQuery(document).ready(function($) 
     { 
      $('#update-from-provider').prependTo('span.displaying-num');  
     });  
    </script> 
    <?php 
} 

其中產品:
jquery dom manipulation

+0

大招,謝謝, –

相關問題