0

是否有可用于检测页面的 wordpress 功能?我想做的例子如下。

<?php if( is_FUNCTION_page('Contact Us') ) : ?>

...display this <div> / xhtml

<?php else: ?>

something else <div>

<?php endif;?> 
4

2 回答 2

3

检查is_page()函数:

is_page();
// When any single Page is being displayed.

is_page(42);
// When Page 42 (ID) is being displayed.

is_page('Contact');
// When the Page with a post_title of "Contact" is being displayed.

is_page('about-me');
// When the Page with a post_name (slug) of "about-me" is being displayed.

is_page(array(42,'about-me','Contact'));
// Returns true when the Pages displayed is either post ID 42, or post_name "about-me", or post_title "Contact".  Note: the array ability was added at Version 2.5.
于 2012-06-07T08:59:01.360 回答
2

是的。使用 Wordpress is_page函数来做到这一点。

例子:

<?php if( is_page('Contact Us') ) : ?>

<div> Your If content goes here </div>

<?php else: ?>

<div> something else </div>

<?php endif;?> 

笔记:

不能在循环内使用

由于某些全局变量在循环期间被覆盖,is_page() 将不起作用。为了在循环之后使用它,您必须在循环之后调用 wp_reset_query()。

于 2012-06-07T09:06:00.213 回答