Joomla 2.5获取子类别的所有ID并在查询中进行子选择 [英] Joomla 2.5 get all Ids of subcategories and do subselect in query

查看:18
本文介绍了Joomla 2.5获取子类别的所有ID并在查询中进行子选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用两个硬坚果绞尽脑汁.因此,这些问题联系在一起,我将它们发布在一个线程中.不幸的是,我无法提供测试示例.来吧……

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,...

  1. 查询为我提供了文章中类别的父类别的 ID('c.parent_id as catparent').是否有可能有一个子选择,它也给了我这个父类别的标题(id 在 catparent 中)?

  1. 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)?

因此,我只想要来自特殊子类别的文章,我的 where 中有一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆