在我的 magento 商店中,需要在Side bar中将 meta 标签实现为url。
我的商店有两种类别。命名为 X 和 Y。
我需要得到这种类型的结果。
X -> 类别X
-x1 -x2 -x3
-> Catogery X关键字需要作为 url
Y -> Y类
-y1 -y2 -y3
-> 类别Y关键字需要作为 url
帮我解决这个问题。
现在我正在使用这段代码
<div class="right-tab-middle">
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if (count($_categories) > 0): ?>
<ul style="overflow:hidden;">
<div style="color:#BE0171;text-decoration:underline; font-size:16px; font-weight:bold;">Shop by:</div>
<!-- <?php foreach($_categories as $_category): ?>
<li style="margin:10px 0px; ">
<a style="color:#BE0171; text-decoration:none;" href="<?php echo $_helper->getCategoryUrl($_category) ?>">
<?php echo $_category->getName() ?>
</a>
<?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
<?php $_subcategories = $_category->getChildrenCategories() ?>
<?php if (count($_subcategories) > 0): ?>
<ul>
<?php foreach($_subcategories as $_subcategory): ?>
<li style="margin:5px 0px 5px 10px; ">
<a style="color:#BE0171; text-decoration:none;" href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
<?php echo $_subcategory->getName() ?><br />
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?> -->
<?php
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$sql = "SELECT GROUP_CONCAT( value SEPARATOR ' ' ) as keywords FROM mag_catalog_product_entity_text WHERE attribute_id=(SELECT attribute_id FROM mag_eav_attribute WHERE attribute_code='meta_keyword')" ;
$rows = $connection->fetchAll($sql);
$metaKeywords = $rows[0]['keywords'];
//strip white space and replace with _
$str = preg_replace('/\s+/', ' ',$metaKeywords);
//$str = str_replace(' ','*',$metaKeywords);
$arr = explode(" ", $str);
$arr = array_count_values($arr);
arsort($arr);
$i = 0;
foreach($arr as $data => $val)
{
if($i<=30)
{
?>
<li style="margin:10px 6px 10px 0px; float:left!important; ">
<a href="<?php echo $this->getUrl('keywords/view/products/key/') ?><?php echo $data; ?>" style="color:#BE0171; text-decoration:none;"> <?php echo $data; ?>
</a>
</li>
<?php
$i++;
}
else
{
break;
}
}
?>
</ul>
<?php endif; ?>
</div>
XY
-x1-y1-x2-y2 -> 所有关键字都显示在此代码中。
但我需要执行上述命令。