简体   繁体   中英

Select articles with different catid on joomla 2.5

I have joomla 2.5, where the article contain parent and sub categories. Like below:

  • Article 1 categories are news -> campus -> institute
  • Article 2 categories are news -> campus -> university
  • Article 3 categories are news -> campus -> institute
  • Article 4 categories are news -> campus -> university

in here, news is categories parent of campus, and so on. I know every category has unique catid. But, in database, joomla only record each article based on last category. So, if I want to get articles based on news id, then the result is empty array. So, I must choose institute or university id. But, what I want is how to get article with institute and university categories together.

Is there any one can help me how to solve the problem with php of joomla 2.5?

Categories are stored as Nested Sets . If you retrieve the 'news' category from the database, the columns 'lft' and 'rgt' contain boundary values for all sub-categories. The query

SELECT * FROM #__categories AS category
LEFT JOIN  #__categories AS parent
    ON category.lft BETWEEN parent.lft AND parent.rgt
WHERE parent.id = 3

will give you all sub-categories of the category with the id 3. Use the id of the 'news' category instead.

Please have in mind that the query is in no way optimized and is only intended to illustrate the approach.

If you want to show articles in a module, you may use one of article modules which allow to show content from preselected categories, like the module Articles Category (Options > Filtering Options > Category > institute, university)

If you want to show these articles in main (content) window and not in module:

  1. create new article
  2. put "{loadposition xx} or {loadmodule yyy} code inside (see How do you put a module inside an article? )

If you are interested in used database query, the base is ContentModelArticles model which is used by these modules and menu item Content > Featured articles which allows to preselect categories too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM