【发布时间】:2013-02-26 12:27:20
【问题描述】:
在我的要求中,我需要将类别页面标题属性设置为我的类别页面标题,但不幸的是,它没有按预期设置,我已经检查了 magento wiki,它们应该是......
我已经尝试通过获取当前类别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:protected] => catalog_category [_eventObject:protected] => 类别 [_cacheTag:protected] => catalog_category [_useFlatResource:protected] => [_designAttributes:Mage_Catalog_Model_Category:private] => 数组( [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 Inkjet Printer Cartridges | Trendsetter [name] => HP Inkjets [url_key] => hp-inkjets [url_path] => printer-consumables/hp/hp-inkjets [is_active] => 1 [available_sort_by] => ) [_storeValuesFlags:protected] => 数组 ( [meta_title] => 1 [name] => 1 [url_key] => 1 [url_path] => 1 [is_active] => 1 [available_sort_by] => 1 ) [_lockedAttributes:protected] => 数组 () [_isDeleteable:protected] => 1 [_isReadonly:protected] => [_resourceName:protected] => 目录/类别 [_resource:protected] => [ _resourceCollectionName:protected] => 目录/category_collection [_dataSaveAllowed:protected] => 1 [_isObjectNew:protected] => [_data:protected] => 数组 ([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 [name] => HP Inkjets [display_mode] => PRODUCTS [meta_title] => HP Inkjets [url_key] => hp-inkjets [url_path] => 打印机耗材/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_layout_update] => [custom_design_from] => [custom_design_to] => [filter_price_range] => ) [_hasDataChanges:protected] => [_origData:protected] => 数组 ( [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 [path] => 1/13/ 520/259/261 [position] => 248 [level] => 2 [children_count] => 0 [name] => HP Inkjets [display_mode] => PRODUCTS [meta_title] => HP Inkjets [url_key] => hp-喷墨 [url_path] => 打印机耗材/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_layout_update] = > [custom_design_from] => [custom_design_to] => [filter_price_range] => ) [_ idFieldName:protected] => entity_id [_isDeleted:protected] => [_oldFieldsMap:protected] => Array () [_syncFieldsMap:protected] => Array ())
并尝试过
echo $catobj->meta_title;
但这也给出了相同的 类别名称 :-(
请帮忙。
我已经调试了类别 obj
print_r($catobj->debug());
但这表明 meta_title 与 name 相同但它不是,它不同.. 真的很烦人
数组([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 [位置] => 248 [级别] => 2 [children_count] => 0 [名称] => HP Inkjets [display_mode] => PRODUCTS [meta_title] => HP Inkjets [url_key] => 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_apply_to_products] => 0 [meta_keywords] => HP 喷墨打印机墨盒 [meta_description] => 以极低的价格提供高品质的 HP 打印机墨水和墨盒。) HP Inkjets
【问题讨论】:
-
你试过了吗? $head = $this->getLayout()->getBlock('head')) { $head->setTitle("你的分类标题"); }
-
@chapagain 非常感谢您的建议,但这就像我在硬编码我需要从类别对象中获取 attr(meta_title) 值的标题,以便我可以在 setTitle 方法中设置...