| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | function get_the_category($id = false) { |
|---|
| 4 | global $post, $category_cache; |
|---|
| 5 | |
|---|
| 6 | if ( !$id ) |
|---|
| 7 | $id = $post->ID; |
|---|
| 8 | |
|---|
| 9 | if ( ! isset($category_cache[$id]) ) |
|---|
| 10 | update_post_category_cache($id); |
|---|
| 11 | |
|---|
| 12 | $categories = $category_cache[$id]; |
|---|
| 13 | |
|---|
| 14 | if (!empty($categories)) |
|---|
| 15 | sort($categories); |
|---|
| 16 | else |
|---|
| 17 | $categories = array(); |
|---|
| 18 | |
|---|
| 19 | return $categories; |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | function get_category_link($category_id) { |
|---|
| 23 | global $wp_rewrite; |
|---|
| 24 | $catlink = $wp_rewrite->get_category_permastruct(); |
|---|
| 25 | |
|---|
| 26 | if ( empty($catlink) ) { |
|---|
| 27 | $file = get_settings('home') . '/' . get_settings('blogfilename'); |
|---|
| 28 | $catlink = $file . '?cat=' . $category_id; |
|---|
| 29 | } else { |
|---|
| 30 | $category = &get_category($category_id); |
|---|
| 31 | $category_nicename = $category->category_nicename; |
|---|
| 32 | |
|---|
| 33 | if ($parent = $category->category_parent) |
|---|
| 34 | $category_nicename = get_category_parents($parent, false, '/', true) . $category_nicename . '/'; |
|---|
| 35 | |
|---|
| 36 | $catlink = str_replace('%category%', $category_nicename, $catlink); |
|---|
| 37 | $catlink = get_settings('home') . trailingslashit($catlink); |
|---|
| 38 | } |
|---|
| 39 | return apply_filters('category_link', $catlink, $category_id); |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | function get_the_category_list($separator = '', $parents='') { |
|---|
| 43 | $categories = get_the_category(); |
|---|
| 44 | if (empty($categories)) { |
|---|
| 45 | return apply_filters('the_category', __('Uncategorized'), $separator, $parents); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | $thelist = ''; |
|---|
| 49 | if ('' == $separator) { |
|---|
| 50 | $thelist .= '<ul class="post-categories">'; |
|---|
| 51 | foreach ($categories as $category) { |
|---|
| 52 | $category->cat_name = $category->cat_name; |
|---|
| 53 | $thelist .= "\n\t<li>"; |
|---|
| 54 | switch(strtolower($parents)) { |
|---|
| 55 | case 'multiple': |
|---|
| 56 | if ($category->category_parent) { |
|---|
| 57 | $thelist .= get_category_parents($category->category_parent, TRUE); |
|---|
| 58 | } |
|---|
| 59 | $thelist .= '<a href="' . get_category_link($category->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '" rel="category tag">'.$category->cat_name.'</a></li>'; |
|---|
| 60 | break; |
|---|
| 61 | case 'single': |
|---|
| 62 | $thelist .= '<a href="' . get_category_link($category->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . ' rel="category tag">'; |
|---|
| 63 | if ($category->category_parent) { |
|---|
| 64 | $thelist .= get_category_parents($category->category_parent, FALSE); |
|---|
| 65 | } |
|---|
| 66 | $thelist .= $category->cat_name.'</a></li>'; |
|---|
| 67 | break; |
|---|
| 68 | case '': |
|---|
| 69 | default: |
|---|
| 70 | $thelist .= '<a href="' . get_category_link($category->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '" rel="category tag">'.$category->cat_name.'</a></li>'; |
|---|
| 71 | } |
|---|
| 72 | } |
|---|
| 73 | $thelist .= '</ul>'; |
|---|
| 74 | } else { |
|---|
| 75 | $i = 0; |
|---|
| 76 | foreach ($categories as $category) { |
|---|
| 77 | $category->cat_name = $category->cat_name; |
|---|
| 78 | if (0 < $i) $thelist .= $separator . ' '; |
|---|
| 79 | switch(strtolower($parents)) { |
|---|
| 80 | case 'multiple': |
|---|
| 81 | if ($category->category_parent) $thelist .= get_category_parents($category->category_parent, TRUE); |
|---|
| 82 | $thelist .= '<a href="' . get_category_link($category->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '" rel="category tag">'.$category->cat_name.'</a>'; |
|---|
| 83 | break; |
|---|
| 84 | case 'single': |
|---|
| 85 | $thelist .= '<a href="' . get_category_link($category->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '" rel="category tag">'; |
|---|
| 86 | if ($category->category_parent) $thelist .= get_category_parents($category->category_parent, FALSE); |
|---|
| 87 | $thelist .= "$category->cat_name</a>"; |
|---|
| 88 | break; |
|---|
| 89 | case '': |
|---|
| 90 | default: |
|---|
| 91 | $thelist .= '<a href="' . get_category_link($category->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '" rel="category tag">'.$category->cat_name.'</a>'; |
|---|
| 92 | } |
|---|
| 93 | ++$i; |
|---|
| 94 | } |
|---|
| 95 | } |
|---|
| 96 | return apply_filters('the_category', $thelist, $separator, $parents); |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | function the_category($separator = '', $parents='') { |
|---|
| 100 | echo get_the_category_list($separator, $parents); |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | function get_the_category_by_ID($cat_ID) { |
|---|
| 104 | $cat_ID = (int) $cat_ID; |
|---|
| 105 | $category = &get_category($cat_ID); |
|---|
| 106 | return $category->cat_name; |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | function get_category_parents($id, $link = FALSE, $separator = '/', $nicename = FALSE){ |
|---|
| 110 | $chain = ''; |
|---|
| 111 | $parent = &get_category($id); |
|---|
| 112 | if ($nicename) { |
|---|
| 113 | $name = $parent->category_nicename; |
|---|
| 114 | } else { |
|---|
| 115 | $name = $parent->cat_name; |
|---|
| 116 | } |
|---|
| 117 | if ($parent->category_parent) $chain .= get_category_parents($parent->category_parent, $link, $separator, $nicename); |
|---|
| 118 | if ($link) { |
|---|
| 119 | $chain .= '<a href="' . get_category_link($parent->cat_ID) . '" title="' . sprintf(__("View all posts in %s"), $parent->cat_name) . '">'.$name.'</a>' . $separator; |
|---|
| 120 | } else { |
|---|
| 121 | $chain .= $name.$separator; |
|---|
| 122 | } |
|---|
| 123 | return $chain; |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | function get_category_children($id, $before = '/', $after = '') { |
|---|
| 127 | global $cache_categories; |
|---|
| 128 | |
|---|
| 129 | if ( ! isset($cache_categories)) |
|---|
| 130 | update_category_cache(); |
|---|
| 131 | |
|---|
| 132 | $c_cache = $cache_categories; // Can't do recursive foreach on a global, have to make a copy |
|---|
| 133 | $chain = ''; |
|---|
| 134 | foreach ($c_cache as $category){ |
|---|
| 135 | if ($category->category_parent == $id){ |
|---|
| 136 | $chain .= $before.$category->cat_ID.$after; |
|---|
| 137 | $chain .= get_category_children($category->cat_ID, $before, $after); |
|---|
| 138 | } |
|---|
| 139 | } |
|---|
| 140 | return $chain; |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | // Deprecated. |
|---|
| 144 | function the_category_ID($echo = true) { |
|---|
| 145 | // Grab the first cat in the list. |
|---|
| 146 | $categories = get_the_category(); |
|---|
| 147 | $cat = $categories[0]->cat_ID; |
|---|
| 148 | |
|---|
| 149 | if ($echo) echo $cat; |
|---|
| 150 | |
|---|
| 151 | return $cat; |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | // Deprecated. |
|---|
| 155 | function the_category_head($before='', $after='') { |
|---|
| 156 | global $currentcat, $previouscat; |
|---|
| 157 | // Grab the first cat in the list. |
|---|
| 158 | $categories = get_the_category(); |
|---|
| 159 | $currentcat = $categories[0]->category_id; |
|---|
| 160 | if ($currentcat != $previouscat) { |
|---|
| 161 | echo $before; |
|---|
| 162 | echo get_the_category_by_ID($currentcat); |
|---|
| 163 | echo $after; |
|---|
| 164 | $previouscat = $currentcat; |
|---|
| 165 | } |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | function category_description($category = 0) { |
|---|
| 169 | global $cat; |
|---|
| 170 | if (!$category) $category = $cat; |
|---|
| 171 | $category = & get_category($category); |
|---|
| 172 | return apply_filters('category_description', $category->category_description, $category->cat_ID); |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | // out of the WordPress loop |
|---|
| 176 | function dropdown_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', |
|---|
| 177 | $optiondates = 0, $optioncount = 0, $hide_empty = 1, $optionnone=FALSE, |
|---|
| 178 | $selected=0, $hide=0) { |
|---|
| 179 | global $wpdb; |
|---|
| 180 | if (($file == 'blah') || ($file == '')) $file = get_settings('home') . '/'; |
|---|
| 181 | if (!$selected) $selected=$cat; |
|---|
| 182 | $sort_column = 'cat_'.$sort_column; |
|---|
| 183 | |
|---|
| 184 | $query = " |
|---|
| 185 | SELECT cat_ID, cat_name, category_nicename,category_parent, |
|---|
| 186 | COUNT($wpdb->post2cat.post_id) AS cat_count, |
|---|
| 187 | DAYOFMONTH(MAX(post_date)) AS lastday, MONTH(MAX(post_date)) AS lastmonth |
|---|
| 188 | FROM $wpdb->categories LEFT JOIN $wpdb->post2cat ON (cat_ID = category_id) |
|---|
| 189 | LEFT JOIN $wpdb->posts ON (ID = post_id) |
|---|
| 190 | WHERE cat_ID > 0 |
|---|
| 191 | "; |
|---|
| 192 | if ($hide) { |
|---|
| 193 | $query .= " AND cat_ID != $hide"; |
|---|
| 194 | $query .= get_category_children($hide, " AND cat_ID != "); |
|---|
| 195 | } |
|---|
| 196 | $query .=" GROUP BY cat_ID"; |
|---|
| 197 | if (intval($hide_empty) == 1) $query .= " HAVING cat_count > 0"; |
|---|
| 198 | $query .= " ORDER BY $sort_column $sort_order, post_date DESC"; |
|---|
| 199 | |
|---|
| 200 | $categories = $wpdb->get_results($query); |
|---|
| 201 | echo "<select name='cat' class='postform'>\n"; |
|---|
| 202 | if (intval($optionall) == 1) { |
|---|
| 203 | $all = apply_filters('list_cats', $all); |
|---|
| 204 | echo "\t<option value='0'>$all</option>\n"; |
|---|
| 205 | } |
|---|
| 206 | if (intval($optionnone) == 1) echo "\t<option value='-1'>".__('None')."</option>\n"; |
|---|
| 207 | if ($categories) { |
|---|
| 208 | foreach ($categories as $category) { |
|---|
| 209 | $cat_name = apply_filters('list_cats', $category->cat_name, $category); |
|---|
| 210 | echo "\t<option value=\"".$category->cat_ID."\""; |
|---|
| 211 | if ($category->cat_ID == $selected) |
|---|
| 212 | echo ' selected="selected"'; |
|---|
| 213 | echo '>'; |
|---|
| 214 | echo $cat_name; |
|---|
| 215 | if (intval($optioncount) == 1) echo ' ('.$category->cat_count.')'; |
|---|
| 216 | if (intval($optiondates) == 1) echo ' '.$category->lastday.'/'.$category->lastmonth; |
|---|
| 217 | echo "</option>\n"; |
|---|
| 218 | } |
|---|
| 219 | } |
|---|
| 220 | echo "</select>\n"; |
|---|
| 221 | } |
|---|
| 222 | |
|---|
| 223 | // out of the WordPress loop |
|---|
| 224 | function wp_list_cats($args = '') { |
|---|
| 225 | parse_str($args, $r); |
|---|
| 226 | if (!isset($r['optionall'])) $r['optionall'] = 0; |
|---|
| 227 | if (!isset($r['all'])) $r['all'] = 'All'; |
|---|
| 228 | if (!isset($r['sort_column'])) $r['sort_column'] = 'ID'; |
|---|
| 229 | if (!isset($r['sort_order'])) $r['sort_order'] = 'asc'; |
|---|
| 230 | if (!isset($r['file'])) $r['file'] = ''; |
|---|
| 231 | if (!isset($r['list'])) $r['list'] = true; |
|---|
| 232 | if (!isset($r['optiondates'])) $r['optiondates'] = 0; |
|---|
| 233 | if (!isset($r['optioncount'])) $r['optioncount'] = 0; |
|---|
| 234 | if (!isset($r['hide_empty'])) $r['hide_empty'] = 1; |
|---|
| 235 | if (!isset($r['use_desc_for_title'])) $r['use_desc_for_title'] = 1; |
|---|
| 236 | if (!isset($r['children'])) $r['children'] = true; |
|---|
| 237 | if (!isset($r['child_of'])) $r['child_of'] = 0; |
|---|
| 238 | if (!isset($r['categories'])) $r['categories'] = 0; |
|---|
| 239 | if (!isset($r['recurse'])) $r['recurse'] = 0; |
|---|
| 240 | if (!isset($r['feed'])) $r['feed'] = ''; |
|---|
| 241 | if (!isset($r['feed_image'])) $r['feed_image'] = ''; |
|---|
| 242 | if (!isset($r['exclude'])) $r['exclude'] = ''; |
|---|
| 243 | if (!isset($r['hierarchical'])) $r['hierarchical'] = true; |
|---|
| 244 | |
|---|
| 245 | list_cats($r['optionall'], $r['all'], $r['sort_column'], $r['sort_order'], $r['file'], $r['list'], $r['optiondates'], $r['optioncount'], $r['hide_empty'], $r['use_desc_for_title'], $r['children'], $r['child_of'], $r['categories'], $r['recurse'], $r['feed'], $r['feed_image'], $r['exclude'], $r['hierarchical']); |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', $file = '', $list = true, $optiondates = 0, $optioncount = 0, $hide_empty = 1, $use_desc_for_title = 1, $children=FALSE, $child_of=0, $categories=0, $recurse=0, $feed = '', $feed_image = '', $exclude = '', $hierarchical=FALSE) { |
|---|
| 249 | global $wpdb, $category_posts; |
|---|
| 250 | // Optiondates now works |
|---|
| 251 | if ('' == $file) { |
|---|
| 252 | $file = get_settings('home') . '/'; |
|---|
| 253 | } |
|---|
| 254 | |
|---|
| 255 | $exclusions = ''; |
|---|
| 256 | if (!empty($exclude)) { |
|---|
| 257 | $excats = preg_split('/[\s,]+/',$exclude); |
|---|
| 258 | if (count($excats)) { |
|---|
| 259 | foreach ($excats as $excat) { |
|---|
| 260 | $exclusions .= ' AND cat_ID <> ' . intval($excat) . ' '; |
|---|
| 261 | } |
|---|
| 262 | } |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | $exclusions = apply_filters('list_cats_exclusions', $exclusions); |
|---|
| 266 | |
|---|
| 267 | if (intval($categories)==0){ |
|---|
| 268 | $sort_column = 'cat_'.$sort_column; |
|---|
| 269 | |
|---|
| 270 | $query = " |
|---|
| 271 | SELECT cat_ID, cat_name, category_nicename, category_description, category_parent |
|---|
| 272 | FROM $wpdb->categories |
|---|
| 273 | WHERE cat_ID > 0 $exclusions |
|---|
| 274 | ORDER BY $sort_column $sort_order"; |
|---|
| 275 | |
|---|
| 276 | $categories = $wpdb->get_results($query); |
|---|
| 277 | } |
|---|
| 278 | if (!count($category_posts)) { |
|---|
| 279 | $now = current_time('mysql', 1); |
|---|
| 280 | $cat_counts = $wpdb->get_results(" SELECT cat_ID, |
|---|
| 281 | COUNT($wpdb->post2cat.post_id) AS cat_count |
|---|
| 282 | FROM $wpdb->categories |
|---|
| 283 | INNER JOIN $wpdb->post2cat ON (cat_ID = category_id) |
|---|
| 284 | INNER JOIN $wpdb->posts ON (ID = post_id) |
|---|
| 285 | WHERE post_status = 'publish' |
|---|
| 286 | AND post_date_gmt < '$now' $exclusions |
|---|
| 287 | GROUP BY category_id"); |
|---|
| 288 | if (! empty($cat_counts)) { |
|---|
| 289 | foreach ($cat_counts as $cat_count) { |
|---|
| 290 | if (1 != intval($hide_empty) || $cat_count > 0) { |
|---|
| 291 | $category_posts["$cat_count->cat_ID"] = $cat_count->cat_count; |
|---|
| 292 | } |
|---|
| 293 | } |
|---|
| 294 | } |
|---|
| 295 | } |
|---|
| 296 | |
|---|
| 297 | if ( $optiondates ) { |
|---|
| 298 | $cat_dates = $wpdb->get_results(" SELECT category_id, |
|---|
| 299 | UNIX_TIMESTAMP( MAX(post_date) ) AS ts |
|---|
| 300 | FROM $wpdb->posts, $wpdb->post2cat |
|---|
| 301 | WHERE post_status = 'publish' AND post_id = ID $exclusions |
|---|
| 302 | GROUP BY category_id"); |
|---|
| 303 | foreach ($cat_dates as $cat_date) { |
|---|
| 304 | $category_timestamp["$cat_date->category_id"] = $cat_date->ts; |
|---|
| 305 | } |
|---|
| 306 | } |
|---|
| 307 | |
|---|
| 308 | $num_found=0; |
|---|
| 309 | $thelist = ""; |
|---|
| 310 | |
|---|
| 311 | if ( $optionall ) |
|---|
| 312 | { |
|---|
| 313 | $link .= '<a href="' . $PHP_SELF . '" title="View all posts">' . |
|---|
| 314 | $all . '</a>'; |
|---|
| 315 | // rss link |
|---|
| 316 | if ( (! empty($feed_image)) || (! empty($feed)) ) { |
|---|
| 317 | |
|---|
| 318 | $link .= ' '; |
|---|
| 319 | |
|---|
| 320 | if (empty($feed_image)) { |
|---|
| 321 | $link .= '('; |
|---|
| 322 | } |
|---|
| 323 | |
|---|
| 324 | $link .= '<a href="' . bloginfo('rss2_url') . '"'; |
|---|
| 325 | |
|---|
| 326 | if ( !empty($feed) ) { |
|---|
| 327 | $title = ' title="' . $feed . '"'; |
|---|
| 328 | $alt = ' alt="' . $feed . '"'; |
|---|
| 329 | $name = $feed; |
|---|
| 330 | $link .= $title; |
|---|
| 331 | } |
|---|
| 332 | |
|---|
| 333 | $link .= '>'; |
|---|
| 334 | |
|---|
| 335 | if (! empty($feed_image)) { |
|---|
| 336 | $link .= "<img src='$feed_image' $alt$title" . ' />'; |
|---|
| 337 | } else { |
|---|
| 338 | $link .= $name; |
|---|
| 339 | } |
|---|
| 340 | |
|---|
| 341 | $link .= '</a>'; |
|---|
| 342 | |
|---|
| 343 | if (empty($feed_image)) { |
|---|
| 344 | $link .= ')'; |
|---|
| 345 | } |
|---|
| 346 | } |
|---|
| 347 | |
|---|
| 348 | // post count |
|---|
| 349 | if (intval($optioncount) == 1) { |
|---|
| 350 | $total_posts = $wpdb->get_results(" SELECT COUNT(ID) AS pc |
|---|
| 351 | FROM $wpdb->posts WHERE post_status = 'publish' |
|---|
| 352 | AND post_date_gmt < '$now' $exclusions"); |
|---|
| 353 | $link .= ' ('. $total_posts[0]->pc .')'; |
|---|
| 354 | } |
|---|
| 355 | // latest post date |
|---|
| 356 | if ( $optiondates ) { |
|---|
| 357 | $max_date = $wpdb->get_results(" SELECT UNIX_TIMESTAMP( MAX(post_date) ) AS ts |
|---|
| 358 | FROM $wpdb->posts |
|---|
| 359 | WHERE post_status = 'publish' |
|---|
| 360 | AND post_date_gmt < '$now' $exclusions"); |
|---|
| 361 | if ( $optiondates == 1 ) $optiondates = 'Y-m-d'; |
|---|
| 362 | $link .= ' ' . gmdate($optiondates, $max_date[0]->ts); |
|---|
| 363 | } |
|---|
| 364 | if ($list) { |
|---|
| 365 | $thelist .= "\t<li>$link\n"; |
|---|
| 366 | } else { |
|---|
| 367 | $thelist .= "\t$link<br />\n"; |
|---|
| 368 | } |
|---|
| 369 | } |
|---|
| 370 | |
|---|
| 371 | foreach ($categories as $category) { |
|---|
| 372 | if ((intval($hide_empty) == 0 || isset($category_posts["$category->cat_ID"])) && (!$hierarchical || $category->category_parent == $child_of) ) { |
|---|
| 373 | $num_found++; |
|---|
| 374 | $link = '<a href="'.get_category_link($category->cat_ID).'" '; |
|---|
| 375 | if ($use_desc_for_title == 0 || empty($category->category_description)) { |
|---|
| 376 | $link .= 'title="'. sprintf(__("View all posts filed under %s"), wp_specialchars($category->cat_name)) . '"'; |
|---|
| 377 | } else { |
|---|
| 378 | $link .= 'title="' . wp_specialchars(apply_filters('category_description',$category->category_description,$category)) . '"'; |
|---|
| 379 | } |
|---|
| 380 | $link .= '>'; |
|---|
| 381 | $link .= apply_filters('list_cats', $category->cat_name, $category).'</a>'; |
|---|
| 382 | |
|---|
| 383 | if ( (! empty($feed_image)) || (! empty($feed)) ) { |
|---|
| 384 | |
|---|
| 385 | $link .= ' '; |
|---|
| 386 | |
|---|
| 387 | if (empty($feed_image)) { |
|---|
| 388 | $link .= '('; |
|---|
| 389 | } |
|---|
| 390 | |
|---|
| 391 | $link .= '<a href="' . get_category_rss_link(0, $category->cat_ID, $category->category_nicename) . '"'; |
|---|
| 392 | |
|---|
| 393 | if ( !empty($feed) ) { |
|---|
| 394 | $title = ' title="' . $feed . '"'; |
|---|
| 395 | $alt = ' alt="' . $feed . '"'; |
|---|
| 396 | $name = $feed; |
|---|
| 397 | $link .= $title; |
|---|
| 398 | } |
|---|
| 399 | |
|---|
| 400 | $link .= '>'; |
|---|
| 401 | |
|---|
| 402 | if (! empty($feed_image)) { |
|---|
| 403 | $link .= "<img src='$feed_image' $alt$title" . ' />'; |
|---|
| 404 | } else { |
|---|
| 405 | $link .= $name; |
|---|
| 406 | } |
|---|
| 407 | |
|---|
| 408 | $link .= '</a>'; |
|---|
| 409 | |
|---|
| 410 | if (empty($feed_image)) { |
|---|
| 411 | $link .= ')'; |
|---|
| 412 | } |
|---|
| 413 | } |
|---|
| 414 | |
|---|
| 415 | if (intval($optioncount) == 1) { |
|---|
| 416 | $link .= ' ('.intval($category_posts["$category->cat_ID"]).')'; |
|---|
| 417 | } |
|---|
| 418 | if ( $optiondates ) { |
|---|
| 419 | if ( $optiondates == 1 ) $optiondates = 'Y-m-d'; |
|---|
| 420 | $link .= ' ' . gmdate($optiondates, $category_timestamp["$category->cat_ID"]); |
|---|
| 421 | } |
|---|
| 422 | if ($list) { |
|---|
| 423 | $thelist .= "\t<li>$link\n"; |
|---|
| 424 | } else { |
|---|
| 425 | $thelist .= "\t$link<br />\n"; |
|---|
| 426 | } |
|---|
| 427 | if ($hierarchical && $children) $thelist .= list_cats($optionall, $all, $sort_column, $sort_order, $file, $list, $optiondates, $optioncount, $hide_empty, $use_desc_for_title, $hierarchical, $category->cat_ID, $categories, 1, $feed, $feed_image, $exclude, $hierarchical); |
|---|
| 428 | if ($list) $thelist .= "</li>\n"; |
|---|
| 429 | } |
|---|
| 430 | } |
|---|
| 431 | if (!$num_found && !$child_of){ |
|---|
| 432 | if ($list) { |
|---|
| 433 | $before = '<li>'; |
|---|
| 434 | $after = '</li>'; |
|---|
| 435 | } |
|---|
| 436 | echo $before . __("No categories") . $after . "\n"; |
|---|
| 437 | return; |
|---|
| 438 | } |
|---|
| 439 | if ($list && $child_of && $num_found && $recurse) { |
|---|
| 440 | $pre = "\t\t<ul class='children'>"; |
|---|
| 441 | $post = "\t\t</ul>\n"; |
|---|
| 442 | } else { |
|---|
| 443 | $pre = $post = ''; |
|---|
| 444 | } |
|---|
| 445 | $thelist = $pre . $thelist . $post; |
|---|
| 446 | if ($recurse) { |
|---|
| 447 | return $thelist; |
|---|
| 448 | } |
|---|
| 449 | echo apply_filters('list_cats', $thelist); |
|---|
| 450 | } |
|---|
| 451 | |
|---|
| 452 | function in_category($category) { // Check if the current post is in the given category |
|---|
| 453 | global $post, $category_cache; |
|---|
| 454 | $cats = ''; |
|---|
| 455 | foreach ($category_cache[$post->ID] as $cat) : |
|---|
| 456 | $cats[] = $cat->cat_ID; |
|---|
| 457 | endforeach; |
|---|
| 458 | |
|---|
| 459 | if ( in_array($category, $cats) ) |
|---|
| 460 | return true; |
|---|
| 461 | else |
|---|
| 462 | return false; |
|---|
| 463 | } |
|---|
| 464 | ?> |
|---|