首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果自定义post类型中的数组- Wordpress functions.php

如果自定义post类型中的数组- Wordpress functions.php
EN

Stack Overflow用户
提问于 2014-02-21 11:31:14
回答 1查看 1.1K关注 0票数 0

我正在使用下面的代码从Wordpress post显示(不同post类型的发布metaboxes )中删除一些片段。代码都在工作,我只是想知道它能否成功地压缩成一个数组?我不知道该怎么做。

我很感激任何人能给予我的帮助。

代码语言:javascript
复制
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');
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-21 11:38:46

不要使用单独的if语句,而是使用in_array()将其组合到一个if语句中。

请参阅:array

代码语言:javascript
复制
if(in_array($post->post_type, array('page', 'post-type-1', 'post-type-2', 'post-type-3', 'post-type-4')) { ...
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21933266

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档