 |
boardom b2 message board
|
View previous topic :: View next topic |
Author |
Message |
Garyamort
Joined: 07 May 2002 Posts: 4
|
Posted: Sun May 12, 2002 6:41 pm Post subject: Messy ListCat hack- display number of posts/date last posted |
|
|
I just made a quick hack for my wife's blog, http://ool.wd1.net/saplings
For the category list, it will display the number of posts in a category and the month/day of the last post.
I haven't cleaned it up yet and am still learning PHP and CSS, so it's bound to have things which could be done better.
First I changed the ListCat's function in the b2template.functions.php, you can replace the whole function with this code:
Quote: |
function list_cats($optionall = 1, $all = "All", $optiondates = 0, $optioncount = 0) {
echo "<p class=storyCategory>";
global $tablecategories,$querycount, $tableposts;
$query="SELECT * FROM $tablecategories";
$result=mysql_query($query);
$querycount++;
if (intval($optionall) == 1) {
echo "\t<a href=\"$PHP_SELF?cat=all\">$all</a>\n";
}
while($row = mysql_fetch_object($result)) {
echo "\t<a href=\"$PHP_SELF?cat=".$row->cat_ID."\">";
echo $row->cat_name."</a>";
if ( (intval($optiondates) == 1) || (intval($optioncount) == 1) ) {
$queryposts="SELECT COUNT(*) as numposts, MONTH(MAX(post_date)) as lastmonth, DAYOFMONTH(MAX(post_date)) as lastday FROM $tableposts WHERE post_category=$row->cat_ID";
$resultposts=mysql_query($queryposts);
$querycountposts++;
$rowposts = mysql_fetch_object($resultposts);
if (intval($optioncount) == 1) {
echo "\t(".$rowposts->numposts.")";
}
if (intval($optiondates) == 1) {
if ($rowposts->lastmonth != "") {
echo "\t<I>".$rowposts->lastmonth."/".$rowposts->lastday."</I>";
}
}
}
echo "<br />\n";
}
echo "</p>";
}
|
The one addition I'm really unsure of is echo "<p class=storyCategory>"; and of course, later echo "</p"
It was my quick and dirty way to stop the number of posts and date from printing in really large font.
Then you just change the function call to ListCats in the index.php file to use the two parameters,
Quote: |
<?php list_cats(0,"All",1,1); ?>
|
You have to stick "All" in as that is the default for the second parm that comes with List_cats(unless you have chosen another option, in which case use your own)
The first 1 after the all tells list_cat's to display the date.
The second 1 tells it to display the number of posts.
If you record the date & time of a person's last visit, this same code could be easily modified to display the number of new posts by simply adding a where clause to the query.[/i] |
|
Back to top |
|
 |
adamwalker
Joined: 07 Apr 2002 Posts: 125 Location: England
|
Posted: Tue May 14, 2002 6:14 pm Post subject: |
|
|
hey i like the hack. ill prob add it to my site soon. dont forget to post when u update it :) _________________ Shameless Plug - For all your B2 template and hack needs visit www.adamwalker.34sp.com |
|
Back to top |
|
 |
mikelittle
Joined: 11 May 2002 Posts: 376 Location: UK
|
Posted: Thu Aug 15, 2002 10:18 pm Post subject: update for 0.6pre4 |
|
|
I've updated this hack for the latest code:
The original from 0.6pre4:
Code: |
function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', $file = 'blah') {
global $tablecategories,$querycount;
global $pagenow;
$file = ($file == 'blah') ? $pagenow : $file;
$sort_column = 'cat_'.$sort_column;
$query="SELECT * FROM $tablecategories WHERE cat_ID > 0 ORDER BY $sort_column $sort_order";
$result=mysql_query($query);
$querycount++;
if (intval($optionall) == 1) {
echo "\t<a href=\"$file?cat=all\">$all</a><br />\n";
}
while($row = mysql_fetch_object($result)) {
echo "\t<a href=\"$file?cat=".$row->cat_ID."\">";
echo stripslashes($row->cat_name)."</a><br />\n";
}
}
|
becomes:
Code: |
function list_cats($optionall = 1, $all = "All", $sort_column = 'ID', $sort_order = 'asc', $file = 'blah',
$optiondates = 0, $optioncount = 0) {
global $tablecategories,$querycount, $tableposts;
global $PHP_SELF;
$file = ($file == 'blah') ? $pagenow : $file;
$sort_column = 'cat_'.$sort_column;
$query="SELECT * FROM $tablecategories WHERE cat_ID > 0 ORDER BY $sort_column $sort_order";
$result=mysql_query($query);
$querycount++;
if (intval($optionall) == 1) {
echo "\t<a href=\"$file?cat=all\">$all</a><br />\n";
}
while($row = mysql_fetch_object($result)) {
echo "\t<a href=\"$file?cat=".$row->cat_ID."\">";
echo $row->cat_name."</a>";
if ( (intval($optiondates) == 1) || (intval($optioncount) == 1) ) {
$queryposts="SELECT COUNT(*) as numposts, MONTH(MAX(post_date)) as lastmonth, DAYOFMONTH(MAX(post_date)) as lastday FROM $tableposts WHERE post_category=$row->cat_ID";
$resultposts=mysql_query($queryposts);
$querycountposts++;
$rowposts = mysql_fetch_object($resultposts);
if (intval($optioncount) == 1) {
echo " (".$rowposts->numposts.")";
}
if (intval($optiondates) == 1) {
if ($rowposts->lastmonth != "") {
echo " ".$rowposts->lastday."/".$rowposts->lastmonth."";
}
}
}
echo "<br />\n";
}
}
|
And to use it, where you used to call:
Code: | <?php list_cats(0, 'All', 'name'); ?> |
You now call:
Code: | <?php list_cats(0, 'All', 'name', 'asc', 'blah', 1, 1); ?> |
Hope this helps.
Mike |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB 2 © 2001, 2002 phpBB Group
|