we have got a category function which generates the list of categories of a blog. now can i get something like this?
o category 1 :: description
o category 2 :: description
o category 3 :: description
we have got a category function which generates the list of categories of a blog. now can i get something like this?
o category 1 :: description
o category 2 :: description
o category 3 :: description
no one?! spooky. anyways to get a subcategory list while inside a category?
I added this function to admin_functions.php:
// Dandy new recursive multiple category stuff. Modified by jcuribe.
function cats_rows($parent = 0, $level = 0, $categories = 0) {
global $wpdb, $tablecategories, $tablepost2cat, $bgcolor;
if (!$categories) {
$categories = $wpdb->get_results("SELECT * FROM $tablecategories ORDER BY cat_name");
}
if ($categories) {
foreach ($categories as $category) {
//Make the Category name link to the posts.
$link = 'cat_ID, $category->category_nicename).'" ';
echo ($link);
if ($category->category_parent == $parent) {
$count = $wpdb->get_var("SELECT COUNT(post_id) FROM $tablepost2cat WHERE category_id = $category->cat_ID");
$pad = str_repeat('Subforum: ', $level);
$bgcolor = ('#c2cdd8 ' == $bgcolor) ? 'none' : '#eee';
echo "<tr><td><img src='./wp-images/logonew.jpg'></td><td style='background-color: $bgcolor' width='685'><font face='Arial' size='2' color='gray'> $pad </font> <font color='#003764' face='Arial'><b><u> $category->cat_name</u></b></font> <br><font size='2' face='Arial'> $category->category_description</font></td>
<td style='background-color: $bgcolor' width='52' align='center'>$count</td>
</tr>";
cats_rows($category->cat_ID, $level + 1);
}
}
} else {
return false;
}
}
Then I used: <?php cats_rows(); ?> to call it.
The output is category title, description, post count. You will have to change the formatting back to a list because I have it in a table.
The function didn't copy and paste properly.
Take out $link = .... and echo ($link) these two lines won't paste properly. Everything else pasted fine. If you need these two lines of code let me know and I will email them.
Could you email this to me? Kathy@kappaluppa.com
Thanks,
K
jcuribe, this is exactly what I'm looking for. Would you be able to email me the code as well? It'd be greatly appreciated. jason=at=jasdonle.com (just take out the equals signs and turn the at into an @)
Thanks,
J
I'd like having this code too.
Can you email me?
jb=at=krylenko.net
Thanks
jb
I used the code from above and edited it to make it a little nicer. And I got around the pasting problem.
<?php
function cats_rows($parent = 0, $level = 0, $categories = 0) {
global $wpdb, $tablecategories, $tablepost2cat, $bgcolor;
if (!$categories) {
$categories = $wpdb->get_results("SELECT * FROM $tablecategories ORDER BY cat_name");
}
if ($categories) {
foreach ($categories as $category) {
if ($category->category_parent == $parent) {
$count = $wpdb->get_var("SELECT COUNT(post_id) FROM $tablepost2cat WHERE category_id = $category->cat_ID");
echo "<a href='/category/$category->category_nicename'>$category->cat_name</a> ($count) - $category->category_description<br />";
cats_rows($category->cat_ID, $level + 1);
}
}
} else {
return false;
}
}
cats_rows(); ?>
You can put this all in a WordPress page, assuming you have RunPHP. You might need to change the link to say something else instead of "category". The one problem is that it shows empty categories. I know there's a way to disable this, but I'm just not sure how.
This topic has been closed to new replies.