0'; } if ($cat_id) { $query = "select distinct posts.ID from $wpdb->posts posts left join $wpdb->term_relationships term_relationships on (posts.ID=term_relationships.object_id) left join $wpdb->term_taxonomy term_taxonomy on (term_relationships.term_taxonomy_id=term_taxonomy.term_taxonomy_id) where posts.post_type='post' and (term_taxonomy.term_id=$cat_id or term_taxonomy.parent=$cat_id) and term_taxonomy.taxonomy='category'"; $records = $wpdb->get_results($query); if ($wpdb->last_error) { echo 'error: '.$wpdb->last_error; return; } $posts = array(); foreach ($records as $record) { $posts[] = $record->ID; } $where2 = implode($posts, ','); if ($where2) { $where2 = ' and posts.ID in ('.$where2.') '; } } $query = "select count(posts.ID) from $wpdb->posts posts left join $thanksCountersTable counters on counters.post_id=posts.ID where 1=1 $where1 $where2 and posts.post_type='post'"; $thankedPosts = $wpdb->get_var($query); if ($wpdb->last_error) { echo 'error: '.$wpdb->last_error; return; } $maxNumPages = (int) ($thankedPosts / $rowsPerStatPage); $rest = $thankedPosts / $rowsPerStatPage - $maxNumPages; if ($rest>0) { $maxNumPages += 1; } if ($_GET['paged']>$maxNumPages) { $_GET['paged'] = $maxNumPages; } $fromRecord = max(0,($_GET['paged'] - 1))*$rowsPerStatPage; $query = "select posts.ID, posts.post_title, counters.quant, counters.updated from $wpdb->posts posts left join $thanksCountersTable counters on counters.post_id=posts.ID where 1=1 $where1 $where2 and posts.post_type='post' order by $sortField $sortDir limit $fromRecord, $rowsPerStatPage"; $records = $wpdb->get_results($query); if ($wpdb->last_error) { echo 'error: '.$wpdb->last_error; return; } $foundPosts = count($records); ?>
';
}
$quantSortDirImg = $currentSortDirImg;
$updatedSortDirImg = '';
$linkQuant = add_query_arg('sortdir', $newSortDir, $link);
} else {
if ($sortDir=='asc') {
$newSortDir = 'desc';
$newSortDirTitle = __('descending', 'thankyou');
$currentSortDirTitle = __('Ascending order', 'thankyou');
$currentSortDirImg = '
';
} else {
$newSortDir = 'asc';
$newSortDirTitle = __('ascending', 'thankyou');
$currentSortDirTitle = __('Descending order', 'thankyou');
$currentSortDirImg = '
';
}
$linkUpdated = add_query_arg('sortdir', $newSortDir, $link);
$quantSortDirImg = '';
$updatedSortDirImg = $currentSortDirImg;
}
$newSortDirTitle = sprintf(__('Click to sort in %s order','thankyou'), $newSortDirTitle);
$linkQuant = add_query_arg('sortfield', 'quant', $linkQuant);
$linkUpdated = add_query_arg('sortfield', 'updated', $linkUpdated);
function thShow($linkQuant, $linkUpdated, $newSortDirTitle, $newSortDirTitle, $quantSortDirImg, $updatedSortDirImg) {
?>
| ID; ?> | post_title; ?> | quant) ? $record->quant : 0; ?> |