5获取所有子类别的ID并在查询中进行子选择

5获取所有子类别的ID并在查询中进行子选择

本文介绍了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)?

因此,我只想要特殊子类别的文章,而我所在的位置有一个"in" n.知道所有子类别都是ID为(5)的父类别的子类别.如何从类别5中获得所有子类别的ID.那么我可以在"b.state = 1 AND($ allSubCategoryIDs)中的c.parent_id" 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?

亲切的问候,

托尼

推荐答案

广告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并在查询中进行子选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 08:58