2013-02-26 76 views
0

在我的要求我需要設置類別頁標題屬性作爲我的類別頁標題,但對於我的一些不幸,它不是如我所料設置檢查的Magento維基他們是它應該...Magento:如何獲得頁面標題屬性(元標題)作爲html頁標題

我已經獲得當前分類ID,然後加載它的頭文件試圖讓meta_title屬性

$current_id= Mage::getModel('catalog/layer')->getCurrentCategory()->getId(); 
$catobj = Mage::getModel('catalog/category')->load($current_id); 
print_r($catobj); 
echo $catobj->getMetaTitle(); 

但是$ catobj-> getMetaTitle()給出類別名稱而不是類別頁面標題:-(

我也曾嘗試打印類別OBJ,看見類別meta_title是有

Mage_Catalog_Model_Category對象([_eventPrefix:保護] => catalog_category [_eventObject:保護] =>類別[_cacheTag:保護] => catalog_category [_useFlatResource:protected] => [_designAttributes:Mage_Catalog_Model_Category:private] => Array([0] => custom_design [1] => custom_design_from [2] => custom_design_to [3] => page_layout [4] => custom_layout_update [5 ] => custom_apply_to_products)[_treeModel:protected] => [_defaultValues:protected] => Array([meta_title] => HP噴墨打印機墨盒| Trendsetter [name] => HP Inkjet [url_key] => hp-inkjets [url_path] => printer-consumables/hp/hp-inkjets [is_active] => 1 [available_sort_by] =>)[_storeValuesFlags:protected] => Array ([meta_title] => 1 [name] => 1 [url_key] => 1 [url_path] => 1 [is_active] => 1 [available_sort_by] => 1)[_lockedAttributes:protected] => Array()[_DeDeteable :保護] => 1 [_isReadonly:保護] => [_resourceName:保護] =>目錄/類別[_resource:保護] => [_resourceCollectionName:保護] =>目錄/ category_collection [_dataSaveAllowed:保護] => 1 [_isObjectNew :protected] => [_data:protected] => Array([entity_id] => 261 [entity_type_id] => 3 [attribute_set_id] => 3 [parent_id] => 259 [created_at] => 2012-12-11 13: 00:28 [updated_at] => 2013-02-26 12:08:33 [路徑] => 1/13/520/259/261 [position] => 248 [level] => 2 [children_count] => 0 [名稱] => HP Inkjet [display_mode] => PRODUCTS [meta_title] => HP Inkjet [url_key] => hp-inkjets [url_path] => printer-consumables/hp/hp-in kjets [custom_design] => [page_layout] => [is_active] => 1 [is_anchor] => 0 [include_in_menu] => 1 [landing_page] => [custom_use_parent_settings] => 0 [custom_apply_to_products] => 0 [available_sort_by] = > [description] => [meta_keywords] =>惠普噴墨打印機墨盒[meta_description] =>高質量惠普打印機墨水和墨盒價格極低。 [custom_layout_update] => [custom_design_from] => [custom_design_to] => [filter_price_range] =>)[_hasDataChanges:protected] => [_origData:protected] => Array([entity_id] => 261 [entity_type_id] => 3 [ 3] [parent_id] => 259 [created_at] => 2012-12-11 13:00:28 [updated_at] => 2013-02-26 12:08:33 [路徑] => 1/13/520/259/261 [position] => 248 [level] => 2 [children_count] => 0 [name] => HP Inkjet [display_mode] => PRODUCTS [meta_title] => HP Inkjet [url_key] => hp- inkjet [url_path] => printer-consumables/hp/hp-inkjets [custom_design] => [page_layout] => [is_active] => 1 [is_anchor] => 0 [include_in_menu] => 1 [landing_page] => [custom_use_parent_settings ] => 0 [custom_apply_to_products] => 0 [available_sort_by] => [description] => [meta_keywords] => HP噴墨打印機墨盒[meta_description] =>高質量HP打印機墨盒和墨盒以極低的價格。[custom_design_from] => [custom_design_to] => [filter_price_range] =>)[_idFieldName:protected] => entity_id [_isDeleted:protected] => [_oldFieldsMap:protected] => Array()[_syncFieldsMap:protected ] =>陣列())


並試圖

echo $catobj->meta_title; 


但是,這也給予同樣的類別名稱 :-( 請這方面的幫助。

我已調試類別OBJ

print_r($catobj->debug()); 

但這表示meta_title是相同的名字,但它不是,其不同..真煩人

陣列([ENTITY_ID] => 261 [entity_type_id] = > 3 [attribute_set_id] => 3 [parent_id] => 259 [created_at] => 2012-12-11 13:00:28 [updated_at] => 2013-02-26 12:08:33 [路徑] => 1 [/ color] [/ color] [/ size] [/ size] [/ size] [/ size] [/ size] [/ size] [/ url] > hp-inkjets [url_path] => printer-consumables/hp/hp-inkjets [is_active] => 1 [is_anchor] => 0 [include_in_menu] => 1 [custom_use_parent_settings] => 0 [custom_app ly_to_products] => 0 [meta_keywords] =>惠普噴墨打印機墨盒[meta_description] =>高質量惠普打印機墨盒和墨盒以極低的價格。 )惠普噴墨打印機

+1

你試過嗎? $ head = $ this-> getLayout() - > getBlock('head')){ $ head-> setTitle(「Your Category Title」); } – 2013-02-26 16:49:53

+0

@chapagain非常感謝您的建議,但這就像我硬編碼我需要從類別對象中獲取attr(meta_title)值的標題,以便我可以在setTitle方法中設置... – ravisoni 2013-02-27 04:53:27

回答

0

那麼通過互聯網搜索後,我發現我的問題的解決方案,商店組是錯誤的。 感謝

+3

This應該是您的問題下面的評論,而不是回答。 – 2013-03-01 05:48:46

0

$ catgId =類別ID

$catSel = Mage::getModel('catalog/category')->load($catgId); 
      $catDesc = array(
      'id' => $catgId, 
      'desc' => $catSel->getDescription(), 
      'url-key' => $catSel->getUrl_key(), 
      'title' => $catSel->getMetaTitle() 
     );