如何从 Joomla 中的 ID 获取部分名称和类别别名?
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 存储在变量中吗?
我将发布整个下拉脚本,如下所示:
define('_JEXEC') 或 die('Restricted access'); 全局$大型机; $数据库=& 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 = "从 #__categories AS c 中选择 c.id、c.title、c.section" ."其中 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()); echo("'; \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');
} ”);
回声(“”); //生成表单 回声(”
Select Section"); foreach ($sections as $item) { echo("id."'>".$item->title." \n" ); } echo(" \n Select Category \n \n”);
?>
There is this extension for Joomla called Jreviews. It has a module which lists the section and categories of Joomla in a tree structure. I wanted to convert it into a double drop down.
I got one script from that makes the section and categories of a Joomla website in a double drop down. I just had to modify its resultant URL, to match it with Jreviews tree structure URL and I would be done.
In the script, there's this piece of code that I discovered:
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');
In this piece of code, if I could replace the bold line with Jreviews directory module url's I would get the required result. In my site, the Jreviews directory has URL's for categories like this:
http://www.yoursite.com/component/jreviews/jreviews_directory_name/section_name/category_name_alias/
Is there a way to store the section name and category alias in a variable when we have their ids?
I'll post the whole drop down script which goes like this:
defined('_JEXEC') or die('Restricted access');
global $mainframe;
$database = & JFactory::getDBO();
$itemid = trim($params->get('linkmenu'));
// select the published sections
$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();
// Generate javascript functions and varaibles
echo ("
var jsCat = [];
jsCat=[");
foreach ($categories as $item)
{
echo("[".$item->id.",\"".$item->title."\",\"".$item->section."\"],");
}
echo("[0,\"Select Category\",\"0\"]]; \n
var iItemID=");
echo($itemid);
echo("
var jsLiveSite='");
echo(JURI::base());
echo("'; \n
function jsRemoveAll(cControl)
{
var cCat = document.getElementById(cControl);
for( var i=(cCat.options.length - 1); i >=0 ; i--)
{
cCat.remove(i);
}
}
function 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);
}
}
}
function 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');
}
");
echo("");
//Generate form
echo("
Select Section");
foreach ($sections as $item)
{
echo("id."'>".$item->title." \n" );
}
echo("
\n
Select Category \n
\n
");
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从您发布的内容来看,您找错了地方。您发布的代码只是从表单中获取值(很可能)并使用它们来创建 URL。此时,在代码中不太可能有与该部分或类别相关的任何其他信息可用。最好的办法是找到创建表单的代码。然后,只需稍微更改查询,甚至仅更改用于创建表单的字段即可。我们需要查看创建下拉菜单的代码,以便为您提供更具体的答案。
From what you have posted, you are looking in the wrong place. The code you posted is simply taking values from a form (most likely) and using them to create the URL. At this point in the code it is unlikely that any other information related to the Section or Category is available. Your best bet is to find the code that creates the form. Then it is a matter of slightly altering the query or even just changing what fields you use to create the forms. We would need to see the code that creates the drop downs to give you a more specific answer.