在单个页面上调用函数

时间:2016-04-03 作者:user3799045

如何将此函数应用于单个页面ID:

function exclude_jobs_locations($args){
    $exclude = "40";
    $args["exclude"] = $exclude;
    return $args;
}
add_filter("sjb_job_location_filter_args","exclude_jobs_locations");
排除父类别时,我是否也可以排除子类别?

我尝试过:

function exclude_jobs_locations_uk($args){  
if( is_page( 2094 ) ) {
    $exclude = "40";
    $args["exclude"] = $exclude;
}
return $args;
}
 add_filter("sjb_job_location_filter_args","exclude_jobs_locations_uk");
但出了点问题。

我使用此函数从以下内容中排除类别:

// Creating list on non-empty job location                    
$jobloc_select = wp_dropdown_categories(apply_filters(\'sjb_job_location_filter_args\', array(
                    \'show_option_none\' => __(\'Location\', \'simple-job-board\'),
                    \'hide_empty\'       => 0,
                    \'name\'             => \'selected_location\',
                    \'orderby\'          => \'NAME\',
                    \'order\'            => \'ASC\',
                    \'class\'            => \'sjb-form-control\',
                    \'hierarchical\'     => TRUE,
                    \'value_field\'      => \'slug\',
                    \'taxonomy\'         => \'jobpost_location\',                        
                    \'selected\'         => $selected_location,
                    \'echo\'             => FALSE,
                )));
                ?>             

2 个回复
SO网友:dg4220

假设您的函数一般运行,将其限制为特定的页面使用

if( is_page( 2094 ) ) {
    add_filter("sjb_job_location_filter_args","exclude_jobs_locations_uk");
}
函数定义的位置无关紧要。

P、 关于排除类别。是的,我们需要更多地了解所谓的(插件?)作用

SO网友:user3799045

解决方案是制作一个模板:

if (!is_page_template(\'jobs-uk.php\'))
add_filter(\'sjb_job_location_filter_args\', \'exclude_jobs_locations_uk\');