仪表板:10个最后草稿页面和10个最后待审页面(Metabox)

时间:2017-06-23 作者:Samuel

我想在仪表板上显示一些用户角色(管理员、编辑器和auther)。包含10个最后草稿页和10个最后编辑页的框。

对于最后编辑的10页,我使用以下自定义:

add_action( \'wp_dashboard_setup\', \'admin_dashboard_last_edits_register\' );

function admin_dashboard_last_edits_register() {
  wp_add_dashboard_widget(
  __FUNCTION__, __( \'Recently edited Pursuits pages\', \'admin-dashboard-last-edits\' ), \'admin_dashboard_last_edits_dashboard_widget\');
}

function admin_dashboard_last_edits_dashboard_widget() { 
  $posts = get_posts(
  array (
    \'numberposts\' => 10, 
    \'post_type\' => array ( \'page\' ), 
    \'orderby\' => \'modified\')
    );

  if ( $posts ) {
    $date_format = get_option( \'date_format\' );
    echo \'<ul>\';
    foreach ( $posts as $post ) {
      printf( __( \'<li><a href="%1$s" title="Edit %3$s"><span class="dashicons dashicons-edit"></span></a> <a href="%2$s" title="View %3$s on website">%3$s</a> <small>%4$s</small>\', \'admin-dashboard-last-edits\' ), esc_html( get_edit_post_link( $post->ID ) ), esc_html( get_permalink( $post->ID ) ), esc_html( $post->post_title ), esc_html( get_post_modified_time( $date_format, false, $post->ID, true )) ); 
    }
    echo \'</ul>\';
  }

  else {
    printf( __( \'No edits found. <a href="%1$s">Write a new post</a>.\', \'admin-dashboard-last-edits\' ), esc_url( admin_url( \'post-new.php\' ) ) );
  }

}
我还想在每个框上添加修改时间。

1 个回复
最合适的回答,由SO网友:Samuel 整理而成
#dahsboard BOXES

#Last edited pages

add_action( \'wp_dashboard_setup\', \'admin_dashboard_last_edits_register\' );

function admin_dashboard_last_edits_register() {
  wp_add_dashboard_widget(
  __FUNCTION__, __( \'Last published pages \', \'admin-dashboard-last-edits\' ), \'admin_dashboard_last_edits_dashboard_widget\');
}

function admin_dashboard_last_edits_dashboard_widget() { 
  $posts = get_posts(
  array (
    \'numberposts\' => 10, 
    \'post_type\' => array ( \'page\' ), 
    \'orderby\' => \'modified\')
    );

  if ( $posts ) {
    $date_format = get_option( \'date_format\' );
    echo \'<ul>\';
    foreach ( $posts as $post ) {
      printf( __( \'<li><a href="%1$s" title="Edit %3$s"><span class="dashicons dashicons-edit"></span></a> <a href="%2$s" title="View %3$s on website">%3$s</a> <small>%4$s</small>\', \'admin-dashboard-last-edits\' ), esc_html( get_edit_post_link( $post->ID ) ), esc_html( get_permalink( $post->ID ) ), esc_html( $post->post_title ), esc_html( get_post_modified_time( $date_format, false, $post->ID, true )) ); 
    }
    echo \'</ul>\';
  }

  else {
    printf( __( \'No edits found. <a href="%1$s">Write a new post</a>.\', \'admin-dashboard-last-edits\' ), esc_url( admin_url( \'post-new.php\' ) ) );
  }

}

#Last draft pages

add_action( \'wp_dashboard_setup\', \'admin_dashboard_last_draft_register\' );

function admin_dashboard_last_draft_register() {
  wp_add_dashboard_widget(
  __FUNCTION__, __( \'Last Draft Pages\', \'admin-dashboard-last-draft\' ), \'admin_dashboard_last_draft_dashboard_widget\');
}

function admin_dashboard_last_draft_dashboard_widget() { 
  $posts = get_posts(
  array (
    \'numberposts\' => 10, 
    \'post_status\' => array(\'draft\'),
    \'post_type\' => array ( \'page\' ), 
    \'orderby\' => \'modified\')
    );

  if ( $posts ) {
    $date_format = get_option( \'date_format\' );
    echo \'<ul>\';
    foreach ( $posts as $post ) {
      printf( __( \'<li><a href="%1$s" title="Edit %3$s"><span class="dashicons dashicons-edit"></span></a> <a href="%2$s" title="View %3$s on website">%3$s</a> <small>%4$s</small>\', \'admin-dashboard-last-edits\' ), esc_html( get_edit_post_link( $post->ID ) ), esc_html( get_permalink( $post->ID ) ), esc_html( $post->post_title ), esc_html( get_post_modified_time( $date_format, false, $post->ID, true )) ); 
    }
    echo \'</ul>\';
  }

  else {
    printf( __( \'No edits found. <a href="%1$s">Write a new post</a>.\', \'admin-dashboard-draft-edits\' ), esc_url( admin_url( \'post-new.php\' ) ) );
  }

}

#Last pending review pages

add_action( \'wp_dashboard_setup\', \'admin_dashboard_last_pending_register\' );

function admin_dashboard_last_pending_register() {
  wp_add_dashboard_widget(
  __FUNCTION__, __( \'Last pending Review Pages\', \'admin-dashboard-last-pending\' ), \'admin_dashboard_last_pending_dashboard_widget\');
}

function admin_dashboard_last_pending_dashboard_widget() { 
  $posts = get_posts(
  array (
    \'numberposts\' => 10, 
    \'post_status\' => array(\'pending\'),
    \'post_type\' => array ( \'page\' ), 
    \'orderby\' => \'modified\')
    );

  if ( $posts ) {
    $date_format = get_option( \'date_format\' );
    echo \'<ul>\';
    foreach ( $posts as $post ) {
      printf( __( \'<li><a href="%1$s" title="Edit %3$s"><span class="dashicons dashicons-edit"></span></a> <a href="%2$s" title="View %3$s on website">%3$s</a> <small>%4$s</small>\', \'admin-dashboard-last-edits\' ), esc_html( get_edit_post_link( $post->ID ) ), esc_html( get_permalink( $post->ID ) ), esc_html( $post->post_title ), esc_html( get_post_modified_time( $date_format, false, $post->ID, true )) ); 
    }
    echo \'</ul>\';
  }

  else {
    printf( __( \'No edits found. <a href="%1$s">Write a new post</a>.\', \'admin-dashboard-pending-edits\' ), esc_url( admin_url( \'post-new.php\' ) ) );
  }

}
结束