显示视频表的ADD_SUBMENT_PAGE函数

时间:2012-01-20 作者:v3nt

想知道是否可以使用自定义菜单链接显示视频的附件管理列表?

欢迎指点!D

add_action(\'admin_menu\', \'mt_add_pages\');
function mt_add_pages() {
    add_menu_page(\'Directors & Showreels\', \'Directors & Showreels\', \'manage_options\', \'dsv_menu\', \'wps_theme_func\',null,2);
    $videos_page = add_submenu_page(\'dsv_menu\', __(\'Videos\',\'showreel_videos\'),  __(\'Videos\',\'showreel_videos\'), \'edit_posts\', \'sub-page-videos\', \'display_showreel_videos\');

}
function display_showreel_videos(){ ?>
     <div class="wrap"><h2>Videos</h2>
          <!-- get attachments by mime type ? (upload.php?post_mime_type=video ??)   -->
    </div><?
}
使用类TT\\u Example\\u List\\u Table扩展了WP\\u List\\u Table,下面的链接提供了帮助。。。看起来不错,但无法使“编辑”或“删除”链接正常工作。

$media_query = new WP_Query(
    array(
        \'post_type\' => \'attachment\', // get attachments only
        \'post_status\' => \'inherit\', // attachments are not \'published\', so set it to inherit
        \'posts_per_page\' => -1, // display all
        \'post_mime_type\' => \'video\' // grab files with the mime type \'video\'
    )
);

$list = array();

foreach ($media_query->posts as $post) {

    $list[] = array(\'thumbnail\'=>\'\', \'ID\'=>$post->ID,\'title\'=>$post->post_title);

}

//Create an instance of our package class...
$testListTable = new TT_Example_List_Table();
$testListTable->setContent($list);
$testListTable->prepare_items();
$testListTable->display();

1 个回复
SO网友:Jared

我问了一个类似的问题,得到了这个答案,查询DB中的附件并将其转储到列表中。这是提供给我的代码:

$media_query = new WP_Query(
    array(
        \'post_type\' => \'attachment\', // get attachments only
        \'post_status\' => \'inherit\', // attachments are not \'published\', so set it to inherit
        \'posts_per_page\' => -1, // display all
        \'post_mime_type\' => \'video\' // grab files with the mime type \'video\'
    )
);
$list = array();
foreach ($media_query->posts as $post) {
    $list[] = wp_get_attachment_url($post->ID);
}
// do something with $list here;
希望这为你指明了正确的方向。我的问题:Get All Images in Media Gallery?

<小时>EDIT: 至于在表中显示它,我认为您可以真正受益于挖掘以下代码:http://wordpress.org/extend/plugins/custom-list-table-example/

它有一个使用WP_List_Table 在WordPress中。我看了一眼,知道这是一个很好的代码

结束

相关推荐

Menu API not switching menus?

我正在使用菜单API,我想切换到其他菜单,但出于某种原因,它保留了第一个菜单这是我的密码在函数中。php add_action( \'init\', \'register_my_menus\',10 ); function register_my_menus() { register_nav_menu(\'main-navigation\', \'Main Navigation\'); } 下面是我的主题文件(header.ph