【发布时间】:2011-08-02 13:25:49
【问题描述】:
Joomla 有一个名为 Jreviews 的扩展。它有一个模块,以树状结构列出 Joomla 的部分和类别。我想将其转换为双下拉菜单。
我得到了一个脚本,它使 Joomla 网站的部分和类别在一个双下拉列表中。我只需要修改它的结果 URL,使其与 Jreviews 树结构 URL 匹配就可以了。
在脚本中,我发现了这段代码:
var iCatID = document.getElementById('catselect_cat').value;
var iSecID = document.getElementById('catselect_sec').value;
if (iCatID != 0)
**window.location= jsLiveSite+'index.php?option=com_content&view=category&layout=blog&id='+iCatID+'&Itemid='+iItemID;**
else
alert('Please select a section and a category');
在这段代码中,如果我可以用 Jreviews 目录模块 url 替换粗体行,我会得到所需的结果。在我的站点中,Jreviews 目录包含如下类别的 URL:
http://www.yoursite.com/component/jreviews/jreviews_directory_name/section_name/category_name_alias/
当我们有它们的 id 时,有没有办法将部分名称和类别别名存储在一个变量中?
我将发布整个下拉脚本,如下所示:
defined('_JEXEC') or die('Restricted access'); 全球$大型机; $database = & JFactory::getDBO(); $itemid = trim($params->get('linkmenu'));
// 选择已发布的部分 $query = "SELECT s.id, s.title FROM #__sections AS s WHERE s.published=1";
$database->setQuery($query); $sections = $database->loadObjectList();
$query = "SELECT c.id, c.title, c.section FROM #__categories AS c" ."WHERE c.published=1";
$database->setQuery($query); $categories = $database->loadObjectList();
// 生成javascript函数和变量 回声 (" var jsCat = [];
jsCat=[");
foreach ($categories as $item)
{
echo("[".$item->id.",\"".$item->title."\",\"".$item->section."\"],");
}
echo("[0,\"选择类别\",\"0\"]]; \n
var iItemID="); 回声($itemid); 回声(” var jsLiveSite='"); 回声(JURI::base()); 回声("'; \n
函数 jsRemoveAll(cControl) { var cCat = document.getElementById(cControl);
for( var i=(cCat.options.length - 1); i >=0 ; i--)
{
cCat.remove(i);
}
}
函数 jsOnSecSelect() { jsRemoveAll('catselect_cat');
var cSec = document.getElementById('catselect_sec');
var cCat = document.getElementById('catselect_cat');
var iSecID = cSec.options[cSec.selectedIndex].value;
for (var i=0; i<jsCat.length; i++)
{
if (jsCat[i][2] == iSecID)
{
var cOpt = document.createElement(\"option\");
cOpt.value = jsCat[i][0];
cOpt.text = jsCat[i][1];
cOpt.secID = jsCat[i][2];
cCat.options.add(cOpt);
}
}
}
函数 jsOnFormSubmit() {
var iCatID = document.getElementById('catselect_cat').value;
var iSecID = document.getElementById('catselect_sec').value;
if (iCatID != 0)
window.location= jsLiveSite+'index.php?option=com_content&view=category&layout=blog&id='+iCatID+'&Itemid='+iItemID;
else
alert('Please select a section and a category');
} ");
回声(“”); //生成表格 回声(”
选择部分"); foreach ($sections 作为 $item) { echo("id."'>".$item->title." \n" ); } 回声(” \n 选择类别\n \n");
?>
【问题讨论】:
标签: php joomla drop-down-menu