有人能告诉我如何引导用户访问主404文件,而不必打印一条错误消息,说“找不到文件”。php?
例如:
<?php
if (!$myVar) {
// go to 404.php and return an official file not found header
} else {
// show the following HTML
}
?>
有人能告诉我如何引导用户访问主404文件,而不必打印一条错误消息,说“找不到文件”。php?
例如:
<?php
if (!$myVar) {
// go to 404.php and return an official file not found header
} else {
// show the following HTML
}
?>
您可以使用locate_template()
包含404模板的函数。记住这样做,而不是使用get_header()
或产生任何输出;否则,您将有一个副本。
<?php
if ( ! $myVar ) {
status_header(404);
global $wp_query;
$wp_query->is_404 = true;
locate_template(\'404\');
return;
}
// otherwise, show the following HTML
我有一个自定义帖子类型(我在模板页面上使用),自定义帖子类型称为“headerhome”。当我在那里发布一个画廊的帖子时,我试图让它重定向到“单人头家庭”。php”,但它总是转到“单一”。php’。自定义帖子类型本身的名称是任意的,它所在的模板页面的名称是“front page”。php’。我真的很困惑,我在WP方面还不是最好的,所以当像这样简单的东西不起作用时,我不知道如何修复它,即使在翻了一个小时的抄本之后。// Add new post type for homepage add_actio