前面我们介绍了WordPress开发注册自定义文章的一些方法
- WordPress插件开发 register_post_type 设定菜单 位置 结合 add_submenu_page 添加自定义设置页面
- wordpress使用register_post_type 函数创建自定义文章类型
下面我们教大家如何在WordPress后台edit.php的自定义文章列表中筛选自定义文章的分类,代码段如下:
function sites_posts_taxonomy_filter() {
global $typenow;
if( $typenow == 'sites' ){ //指定post_type类型 $taxonomy_names = array('favorites', );//指定分类taxonomy foreach ($taxonomy_names as $single_taxonomy) { $current_taxonomy = isset( $_GET[$single_taxonomy] ) ? $_GET[$single_taxonomy] : ''; $taxonomy_object = get_taxonomy( $single_taxonomy ); $taxonomy_name = strtolower( $taxonomy_object->labels->name ); $taxonomy_terms = get_terms( $single_taxonomy ); if(count($taxonomy_terms) > 0) { echo "<select name='$single_taxonomy' id='$single_taxonomy' class='postform'>"; echo "<option value=''>All $taxonomy_name</option>"; foreach ($taxonomy_terms as $single_term) { echo '<option value='. $single_term->slug, $current_taxonomy == $single_term->slug ? ' selected="selected"' : '','>' . $single_term->name .' (' . $single_term->count .')</option>'; } echo "</select>"; } } }
}
add_action( 'restrict_manage_posts', 'sites_posts_taxonomy_filter' );
腾讯云
限时秒杀【点击购买】
搬瓦工,CN2
高速线路,1GB
带宽,电信联通优化KVM
,延迟低,速度快,建站稳定,搬瓦工BandwagonHost VPS优惠码BWH26FXH3HIQ
,支持<支付宝> 【点击购买】!
Vultr$3.5
的日本
节点,512M
内存/500G
流量/1G
带宽,电信联通优化,延迟低,速度快【点击购买】!
阿里云
香港、新加坡
VPS/1核/1G/25G SSD
/1T
流量/30M
带宽/年付¥288
【点击购买】
评论已关闭