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' => '
'; 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 '
Page '.$current_page.' of '.$count_pages.' (Total: '.$count_comments.' Comments.)
'; Echo 'Order: '.$comment_order.'
Default page: '.$default_comments_page.'
'; Print_R ($defaults); Echo ''; Echo '