2017-05-16 20 views
0

カテゴリを取得したいとMagentoの中でページタイトルに入れた:私はカテゴリを取得し、title.Myに入れたい私はこれは私が(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() ?> 

コードは

?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文を実装しようとしましたが、同じ問題です。

私の英語のために残念です。

答えて

0

このコードを試してください。

<?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() ?> 
+0

私の最初のページの仕事はOKですが、新しい問題があります。私は後で詳しく説明します。 – RobyBoy

+0

オハイオ州私はあなたを手伝ってくれます、あなたはこの答えを受け入れることができますか?ありがとう –

+0

今問題は:私のタイトル私は "最高品質$ _title"になりたいが、カテゴリ "病気"があるとき、それは奇妙な "最高品質の病気"と聞こえる。別の変数とタイトルを "$ _newTitleの商品"に挿入する場合は、最初にifを作成しているのだろうかと思います。 – RobyBoy

5

管理者自身でメタ詳細を管理できます。管理>カタログ>カテゴリの管理を選択します。テンプレートファイルを変更する必要はありません。上記のコード

Manage the meta info

Mage::registry("current_category"); 

現在のカテゴリオブジェクトを返します。したがってカテゴリのものを除くすべてのページでは、上記のレジストリは存在しません。カテゴリページを除くすべてのページでエラーが発生します。

関連する問題