Joomla 2.5 获取子类别的所有 Id 并在查询中进行子选择 [英] Joomla 2.5 get all Ids of subcategories and do subselect in query
问题描述
我用两个硬坚果绞尽脑汁.因此,这些问题是联系在一起的,我将它们发布在一个线程中.不幸的是,我无法提供测试示例.我们开始……
I rack my brain with two hard nuts. Thus the problems are linked together I post them in one thread. Unfortunately I am not able to provide a Test Example. Here we go …
我在 Joomla 2.5 模板中使用以下查询:
I use following Query in my Joomla 2.5 template:
->select(array('a.description','a.display_name','a.parent_id','a.filename','a.url', 'b.title','b.alias', 'b.id','b.catid','b.state','c.title as catTitle','c.parent_id as catparent'))
->from('#__attachments AS a')
->join('LEFT', '#__content AS b ON (a.parent_id = b.id)')
->join('INNER', '#__categories AS c ON b.catid = c.id')
->where("b.state = 1 AND c.parent_id in (23)");
这将模块表#_attachments"与#_content"和#_articles"连接起来.目标是获取文章的附加图片、文章标题、别名、文章 id、类别标题、类别 id,...
this joins me the module table "#_attachments" with "#_content" and "#_articles". with the goal to get the attached images of an article, the title of the article, the alias, the article id, the category title, the category id,...
该查询为我提供了文章类别的父类别的 id('c.parent_id as catparent').是否有可能有一个子选择,它也给我这个父类别的标题(id 在 catparent 中)?
The query gives me the id of the parent category ('c.parent_id as catparent') of the category from the article. Is it possible to have a subselect which also gives me the title of this parent-category (the id is in catparent)?
因此,我只想要来自特殊子类别的文章,我的位置中有in"n.知道所有子类别都是具有 id (5) 的父类别的子类别.如何从 cat 5 中获取子类别的所有 Id.所以我可以在我的b.state = 1 AND c.parent_id in ($allSubCategoryIDs)"where 子句中使用这个 Id?
Thus I only want articles from special subcategories I have an "in"n in my where. know all subcategories are childs of parent category with id (5). How do I get all Id´s of the subcategories from cat 5. So I can use this Id´s in my "b.state = 1 AND c.parent_id in ($allSubCategoryIDs)" where clause?
亲切的问候,
托尼
推荐答案
ad 1.
要获取父类别的标题,添加
To fetch the title of the parent category, add
->select('parent.title AS parentTitle')
->join('left', '#__categories AS parent ON parent.id=c.parent_id')
您的查询.
广告 2.
由于 Joomla 将类别存储为嵌套集,这是通过更改来实现的
Since Joomla stores categories as Nested Sets, this is accomplished by changing
->where("b.state = 1 AND c.parent_id in (23)");
进入
->where('b.state=1')
->where('c.lft BETWEEN parent.lft AND parent.rgt')
这篇关于Joomla 2.5 获取子类别的所有 Id 并在查询中进行子选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!