私は Joomla プロジェクトを持っていますが、ドロップダウン メニュー リストのリンクを変更するのに少し問題があります。
このメニューとその子メニューがあります。
ショップ
- firstcat
- secondcat
- thirdcat
HTML:
<ul class="level2">
<li>
<a id="firstcat" href="/my_website/index.php/shop/firstcat">First Cat</a>
</li>
<li>
<a id="secondcat" href="/my_website/index.php/shop/secondcat">Second Cat</a>
</li>
<li>
<a id="thirdcat" href="/my_website/index.php/shop/thirdcat">Third Cat</a>
</li>
</ul>`
メニュー項目がそのcategory_aliasにリンクされているJoomlaのデフォルト。しかし、メニューをそのcategory_idにリンクしたい. ここで、異なる ID を取得し、データベースで対応する category_id を見つけて、href
in を category_id に置き換えたいと考えています。
このような:
<a id="firstcat" href="/my_website/index.php/shop?16">FirstCat</a>
<a id="secondcat" href="/my_website/index.php/shop?17">SecondCat</a>
<a id="thirdcat" href="/my_website/index.php/shop?18">ThirdCat</a>
Joomlaでファイルを掘り下げてエイリアスをidに置き換えるのに時間がかかるため、JavaScriptまたはjQueryを介してそれを行いたいだけです。
今のところ、私はそれを手動で行うだけです。
$('ul.level2 li a#firstcat').attr('href','/my_website/index.php/shop?catid=16');
$('ul.level2 li a#secondcat').attr('href','/my_website/index.php/shop?catid=17');
$('ul.level2 li a#thirdcat').attr('href','/my_website/index.php/shop?catid=18');
私が彼らのcategory_idを取得しなければならないphpの部分はこれです。
<?php
echo $menuItem->alias . '<br/>';
$db = & JFactory::getDBO();
$db->setQuery('SELECT id FROM #__k2_categories WHERE alias="' . $menuItem->alias . '"');
$result = $db->loadResult();
echo $result;
foreach ($result as $res) {
echo $res->id;
}
?>
$menuItem->alias
-> 現在表示されているアイテムのエイリアスを取得します。