function ed_classified_page in Classified Ads 6.2
Same name and namespace in other branches
- 5.2 ed_classified.module \ed_classified_page()
- 5 ed_classified.module \ed_classified_page()
- 7.2 ed_classified.module \ed_classified_page()
Display a page of classified ads, as appropriate.
Lifted from image_gallery module. Shameless.
1 string reference to 'ed_classified_page'
- ed_classified.module in ./
ed_classified.module - Simple text-based classified ads module.
File
- ./
ed_classified.module, line 639 - Simple text-based classified ads module.
Code
function ed_classified_page($type = NULL, $tid = 0) {
module_load_include('inc', 'ed_classified', 'ed_classified_utils');
// get a list of categories and counts
$cats = taxonomy_get_tree(_ed_classified_get_vid(), $tid, -1, 1);
for ($i = 0; $i < count($cats); $i++) {
$cats[$i]->count = taxonomy_term_count_nodes($cats[$i]->tid, EDI_CLASSIFIED_MODULE_NAME);
$tree = taxonomy_get_tree(_ed_classified_get_vid(), $cats[$i]->tid, -1);
$descendant_tids = array_merge(array(
$cats[$i]->tid,
), array_map('_taxonomy_get_tid_from_term', $tree));
$last = db_fetch_object(db_query_range(db_rewrite_sql("SELECT n.nid, n.sticky FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN (" . implode(',', $descendant_tids) . ") AND n.status = 1 ORDER BY n.sticky,n.nid DESC, n.created DESC"), 0, 1));
if (isset($last->nid)) {
$cats[$i]->latest = node_load(array(
'nid' => $last->nid,
));
}
}
// TODO: order by created date, #views, what?
$ads = array();
if ($tid) {
# $result = pager_query(db_rewrite_sql("SELECT n.nid FROM {term_node} t INNER JOIN {node} n ON t.nid=n.nid WHERE n.status=1 AND n.type='ed_classified' AND t.tid=%d ORDER BY n.sticky DESC, n.created DESC"), _ed_classified_variable_get('ads_per_page', 10), 0, NULL, $tid);
// The following line from phdhiren works, just not sure how vid is appropriate, but it works (well, vid is overloaded as version and as vocabulary in different contexts)
$result = pager_query(db_rewrite_sql("SELECT n.nid FROM {term_node} t INNER JOIN {node} n ON t.vid=n.vid WHERE n.status=1 AND n.type='ed_classified' AND t.tid=%d ORDER BY n.sticky DESC, n.created DESC", '{term_node}', 'nid'), _ed_classified_variable_get('ads_per_page', 10), 0, NULL, $tid);
while ($node = db_fetch_object($result)) {
$ads[] = node_load(array(
'nid' => $node->nid,
));
}
$classified_cat = taxonomy_get_term($tid);
$parents = taxonomy_get_parents($tid);
foreach ($parents as $parent) {
$breadcrumb[] = l($parent->name, drupal_get_path_alias(_ed_classified_make_category_path($parent->tid)));
}
$breadcrumb[] = l(_ed_classified_displayname(), drupal_get_path_alias(EDI_CLASSIFIED_PATH_NAME));
$breadcrumb = array_reverse($breadcrumb);
drupal_set_title($classified_cat->name);
}
// $breadcrumb[] = l('blah', $_GET['q']);
drupal_set_breadcrumb(empty($breadcrumb) ? array() : $breadcrumb);
// menu_set_location($breadcrumb);
$content = theme('ed_classified_taxonomy', $cats, $ads);
return $content;
}