gen_get_parent_id ... for the guys that don't have the page tools plugin installed (Thanks to Krischan, again :)) Released under the GPL license http://www.gnu.org/licenses/gpl.txt This file is part of WordPress. WordPress is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * gen_the_time * Same as the_time but echoes nothing. A string is returned instead. */ function gen_the_time( $d = '' ) { return apply_filters('the_time', get_the_time( $d ), $d); } /* * gen_bloginfo * Same as bloginfo but echoes nothing. A string is returned instead. */ function gen_bloginfo($show='') { $info = get_bloginfo($show); $info = apply_filters('bloginfo', $info, $show); return convert_chars($info); } /* * gen_get_parents * - $before, $after are chunks of text (HTML) that are placed before * and after the link to each page. (-> page tools) * * Prints HTML with links to the parents of the current page. */ function gen_get_parents( $args = '', $value = '', $before = "\n\n" ) { global $id; $result = ''; $home = ''; parse_str($args, $r); if (!isset($r['title'])) { $r['title'] = 'Trace'; } if (!empty($r['title'])) { $result .= "
  • \n

    " . $r['title'] . "

    \n"; } $home = 'home'; if (gen_is_page($id)) { $result .= $before . $home . __gen_get_parents($id, 0, $value, $before, $after) . $after; } else { $result .= $before . $home . $after; } if (!empty($r['title'])) { $result .= '
  • '; } return $result; //($id != 1 ? $result : ''); } function __gen_get_parents($id, $depth, $value, $before, $after) { $result = $value; $links = array(); if (($id > 0)) {// && (is_page($id))) { $link = get_permalink( $id ); $title = get_the_title( $id ); if ($depth == 0) { $result = $before . $title . $value . $after; } else { $result = $before . '' . $title . '' . $value . $after; } $result = __gen_get_parents(page_get_parent_id($id), $depth + 1, $result, $before, $after); } return $result; } /* * gen_get_children * - $before, $after are chunks of HTML that will be placed before * and after the link to each page. * * Prints HTML with links to the children of the current page. */ function gen_get_children ( $before = "
  • ", $after = "
  • " ) { global $id; $children = gen_get_child_ids( $id ); $links = array(); if ( ! $children ) return; foreach ( $children as $child ) { $cid = $child->ID; if ( $cid == 0 ) next; $link = get_permalink( $cid ); $title = get_the_title( $cid ); $links[] = "$title"; } $s = ""; foreach ( $links as $link ) { $s .= $before.$link.$after."\n"; } return $s; } /* * gen_get_child_ids * - $parent the ID of the parent page * - returns an associative array containing the IDs of the children * of the parent page */ function gen_get_child_ids ( $parent = 0 ) { global $wpdb; // Return if no ID was specified. if ( $parent == 0 ) return 0; // Get the ID of the parent. return $wpdb->get_results(" SELECT ID FROM $wpdb->posts WHERE post_parent = $parent AND post_status = 'static' ORDER BY menu_order, post_title "); } function gen_is_page($page = 0) { global $wpdb; if ($page > 0) { $result = $wpdb->get_results(" SELECT ID FROM $wpdb->posts WHERE ID = $page AND post_status = 'static'"); return (!empty($result)); } return false; } function gen_last_modified($page = 0, $gmt = false) { global $wpdb; $result = 0; $format = get_settings('date_format'); if ($page > 0) { $ts = $wpdb->get_var(" SELECT post_modified FROM $wpdb->posts WHERE ID = $page"); $result = mysql2date($format, $ts); } return apply_filters('get_the_time', $result, $format, $gmt); } function gen_get_parent_id($page) { global $wpdb; if ($page > 0) { $parent = $wpdb->get_var("SELECT post_parent FROM $wpdb->posts WHERE ID=$page"); if ($parent) { return $parent; } } return -1; } function gen_get_page_id() { global $wp_query; if (is_home()) { return 0; } else { return $wp_query->post->ID; } } /* * Same as _page_level_out except that an additional parameter is accepted: mark_id. * It can be used to mark active pages in a page tree... */ function gen_page_level_out($parent, $page_tree, $args, $depth = 0, $echo = true) { global $wp_query; $queried_obj = $wp_query->get_queried_object(); $output = ''; $mark = -1; if (isset($args['mark_id'])) { $mark = $args['mark_id']; } if($depth) $indent = str_repeat("\t", $depth); //$indent = join('', array_fill(0,$depth,"\t")); if (isset($page_tree[$parent]['children'])) { foreach($page_tree[$parent]['children'] as $page_id) { $cur_page = $page_tree[$page_id]; $title = $cur_page['title']; $css_class = 'page_item'; if (($page_id == $queried_obj->ID) || ($mark == $page_id)) { $css_class .= ' current_page_item'; } $output .= $indent . '
  • ' . $title . ''; if(isset($cur_page['ts'])) { $format = get_settings('date_format'); if(isset($args['date_format'])) $format = $args['date_format']; $output .= " " . mysql2date($format, $cur_page['ts']); } echo "\n"; if(isset($cur_page['children']) && is_array($cur_page['children'])) { $new_depth = $depth + 1; if(!$args['depth'] || $depth < ($args['depth']-1)) { $output .= "$indent\n"; } } $output .= "$indent
  • \n"; } if ( $echo ) echo $output; else return $output; } } function gen_get_permalink($id) { if ($id == 0) { return get_settings('home') . "/"; } else if ($id == -1) { return NULL; } else { return get_permalink($id); } } ?>