Reputation: 4331
I am working on custom plugin in WP.I have showed the data in table format.Now i am trying to add functionality to plugin.But my table missing header and footer just like normal data listing in WP like Pages and Posts etc.Also i added the new button link.Either this is the right way ? I want to load my page on button clickMy code is :
function extra_tablenav( $which ) {
if ( $which == "top" ){
//The code that goes before the table is here
echo '<h2>Letter Templates <a href="http://localhost/letter/wp-content/plugins/letter/add-letter.php?type=new" class="add-new-h2">Add New</a></h2>';
}
}
function get_columns() {
return $columns= array(
'col_id'=>__('ID'),
'col_name'=>__('Name'),
'col_url'=>__('Url'),
'col_description'=>__('Description')
);
}
public function get_sortable_columns() {
return $sortable = array(
'col_id'=>'id',
'col_name'=>'name'
);
}
Upvotes: 1
Views: 4422
Reputation: 2314
You can use the $_column_headers
extended Property
this property is assigned automatically, must manually define it in their prepare_items() or __construct() methods.
like,
function prepare_items(){
$columns = array(
'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
'col_id' => 'ID',
'col_name' => 'Name',
'col_url' => 'URL',
'col_description' => 'Description',
);
$sortable_columns = array(
'col_id' => 'ID',
'col_name' => 'Name',
);
$hidden = array();
$this->_column_headers = array($columns, $hidden, $sortable);
}
function extra_tablenav( $which ) {
if ( $which == "top" ){
echo '<h2>Letter Templates <a href="admin.php?page=letter-template&type=new">Add New</a></h2>';
}
}
The Wordpress natively supports URLs like wp-admin/admin.php?page=
you acess plugin pages like wp-admin/admin.php?page=mypage&tab=add-letter
And then in your code you just look at the GET and pull up the main page or a sub-page as needed.
like
if(isset($_GET['type']) && $_GET['type']=='new'){
include('add-letter.php');
}
Upvotes: 1