我有一个复选框选项,可以只在主页上或在整个页面上显示某个功能,
复选框
<input class="checkbox" type="checkbox" id="home-only" name="mytheme_options[home-only]" value="1" checked="checked">
PHP
$display_in_home = mytheme_option('home-only');
if ($display_in_home == 1) {
echo 'Sample Text';
}
我不确定如何将$display_in_home == 1
包含/或分配给功能
is_front_page()
在上方的代码中
我试过这样的东西,但没有运气
$showin_in_home = mytheme_option('home-only');
$front = is_front_page();
if( $showin_in_home == 1 ) $filter = $front;
else $filter = '';
if ($filter) {
echo 'Sample Text';
}
对不起,如果我上面的代码看起来很有趣,我只是个新手,刚开始学习PHP。
也许您正在寻找逻辑运算符。
试试这样的东西:
if( mytheme_option('home-only') && is_front_page() )
{
echo 'Sample text';
}
这对于用作快捷方式可能很有用:$show_in_home = mytheme_option('home-only');
。
但是,在我看来,这是不必要的:$filter = is_front_page()
。