In order to produce an index page of posts by category I did the following in the home.php file of my theme:
I query the database like so:
$wpdb->get_results("SELECT DISTINCT cat_name,cat_ID,category_nicename FROM $wpdb->categories, $wpdb->post2cat WHERE $wpdb->categories.cat_ID = $wpdb->post2cat.category_id ORDER BY cat_name ASC");
and then did a foreach loop over the result. I then
1) call query_posts
2) run The Loop
on each iteration of the foreach loop.
This works, what I want to know is if this is a stable, efficient and generally sensible way of doing it. I did get a MySQL error 28 but I gather than is probably the hosts fault, should I expect any other problems or should I be comfortable with this?
- The topic ‘Looping over categories’ is closed to new replies.