get_queried_object(); } Function get_related_posts($limit = -1, $post_id = Null){ Global $post; $limit = IntVal ($limit); If( $post_id == Null && IsSet($post->ID) ) $post_id = $post->ID; Else return False; If( !$arr_tag = wp_get_post_tags($post_id) ) return False; $arr_tag_id = Array(); Foreach( $arr_tag as $tag ) $arr_tag_id[] = $tag->term_id; $query = get_posts (Array( 'tag__in' => $arr_tag_id, 'post__not_in' => Array($post_id), 'numberposts' => $limit )); If (!Empty($query)) return $query; Else return False; } Function get_random_posts($limit = -1){ $limit = IntVal ($limit); $rand_posts =& get_posts (Array( 'orderby' => 'rand', 'numberposts' => $limit, 'post__not_in' => get_option('sticky_posts'), 'caller_get_posts' => 1 )); If ($rand_posts) return $rand_posts; Else return False; } Function show_widget ($sidebar_id, $widget_class_name, $instance = Array(), $widget_args = Array()){ Global $wp_registered_sidebars, $wp_widget_factory; If ( is_string($instance) ) parse_str($instance, $instance); If ( is_string($widget_args) ) parse_str($widget_args, $widget_args); $defaults = array( 'before_widget' => '
  • ', 'after_widget' => "
  • \n", 'before_title' => '

    ', 'after_title' => "

    \n", ); $args = Array_Merge($defaults, (array) $wp_registered_sidebars[$sidebar_id], (array) $widget_args); $args['before_widget'] = SPrintF ( $args['before_widget'], $wp_widget_factory->widgets[$widget_class_name]->id, $wp_widget_factory->widgets[$widget_class_name]->widget_options['classname'] ); the_widget($widget_class_name, $instance, $args); } Function _show_widgets (){ /* Shows all registred Widgets */ Global $wp_widget_factory; Echo '
    '; Print_R ($wp_widget_factory->widgets); Echo '
    '; } Function the_excerpt(){ Echo apply_filters( 'the_excerpt', self::get_the_excerpt() ); } Function get_the_excerpt($post_id = Null){ If ($post_id == Null) $post_id = get_the_ID(); // Get the post $post = &get_post ($post_id); // check if password is required If ( post_password_required($post) ){ $excerpt = __('There is no excerpt because this is a protected post.'); // translation in the core text domain return $excerpt; } If ($post->post_excerpt != ''){ // get the users excerpt $excerpt = $post->post_excerpt; } Else { // Create the excerpt $excerpt = $post->post_content; $excerpt = strip_shortcodes( $excerpt ); $excerpt = apply_filters('the_content', $excerpt); $excerpt = str_replace(']]>', ']]>', $excerpt); $excerpt = strip_tags($excerpt); $excerpt_length = apply_filters('excerpt_length', 55); $excerpt_more = apply_filters('excerpt_more', '[...]'); $words = explode(' ', $excerpt, $excerpt_length + 1); If ( Count($words) > $excerpt_length ){ Array_Pop($words); Array_Push($words, $excerpt_more); $excerpt = Implode(' ', $words); } } // Run filters - there is a bug if you try to run an empty excerpt through the filter If ($excerpt != '') $excerpt = apply_filters('get_the_excerpt', $excerpt); return $excerpt; } Function get_page_path($post_id = Null){ If ($post_id == Null){ Global $post; $post_id = $post->ID; } $post_parent = get_post($post_id); $arr_path = Array(); $arr_path[] = $post_parent->post_title; While ($post_parent->post_parent != 0){ $post_parent_id = $post_parent->post_parent; $post_parent =& get_post($post_parent_id); // Add the post title to the array $arr_path[] = ''.$post_parent->post_title.''; } // Inverse the path elements to get the right result $arr_path = Array_Reverse ($arr_path); return $arr_path; } Function get_post_attached_image($post_id = Null, $number = 1, $orderby = 'RAND', $image_size = 'thumbnail'){ If ($post_id == Null) $post_id = get_the_id(); $number = IntVal ($number); $arr_attachment = get_posts (Array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'numberposts' => $number, 'post_mime_type' => 'image', 'orderby' => $orderby )); // Check if there are attachments If (Empty($arr_attachment)) return False; // Convert the attachment objects to urls ForEach ($arr_attachment AS $index => $attachment){ $arr_attachment[$index] = wp_get_attachment_image_src ($attachment->ID, $image_size); /* Return Values An array containing: $image[0] => url $image[1] => width $image[2] => height */ } return $arr_attachment; } Function get_post_thumbnail($post_id = Null, $size = 'thumbnail'){ If ($post_id == Null){ Global $post; $post_id = $post->ID; } // Try to find a thumbnail of the post If (Function_Exists('get_post_thumbnail_id') && $thumb = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), $size)){ // If the user has set a post thumb we use it return $thumb; } Else { // If there is now thumb we use a random image from this post $arr_attachment = (Array) get_posts (Array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'numberposts' => -1, 'post_mime_type' => 'image', 'orderby' => 'ASC' )); // Check if there are attachments If (Empty($arr_attachment)) return False; Shuffle ($arr_attachment); $thumb = wp_get_attachment_image_src($arr_attachment[0]->ID, $size); /* Return Value: An array containing: $image[0] => url $image[1] => width $image[2] => height */ } // If we found a thumb we use it If (!Empty($thumb)) return $thumb; Else return False; } Function get_response ($post_id = Null, $args = Array()){ $arr_comment = Array(); $arr_trackback = Array(); $comment_count = 0; $trackback_count = 0; If ($post_id == Null) $post_id = get_the_id(); $page_comments = (get_option('page_comments') == '1'); // true OR false - split comments to pages or not $comments_per_page = AbsInt ( get_option('comments_per_page') ); // number of comments per page $default_comments_page = StrToLower (get_option('default_comments_page')); // oldest OR newest $comment_order = StrToUpper (get_option('comment_order')); // the order of the comments - ASC OR DESC $count_pages = get_comment_pages_count(); // Number of total pages $count_comments = get_comments_number($post_id); // Counts the current number of comments $current_page = AbsInt ( get_query_var('cpage') ); // current page. starts with 1. $defaults = Array( 'status' => 'approve', 'orderby' => 'comment_date_gmt', 'order' => $comment_order, 'number' => $page_comments ? $comments_per_page : '', 'offset' => '', 'post_id' => $post_id ); // If the comments are paged we have to recalculate something manualy // Last page display by default, older comments at the top If ($page_comments && $default_comments_page == 'newest' && $comment_order == 'ASC'){ // The oldest comments should be shown on the first page and the oldest ones on top $defaults['offset'] = $count_comments - ($count_pages - $current_page + 1) * $comments_per_page; If ($defaults['offset'] < 0){ // If we are on the last page of comments the offset can be less than 0 so there are not enougth comments left to fill the page. // So we will only show the remaining comments $defaults['number'] += $defaults['offset']; $defaults['offset'] = 0; } } // First page display by default, older comments at the top ElseIf ($page_comments && $default_comments_page == 'oldest' && $comment_order == 'ASC'){ // The newest comments should be shown on the first page but the oldest ones on top $defaults['offset'] = ($current_page - 1) * $comments_per_page; } // Last page display by default, newer comments at the top ElseIf ($page_comments && $default_comments_page == 'newest' && $comment_order == 'DESC'){ $defaults['offset'] = ($count_pages - $current_page) * $comments_per_page; } // First page display by default, newer comments at the top ElseIf ($page_comments && $default_comments_page == 'oldest' && $comment_order == 'DESC'){ $defaults['offset'] = $count_comments - ($current_page * $comments_per_page); If ($defaults['offset'] < 0){ // If we are on the last page of comments the offset can be less than 0 so there are not enougth comments left to fill the page. // So we will only show the remaining comments $defaults['number'] += $defaults['offset']; $defaults['offset'] = 0; } } /* This is just for debuging while developing Echo '
    '; Echo '

    Page '.$current_page.' of '.$count_pages.' (Total: '.$count_comments.' Comments.)

    '; Echo '

    Order: '.$comment_order.'
    Default page: '.$default_comments_page.'

    '; Echo '

    '; Print_R ($defaults); Echo '

    '; Echo '
    '; */ $args = Array_Merge($defaults, $args); ForEach( (Array) get_comments($args) AS $comment ){ If (get_option('thread_comments') && $comment->comment_parent != 0) Continue; If ($comment->comment_type == ''){ // This is a comment and not a trackback ;) // check if the comment were composed by an user if ($user = get_userdata($comment->user_id)){ // there is a user with this id $comment->comment_author = $user->display_name; $comment->comment_author_email = $user->user_email; $comment->comment_url = $user->user_url; $comment->author_is_user = True; } else { $comment->author_is_user = False; } } // get comment classes $comment->class = get_comment_class(Null, $comment->comment_ID); // Remove the odd and even classes If (($key = Array_Search('odd', $comment->class)) !== False) Unset ($comment->class[$key]); If (($key = Array_Search('even', $comment->class)) !== False) Unset ($comment->class[$key]); If (($key = Array_Search('thread-odd', $comment->class)) !== False) Unset ($comment->class[$key]); If (($key = Array_Search('thread-even', $comment->class)) !== False) Unset ($comment->class[$key]); // comment time $comment->comment_date = StrToTime($comment->comment_date); // Seperate comments and trackbacks If ($comment->comment_type == ''){ // This is a comment and not a trackback ;) // We count the number of comments to ascertain if the we'll add the even or odd class If (++$comment_count % 2 == 1) $comment->class[] = 'odd'; Else $comment->class[] = 'even'; // Store in Array $arr_comment[] = $comment; } Else { // This is a trackback and not a comment ;) // We count the number of comments to ascertain if the we'll add the even or odd class If (++$trackback_count % 2 == 1) $comment->class[] = 'odd'; Else $comment->class[] = 'even'; // Add trackback and pingback classes $comment->class[] = 'trackback'; $comment->class[] = 'pingback'; $comment->class = Array_Unique ($comment->class); // Store in Array $arr_trackback[] = $comment; } } // Set the empty Arrays to FALSE (bool) If (Empty ($arr_comment)) $arr_comment = False; If (Empty ($arr_trackback)) $arr_trackback = False; return Array($arr_comment, $arr_trackback); } Function get_comments ($args = Array()){ List ($arr_comment, $arr_trackback) = self::get_response($args); return $arr_comment; } Function get_trackbacks ($args = Array()){ List ($arr_comment, $arr_trackback) = self::get_response($args); return $arr_trackback; } Function print_comment($comment, $args, $depth){ $GLOBALS['comment'] = $comment; If ($comment->comment_type == ''){ // This is a comment and not a trackback ;) // check if the comment were composed by an user if ($user = get_userdata($comment->user_id)){ // there is a user with this id $comment->comment_author = $user->display_name; $comment->comment_author_email = $user->user_email; $comment->comment_url = $user->user_url; $comment->author_is_user = True; } else { $comment->author_is_user = False; } } // get comment classes $comment->class = get_comment_class(Null, $comment->comment_ID); // comment time #$comment->comment_date = StrToTime($comment->comment_date); // Load comment template If (get_query_template('comment')) Include get_query_template('comment'); Else return False; } Function print_trackback($trackback, $args, $depth){ $GLOBALS['comment'] = $trackback; // get comment classes $trackback->class = get_comment_class(Null, $trackback->comment_ID); // Add trackback and pingback classes $trackback->class[] = 'trackback'; $trackback->class[] = 'pingback'; $trackback->class = Array_Unique ($trackback->class); // comment time #$trackback->comment_date = StrToTime($trackback->comment_date); // Load template If (get_query_template('trackback')) Include get_query_template('trackback'); Else return False; } Function count_comments($type = 'comment'){ Global $wp_query; $arr_comment = separate_comments($wp_query->comments); If (IsSet($arr_comment[$type])) return Count($arr_comment[$type]); Else return False; } Function get_theme_plugins(){ $wp_plugins = array (); $plugin_root = TEMPLATEPATH.'/plugins/'; If (!$plugins_dir = @opendir( $plugin_root)) return False; $plugin_files = array(); Require_Once ABSPATH.'wp-admin/includes/plugin.php'; while (($file = readdir( $plugins_dir ) ) !== false ){ // Check all items out of the directory if ( substr($file, 0, 1) == '.' ) continue; // Check if the current item is a dir if ( is_dir( $plugin_root.'/'.$file ) ) { // read sub dir If (!$plugins_subdir = @opendir( $plugin_root.'/'.$file )) Continue; while (($subfile = readdir( $plugins_subdir ) ) !== false ) { if ( substr($subfile, 0, 1) == '.' ) continue; if ( substr($subfile, -4) == '.php' ) $plugin_files[] = "$file/$subfile"; } closedir( $plugins_subdir ); } // The current item is a file else { // Check if this is a php file if ( substr($file, -4) == '.php' ) $plugin_files[] = $file; } } closedir( $plugins_dir ); if ( !$plugins_dir || empty($plugin_files) ) return $wp_plugins; foreach ( $plugin_files as $plugin_file ) { if ( !is_readable( "$plugin_root/$plugin_file" ) ) continue; $plugin_data = get_plugin_data( "$plugin_root/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached. if ( empty ( $plugin_data['Name'] ) ) continue; $wp_plugins[plugin_basename( $plugin_file )] = $plugin_data; } uasort( $wp_plugins, create_function( '$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );' )); return $wp_plugins; } Function include_theme_plugins(){ $arr_plugins = self::get_theme_plugins(); ForEach ($arr_plugins AS $file => $data){ Include_Once TEMPLATEPATH.'/plugins/'.$file; } } Function show_sidebar ($adjustment, $sidebar_before, $sidebar_after, $sidebar_name = ''){ $sidebar_adjustment = Get_Theme_Setting('sidebar_adjustment'); If ($sidebar_adjustment == '') $sidebar_adjustment = 'right'; If ($sidebar_adjustment == $adjustment){ Echo $sidebar_before; get_sidebar($sidebar_name); Echo $sidebar_after; } } } /* End of File */