我是使用Wordpress的新手,但我理解php代码 .

我有一个'child' functions.php,一个根据url(www.example.com/?catid=123)上的参数( catid )回显类别名称的函数 . 类别名称是从MySQL数据库中检索的,因此子函数内部只是一个SQL语法列表 .

现在,我可以在我的page.php(内容)中正确使用该函数(用一些 if..else 语句回显) . 但它不适用于我的header.php,显然只适用于 <title> 标签 . 我的意思是,如果我只是在我的header.php的任何 <div> 中随机回显,它就可以了 . 但当我试图在 Headers 内回应它时,就像这样

<?php
   if(!isset($_GET['catid'])) { 
      $title= 'use default title set from wp dashboard(wp_title())';
   } else { 
      $title= 'my own title based on categoryid';
   }
?>

<!DOCTYPE html>
<html>
  <meta charset="<?php language_attributes(); ?>" />
   <head>
      <meta charset="<?php bloginfo('charset'); ?>" />
      <title> <?php echo $title; ?> </title>
 //the rest of the header code here

我从'parent'复制了原始page.php(编辑:我的意思是header.php)并将其粘贴到'child'文件夹中 . 我编辑了'child'文件夹中的代码(让我们把它叫做child-page.php(错字,它是child-header.php) .

我做错了什么?我无法在 Headers 标签上显示它 . 页面 Headers 将显示基于 wp_title() 的 Headers (我们从仪表板设置)实际上甚至没有回显 $title 我设置 .