Search

カテゴリーで
親子関係になっている物の
子についてだけエントリーのタイトルを表示する。


 子
 子

 子

の場合SQLで抽出すると

親カテゴリー名 子カテゴリー名 エントリーのタイトル

で表示される。

MySQLの場合



select t1.cat_name,
t2.cat_name,
t4.post_title
from ((wp_categories as t1
inner join wp_categories as t2 on t1.cat_ID = t2.category_parent)
inner join wp_post2cat as t3 on t2.cat_ID = t3.category_id)
inner join wp_posts as t4 on t3.post_id = t4.ID
order by t1.cat_name,t2.cat_name,t4.post_date desc

ループでまわして表示すればOK

Oracleの場合


select t1.cat_name,
t2.cat_name,
t4.post_title
from wp_categories t1
wp_categories t2
wp_post2cat t3,
wp_posts t4
where t1.cat_ID = t2.category_parent
and t2.cat_ID = t3.category_id
and t3.post_id = t4.ID
order by t1.cat_name,t2.cat_name,t4.post_date desc

Something to say?