[wp-hackers] Take 2: Improved template-functions-category.php
Allan Mertner
amwp at mertner.com
Sun Sep 12 22:04:46 UTC 2004
>Sorry, I wasn't clear there. I meant that the class should go on the
><a href> not the <li> which would fit in with your desire to style
>the category name separately from the count and date.
>
>
You were actually quite clear, I just didn't read it correctly - sorry :)
>Yes I should think so.
>
>
Changing the <a> to have a class reference involves a few more changes
than the previous patch so I have attached the diff instead of embedding
it (it becomes hard to read because of line wrapping of long lines). If
that's not ok, I can post it directly in the body as well.
While I was at it, I added a few lines of code so the count and last
post date also are shown for the All category when these options are
enabled. The code shows the count of all "published" posts and as the
date the date of the newest published post.
Thanks,
Allan
-------------- next part --------------
Index: template-functions-category.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/wp-includes/template-functions-category.php,v
retrieving revision 1.39
diff -r1.39 template-functions-category.php
83c83
< $thelist .= '<a href="' . get_category_link(0, $category->category_id, $category->category_nicename) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '">'.$category->cat_name.'</a></li>';
---
> $thelist .= '<a class="cat_item" href="' . get_category_link(0, $category->category_id, $category->category_nicename) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '">'.$category->cat_name.'</a></li>';
86c86
< $thelist .= '<a href="' . get_category_link(0, $category->category_id, $category->category_nicename) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '>';
---
> $thelist .= '<a class="cat_item" href="' . get_category_link(0, $category->category_id, $category->category_nicename) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '>';
94c94
< $thelist .= '<a href="' . get_category_link(0, $category->category_id, $category->category_nicename) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '">'.$category->cat_name.'</a></li>';
---
> $thelist .= '<a class="cat_item" href="' . get_category_link(0, $category->category_id, $category->category_nicename) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '">'.$category->cat_name.'</a></li>';
106c106
< $thelist .= '<a href="' . get_category_link(0, $category->category_id, $category->category_nicename) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '">'.$category->cat_name.'</a>';
---
> $thelist .= '<a class="cat_item" href="' . get_category_link(0, $category->category_id, $category->category_nicename) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '">'.$category->cat_name.'</a>';
109c109
< $thelist .= '<a href="' . get_category_link(0, $category->category_id, $category->category_nicename) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '">';
---
> $thelist .= '<a class="cat_item" href="' . get_category_link(0, $category->category_id, $category->category_nicename) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '">';
115c115
< $thelist .= '<a href="' . get_category_link(0, $category->category_id, $category->category_nicename) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '">'.$category->cat_name.'</a>';
---
> $thelist .= '<a class="cat_item" href="' . get_category_link(0, $category->category_id, $category->category_nicename) . '" title="' . sprintf(__("View all posts in %s"), $category->cat_name) . '">'.$category->cat_name.'</a>';
159c159
< $chain .= '<a href="' . get_category_link(0, $parent->cat_ID, $parent->category_nicename) . '" title="' . sprintf(__("View all posts in %s"), $parent->cat_name) . '">'.$name.'</a>' . $separator;
---
> $chain .= '<a class="cat_item" href="' . get_category_link(0, $parent->cat_ID, $parent->category_nicename) . '" title="' . sprintf(__("View all posts in %s"), $parent->cat_name) . '">'.$name.'</a>' . $separator;
315a316,319
> $all_counts_list = $wpdb->get_results(" SELECT COUNT(*) as all_count FROM $wpdb->posts WHERE post_status='publish'");
> if(! empty($all_counts_list)) {
> $all_counts = $all_counts_list[0]->all_count;
> }
340,353c344,353
< foreach ($cat_dates as $cat_date) {
< $category_lastday["$cat_date->cat_ID"] = $cat_date->lastday;
< $category_lastmonth["$cat_date->cat_ID"] = $cat_date->lastmonth;
< }
< }
<
< if (intval($optionall) == 1 && !$child_of && $categories) {
< $all = apply_filters('list_cats', $all);
< $link = "<a href=\"".$file.$querystring_start.'cat'.$querystring_equal.'all">'.$all."</a>";
< if ($list) {
< echo "\n\t<li>$link</li>";
< } else {
< echo "\t$link<br />\n";
< }
---
> $all_last = 0;
> if (! empty($cat_dates)) {
> foreach ($cat_dates as $cat_date) {
> $lastdate = mktime(0, 0, 0, $cat_date->lastmonth, $cat_date->lastday, $cat_date->lastyear);
> $category_last["$cat_date->cat_ID"] = $lastdate;
> if ($lastdate > $all_last) {
> $all_last = $lastdate;
> }
> }
> }
354a355,375
>
> if (intval($optionall) == 1 && !$child_of && $categories) {
> $all = apply_filters('list_cats', $all);
> $link = "<a class='cat_item' href=\"".$file.$querystring_start.'cat'.$querystring_equal.'all">'.$all."</a>";
>
> // Add count and date for the All link
> if (intval($optioncount) == 1) {
> $link .= '<span class="cat_count"> ('.$all_counts.')</span>';
> }
> if (intval($optiondates) == 1) {
> $link .= ' <span class="cat_date">';
> $link .= date( get_settings('date_format'), $all_last );
> $link .= '</span>';
> }
>
> if ($list) {
> echo "\n\t<li>$link</li>";
> } else {
> echo "\t$link<br />\n";
> }
> }
362c383
< $link = '<a href="'.get_category_link(0, $category->cat_ID, $category->category_nicename).'" ';
---
> $link = '<a class="cat_item" href="'.get_category_link(0, $category->cat_ID, $category->category_nicename).'" ';
379c400
< $link .= '<a href="' . get_category_rss_link(0, $category->cat_ID, $category->category_nicename) . '"';
---
> $link .= '<a class="cat_item" href="' . get_category_rss_link(0, $category->cat_ID, $category->category_nicename) . '"';
404c425
< $link .= ' ('.intval($category_posts["$category->cat_ID"]).')';
---
> $link .= '<span class="cat_count"> ('.intval($category_posts["$category->cat_ID"]).')</span>';
407c428,430
< $link .= ' '.$category_lastday["$category->cat_ID"].'/'.$category_lastmonth["$category->cat_ID"];
---
> $link .= ' <span class="cat_date">';
> $link .= date( get_settings('date_format'), $category_last["$category->cat_ID"] );
> $link .= '</span>';
410c433
< $thelist .= "\t<li>$link\n";
---
> $thelist .= "\t<li>$link\n";
451c474
< ?>
\ No newline at end of file
---
> ?>
More information about the hackers
mailing list