【问题标题】:WordPress: page Template Conditional checking not working in functions.phpWordPress:页面模板条件检查在functions.php中不起作用
【发布时间】:2019-08-25 01:06:33
【问题描述】:

仅当用户使用特定模板但条件页面模板 ( is_page_template('templa_name) ) 不起作用并且代码落入 else 部分时,我才想在 WordPress 中添加样式表。我什至通过代码获得了正确的模板名称,并尝试添加该代码,但没有奏效。我可以轻松添加并继续我的开发,但这很奇怪,我想知道这个奇怪问题的解决方案。

尝试了模板文件和stackoverflow中的代码。有答案但无济于事。尝试了不同的代码变种,但都是一样的

if ( is_page_template('page-templates/page-landing-page.php') ) {

    function this_echoes() {

        $looking_at = is_page_template( 'page-templates/page-landing-page.php' );
        echo $looking_at;
        echo '<br>';
        echo 'if';
        echo '<br>';
        $page_template22 = get_page_template_slug( get_queried_object_id() );
        echo $page_template22;
    }
     } else {
     function this_echoes() {

        $looking_at = is_page_template( 'page-templates/page-landing-page.php' );
        echo '<br>';
        echo $looking_at;
        echo '<br>';
        echo '$looking_at';
        echo '<br>';
        $page_template22 = get_page_template_slug( get_queried_object_id() );
        echo $page_template22 ;

        echo 'else';
      }

}

我希望代码属于 if 语句而不是 else 语句。我知道我检查的方式是正确的。

【问题讨论】:

    标签: wordpress wordpress-theming custom-wordpress-pages


    【解决方案1】:

    您的 if 条件需要进入主 this_echoes 函数。

    我建议使用模板名称 slugs (https://codex.wordpress.org/Function_Reference/get_page_template_slug) 然后使用 if 检查完成您的工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-25
      • 1970-01-01
      • 2016-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-06
      • 1970-01-01
      相关资源
      最近更新 更多