我正在使用下面的代码从Wordpress post显示(不同post类型的发布metaboxes )中删除一些片段。代码都在工作,我只是想知道它能否成功地压缩成一个数组?我不知道该怎么做。
我很感激任何人能给予我的帮助。
function hide_publishing_actions(){
global $post;
if($post->post_type == 'page'){
echo '
<style type="text/css">
#misc-publishing-actions,
#minor-publishing-actions,
ul.subsubsub,
p.search-box,
div.view-switch,
#posts-filter .tablenav select[name=m],
#posts-filter .tablenav #post-query-submit{
display:none;
}
</style>
';
}
if($post->post_type == 'post-type-1'){
echo '
<style type="text/css">
#misc-publishing-actions,
#minor-publishing-actions,
ul.subsubsub,
p.search-box,
div.view-switch,
#posts-filter .tablenav select[name=m],
#posts-filter .tablenav #post-query-submit{
display:none;
}
</style>
';
}
if($post->post_type == 'post-type-2'){
echo '
<style type="text/css">
#misc-publishing-actions,
#minor-publishing-actions,
ul.subsubsub,
p.search-box,
div.view-switch,
#posts-filter .tablenav select[name=m],
#posts-filter .tablenav #post-query-submit{
display:none;
}
</style>
';
}
if($post->post_type == 'post-type-3'){
echo '
<style type="text/css">
#misc-publishing-actions,
#minor-publishing-actions,
ul.subsubsub,
p.search-box,
div.view-switch,
#posts-filter .tablenav select[name=m],
#posts-filter .tablenav #post-query-submit{
display:none;
}
</style>
';
}
if($post->post_type == 'post-type-3'){
echo '
<style type="text/css">
#misc-publishing-actions,
#minor-publishing-actions,
ul.subsubsub,
p.search-box,
div.view-switch,
#posts-filter .tablenav select[name=m],
#posts-filter .tablenav #post-query-submit{
display:none;
}
</style>
';
}
if($post->post_type == 'post-type-4'){
echo '
<style type="text/css">
#misc-publishing-actions,
#minor-publishing-actions,
ul.subsubsub,
p.search-box,
div.view-switch,
#posts-filter .tablenav select[name=m],
#posts-filter .tablenav #post-query-submit{
display:none;
}
</style>
';
}
}
add_action('admin_head-post.php', 'hide_publishing_actions');
add_action('admin_head-post-new.php', 'hide_publishing_actions');
add_action('admin_head-edit.php', 'hide_publishing_actions');发布于 2014-02-21 11:38:46
不要使用单独的if语句,而是使用in_array()将其组合到一个if语句中。
请参阅:array
if(in_array($post->post_type, array('page', 'post-type-1', 'post-type-2', 'post-type-3', 'post-type-4')) { ...https://stackoverflow.com/questions/21933266
复制相似问题