首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >只有当当前页不是两个页面模板之一时,才显示内容

问只有当当前页不是两个页面模板之一时,才显示内容
EN

WordPress Development用户
提问于 2013-09-23 10:06:00
回答 3查看 8.6K关注 0票数 1

如果当前页面没有使用特定的页面模板,我一直使用这个if条件语句来显示内容;

代码语言:javascript
复制
if (! is_page_template('template-custom.php')) {
    <!-- show some content  -->
}

一直运作得很好。只有现在,如果当前页面没有使用2个模板中的一个,则需要修改语句以显示内容(因此,如果当前页面使用template-custom.php或template-custom2.php,则不要显示内容)。

我试过这个;

代码语言:javascript
复制
if (! is_page_template('template-custom.php') || is_page_template('template-custom2.php')) {
    <!-- show some content  -->
}

还有这个;

代码语言:javascript
复制
if (! is_page_template('template-custom.php') || ! is_page_template('template-custom2.php')) {
    <!-- show some content  -->
}

但对阿维尔来说。

有什么建议吗?

EN

回答 3

WordPress Development用户

回答已采纳

发布于 2013-09-23 10:19:46

如果不想显示内容,如果当前模板是template-custom.php或template-custom2.php,则可以使用:

代码语言:javascript
复制
if (!is_page_template('template-custom.php') && !is_page_template('template-custom2.php')) {
    <!-- show some content when you AREN NOT in template-custom.php NOR template-custom2.php -->
}

或

代码语言:javascript
复制
if (is_page_template('template-custom.php') || is_page_template('template-custom2.php')) {
    <!-- show some content when you ARE in template-custom.php OR template-custom2.php -->
}
票数 3
EN

WordPress Development用户

发布于 2013-09-23 10:20:46

根据德摩根定律

代码语言:javascript
复制
"not (A or B)" is the same as "(not A) and (not B)"
票数 0
EN

WordPress Development用户

发布于 2013-09-23 10:13:44

试试这个:

代码语言:javascript
复制
if (! is_page_template('template-custom.php') || ! is_page_template('template-custom2.php')) {
    <!-- show some content  -->
}
票数 -2
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/115281

复制
相关文章

相似问题

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