Php wordpress如果没有索引,则响应其他内容
我想给出我的标题Php wordpress如果没有索引,则响应其他内容,php,wordpress,Php,Wordpress,我想给出我的标题条件语句。如果不是主页,只需显示它是什么=。如果主页显示这是+ 所以语法应该是 <?php $path = $_SERVER['REQUEST_URI']; $page = basename($path); $page = basename($path, '.php'); ?> <?php if($page == 'index') {echo 'This is'. get_the_title(); } else {echo get_
条件语句。如果不是主页,只需显示它是什么=
。如果主页显示这是+
所以语法应该是
<?php
$path = $_SERVER['REQUEST_URI'];
$page = basename($path);
$page = basename($path, '.php');
?>
<?php if($page == 'index')
{echo 'This is'. get_the_title(); }
else
{echo get_the_title();}
?>
问题是我真的不知道在wordpress中,我们是用同样的方法还是更聪明或更简单的方法
哦,忘了!
实际上,我的索引/主页不是真正的索引,它是一个叫做“主页”的页面 设置从
阅读设置->静态页面,首页=>主页
谢谢您的建议。将代码放入
functions.php
function title_edit($title){
if(!is_front_page() || get_post_type() != 'page') return $title;
$title = 'Home: '.$title;
return $title;
}
add_filter('the_title','title_edit');
问题解决了谢谢@silentboy
<?php if(is_front_page())
echo 'This is'.get_the_title();
else echo get_the_title(); ?>
谢谢:-)是否可以将此代码放在/theme/functinos.php
中?但是,我收到的错误消息是“无法重新声明获取标题()(以前在\wordpress\wp includes\post template.php:102中声明)`只需更改名称或应用挂钩。实际上,我的索引/主页不是真正的索引,它是从阅读设置->静态页面,首页=>主页
中名为“主页”设置的页面,is_home不是为这个案子工作的。多谢了,汉克斯得到了错误“title_edit()缺少参数1”,最后我使它也工作了。我没有尝试编辑核心主题文件。但恭喜你自己解决了。谢谢