Nested category list from Philip Taron.
git-svn-id: http://svn.automattic.com/wordpress/trunk@848 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d7c6fe0211
commit
63a6efea29
|
@ -1,5 +1,50 @@
|
|||
<?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.
|
||||
function cat_rows($parent = 0, $level = 0, $categories = 0) {
|
||||
|
|
|
@ -65,6 +65,11 @@ fieldset legend {
|
|||
padding: .1em;
|
||||
}
|
||||
|
||||
fieldset span.cat-nest {
|
||||
display: block;
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
form, label input {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
|
@ -91,8 +96,8 @@ p, dl, dd, dt {
|
|||
|
||||
textarea, input, select {
|
||||
background: #f4f4f4;
|
||||
color: black;
|
||||
border: 1px solid #cacaca;
|
||||
color: #000;
|
||||
font-family: Georgia, "Times New Roman", Times, serif;
|
||||
margin: 1px;
|
||||
padding: 2px;
|
||||
|
|
|
@ -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>";
|
||||
}
|
||||
|
||||
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) {
|
||||
global $month, $postdata, $time_difference;
|
||||
// echo $postdata['Date'];
|
||||
|
|
Loading…
Reference in New Issue