Nested category list from Philip Taron.

git-svn-id: https://develop.svn.wordpress.org/trunk@848 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Matt Mullenweg 2004-02-09 08:55:29 +00:00
parent e7557946d6
commit e2efe09044
3 changed files with 51 additions and 26 deletions

View File

@ -1,5 +1,50 @@
<?php <?php
function get_nested_categories($default = 0) {
global $post, $tablecategories, $tablepost2cat, $mode, $wpdb;
if ($post->ID) {
$checked_categories = $wpdb->get_col("
SELECT category_id
FROM $tablecategories, $tablepost2cat
WHERE $tablepost2cat.category_id = cat_ID AND $tablepost2cat.post_id = '$post->ID'
");
} else {
$checked_categories[] = $default;
}
$categories = $wpdb->get_results("SELECT * FROM $tablecategories ORDER BY category_parent DESC");
$result = array();
foreach($categories as $category) {
$array_category = get_object_vars($category);
$me = 0 + $category->cat_ID;
$parent = 0 + $category->category_parent;
$array_category['children'] = $result[$me];
$array_category['checked'] = in_array($category->cat_ID, $checked_categories);
$array_category['cat_name'] = stripslashes($category->cat_name);
$result[$parent][] = $array_category;
}
return $result[0];
}
function write_nested_categories($categories) {
foreach($categories as $category) {
echo '<label for="category-', $category['cat_ID'], '" class="selectit"><input value="', $category['cat_ID'],
'" type="checkbox" name="post_category[]" id="category-', $category['cat_ID'], '"',
($category['checked'] ? ' checked="checked"' : ""), '/>', $category['cat_name'], "</label>\n";
if(isset($category['children'])) {
echo "\n<span class='cat-nest'>\n";
write_nested_categories($category['children'], $count);
echo "</span>\n";
}
}
}
function dropdown_categories($default = 0) {
write_nested_categories(get_nested_categories($default));
}
// Dandy new recursive multiple category stuff. // Dandy new recursive multiple category stuff.
function cat_rows($parent = 0, $level = 0, $categories = 0) { function cat_rows($parent = 0, $level = 0, $categories = 0) {

View File

@ -65,6 +65,11 @@ fieldset legend {
padding: .1em; padding: .1em;
} }
fieldset span.cat-nest {
display: block;
margin-left: 10px;
}
form, label input { form, label input {
margin: 0; margin: 0;
padding: 0; padding: 0;
@ -91,8 +96,8 @@ p, dl, dd, dt {
textarea, input, select { textarea, input, select {
background: #f4f4f4; background: #f4f4f4;
color: black;
border: 1px solid #cacaca; border: 1px solid #cacaca;
color: #000;
font-family: Georgia, "Times New Roman", Times, serif; font-family: Georgia, "Times New Roman", Times, serif;
margin: 1px; margin: 1px;
padding: 2px; padding: 2px;

View File

@ -396,31 +396,6 @@ function profile($user_login) {
echo "<a href='profile.php?user=".$user_data->user_login."' onclick=\"javascript:window.open('profile.php?user=".$user_data->user_login."','Profile','toolbar=0,status=1,location=0,directories=0,menuBar=1,scrollbars=1,resizable=0,width=480,height=320,left=100,top=100'); return false;\">$user_login</a>"; echo "<a href='profile.php?user=".$user_data->user_login."' onclick=\"javascript:window.open('profile.php?user=".$user_data->user_login."','Profile','toolbar=0,status=1,location=0,directories=0,menuBar=1,scrollbars=1,resizable=0,width=480,height=320,left=100,top=100'); return false;\">$user_login</a>";
} }
function dropdown_categories($default = 0) {
global $post, $tablecategories, $tablepost2cat, $mode, $wpdb;
$categories = $wpdb->get_results("SELECT * FROM $tablecategories ORDER BY cat_name");
if ($post->ID) {
$postcategories = $wpdb->get_col("
SELECT category_id
FROM $tablecategories, $tablepost2cat
WHERE $tablepost2cat.category_id = cat_ID AND $tablepost2cat.post_id = '$post->ID'
");
} else {
$postcategories[] = $default;
}
foreach($categories as $category) {
++$i;
$category->cat_name = stripslashes($category->cat_name);
echo "\n<label for='category-$i' class='selectit'><input value='$category->cat_ID' type='checkbox' name='post_category[]' id='category-$i'";
if ($postcategories && in_array($category->cat_ID, $postcategories))
echo ' checked="checked"';
echo " /> $category->cat_name</label> ";
}
}
function touch_time($edit = 1) { function touch_time($edit = 1) {
global $month, $postdata, $time_difference; global $month, $postdata, $time_difference;
// echo $postdata['Date']; // echo $postdata['Date'];