我想获得类别并在 magento 中放入页面标题
I want to get category and put in the page title in magento
这是我要修改的代码(在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() ?>
我想获取类别并输入 title.My 代码是:
?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() ?>
当我在类别项目中时效果很好,但主页不再打开它。
我认为 $_title 是空的或类似的东西。我尝试执行 if 语句,但还是同样的问题。
对不起我的英语。
请尝试此代码。
<?php if (Mage::registry('current_category')) : ?>
<?php $currentCategory = Mage::registry("current_category"); ?>
<?php $_title = $currentCategory->getName(); ?>
<?php else : ?>
<?php $_title = $this->getTitle(); ?>
<?php endif; ?>
<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() ?>
您可以从管理员本身管理元详细信息。管理 > 目录 > 管理类别。您不需要修改任何模板文件。
Mage::registry("current_category");
以上代码 returns 当前类别对象。因此在除类别页面之外的所有页面上,上述注册表将不存在。所以你会在除类别页面之外的所有页面上出现错误。
这是我要修改的代码(在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() ?>
我想获取类别并输入 title.My 代码是:
?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() ?>
当我在类别项目中时效果很好,但主页不再打开它。 我认为 $_title 是空的或类似的东西。我尝试执行 if 语句,但还是同样的问题。
对不起我的英语。
请尝试此代码。
<?php if (Mage::registry('current_category')) : ?>
<?php $currentCategory = Mage::registry("current_category"); ?>
<?php $_title = $currentCategory->getName(); ?>
<?php else : ?>
<?php $_title = $this->getTitle(); ?>
<?php endif; ?>
<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() ?>
您可以从管理员本身管理元详细信息。管理 > 目录 > 管理类别。您不需要修改任何模板文件。
Mage::registry("current_category");
以上代码 returns 当前类别对象。因此在除类别页面之外的所有页面上,上述注册表将不存在。所以你会在除类别页面之外的所有页面上出现错误。