1

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 :

enter image description here

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

1 Answer 1

1

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

check

Sign up to request clarification or add additional context in comments.

11 Comments

Great And many thanks .header and footer are showed.Any idea about the add button ?
what you want to do with the link? it is showing right
I am not sure but i use link for adding ? Do this is the way i am doing OR in WP have alternates for adding.What is the way the best way of adding data to DB in WP custom plugins.Hope you got my point
no issues you can extra_tablenav like href="admin.php?page=add-letter.php&type=new"
hope you understand it
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.