这是我要修改的代码(在head.phtml中):
<meta http-equiv="Content-Type" content="<?php echo $this->getContentType() ?>" />
<title><?php echo $this->getTitle() ?></title>
<meta name="description" content="<?php echo htmlspecialchars($this->getDescription()) ?>" />
<meta name="keywords" content="<?php echo htmlspecialchars($this->getKeywords()) ?>" />
<meta name="robots" content="<?php echo htmlspecialchars($this->getRobots()) ?>" />
<link rel="shortcut icon" href="<?php echo $this->getFaviconFile(); ?>" type="image/x-icon" />
<?php echo $this->getCssJsHtml() ?>
<?php echo $this->getChildHtml() ?>
<?php echo $this->getIncludes() ?>
Run Code Online (Sandbox Code Playgroud)
我想获得类别并输入标题.我的代码是:
?php
$currentCategory = Mage::registry("current_category");
?>
<?php $_title = $currentCategory->getName(); ?>
<meta http-equiv="Content-Type" content="<?php echo $this->getContentType() ?>" />
<title><?php echo $_title ?></title>
<meta name="description" content="<?php echo htmlspecialchars($this->getDescription()) ?>" />
<meta name="keywords" content="<?php echo htmlspecialchars($this->getKeywords()) ?>" />
<meta name="robots" content="<?php echo htmlspecialchars($this->getRobots()) ?>" />
link rel="shortcut icon" href="<?php echo $this->getFaviconFile(); ?>" type="image/x-icon" />
<?php echo $this->getCssJsHtml() ?>
<?php echo $this->getChildHtml() ?>
<?php echo $this->getIncludes() ?>
Run Code Online (Sandbox Code Playgroud)
当我在类别项目但主页不再打开它时,它运作良好.我认为$ _title是空的或类似的东西.我试图实现if语句但是同样的问题.
对不起我的英语不好.
您可以从管理员本身管理元详细信息.管理>目录>管理类别.您无需修改任何模板文件.
Mage::registry("current_category");
Run Code Online (Sandbox Code Playgroud)
上面的代码返回当前的类别对象.因此,在除类别之外的所有页面上,上述注册表将不存在.因此除了类别页面之外,您将在所有页面上收到错误.