php如果条件在wordpress中不起作用
有关下页: 如果标题与提供的标题匹配,我尝试显示滑块:php如果条件在wordpress中不起作用,php,wordpress,if-statement,Php,Wordpress,If Statement,有关下页: 如果标题与提供的标题匹配,我尝试显示滑块: <div id="content" class="site-content" role="main"> <div class="layout-full"> <header class="entry-header"> <h1 class="entry-title"><?php single_cat_title
<div id="content" class="site-content" role="main">
<div class="layout-full">
<header class="entry-header">
<h1 class="entry-title"><?php single_cat_title(); ?></h1>
<!-- This displays 'Wedding' -->
</header>
<!-- wedding -->
<?php
if ( single_cat_title() == "Wedding") {
//above line doesn't work...and instead prints wedding on the page.
echo do_shortcode('[metaslider id="1710"]');
}
?>
<!--portrait -->
<?php echo do_shortcode('[metaslider id="1718"]'); ?>
<!--travel -->
<?php echo do_shortcode('[metaslider id="1714"]'); ?>
</div>
根据文档(),有两个可选参数要包含在single\u cat\u title()函数中
尝试将第二个参数($display
)设置为FALSE
:
if ( single_cat_title('', FALSE) == "Wedding") {
echo do_shortcode('[metaslider id="1710"]');
}
如果不设置此值,则表示应显示标题,请将此值设置为false以检索而不是显示标题。默认情况下,函数single\u cat\u title打印标题,如果要检索用于比较的值,则需要以不同的方式使用函数
在函数的上,可以看到定义:
single_cat_title( string $prefix = '', bool $display = true )
也就是说,在您的情况下,如果出现以下情况,您应该执行以下操作:
if ( single_cat_title('', false) == "Wedding") {
通过将第二个参数设置为false,您将获得所需的值,而不是将其打印出来。single\u cat\u title()
采用两个参数,prefix
默认为空字符串,display
为布尔值,默认为true
将条件更改为此格式:
if ("Wedding" == single_cat_title("", false)) {
// do something
}
您是否检查了single\u cat\u title()
是否准确返回了Wedding
,并且它不包含空格或其他一些细微差别if(!stracecmp(single\u cat\u title('',FALSE),“Wedding”)