简体   繁体   English

从PHP查询中排除页面

[英]Exclude pages from PHP query

So I have this chunk of PHP that excluded a certain element from appearing on all of my WordPress pages, while keeping them on posts/products, but there's a couple of pages where I would still like it to appear. 因此,我拥有这段PHP,可以将某些元素排除在我的所有WordPress页面上,而不会保留在帖子/产品上,但是我仍然希望在其中几页上显示它。

How do I go about excluding certain Page IDs from this query? 如何从此查询中排除某些页面ID?

add_action( 'template_redirect', 'avada_check_page' );
function avada_check_page() {
if ( is_singular( 'page' ) ) {
add_action( 'avada_override_current_page_title_bar', 'avada_remove_title_bar' );
}
}
function avada_remove_title_bar() {
}

There's about 100 pages I want to apply this to and only 5 where I want to exclude them from this code. 我希望将其应用于大约100页,而只有5个页面要从此代码中排除它们。

A simple way would just be to use a condition on that first if statement. 一种简单的方法就是在第一个if语句上使用条件。

add_action( 'template_redirect', 'avada_check_page' );
function avada_check_page() {
    if ( is_singular( 'page' ) && !in_array(get_the_ID(),array(1,2,3,4)) ) {
        add_action( 'avada_override_current_page_title_bar', 'avada_remove_title_bar' );
    }
}
function avada_remove_title_bar() {

}

Where 1,2,3,4 place the exceptions posts ID's. 1,2,3,4放置例外的地方发布ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM