Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if( !function_exists('yg_recentposts')) {
- function yg_recentposts($args = '', $echo = true) {
- global $wpdb;
- $defaults = yg_recentposts_defaults();
- $args = wp_parse_args( $args, $defaults );
- extract($args);
- $hideposttitle = (bool) $hideposttitle;
- $separator = $separator;
- $afterexcerpt = $afterexcerpt;
- $afterexcerptlink = (bool) $afterexcerptlink;
- $show_type = $show_type;
- $shownum = (int) abs($shownum);
- if(isset($limit) && $shownum == 10) $shownum = (int) $limit;
- $postoffset = (int) abs($postoffset);
- $reverseorder = (int) abs($reverseorder);
- $firstimage = (bool) $firstimage;
- $showauthor = (bool) $showauthor;
- $showtime = (bool) $showtime;
- $spot = esc_attr($spot);
- $atimage = (bool) $atimage;
- $defimage = esc_url($defimage);
- $format = esc_attr($format);
- $time = '';
- $width = (int) $width;
- $height = (int) $height;
- $w = (int) $w;
- $h = (int) $h;
- if ($width > $w) {
- $width = $width; $height = $height;
- } else {
- $width = $w; $height = $h;
- }
- $excerptlength = (int) abs($excerpt);
- $excerptlengthwords = (int) abs($excerptlengthwords);
- $excerpt = '';
- $cats = str_replace(" ", "", esc_attr($cats));
- if (($shownum < 1 ) || ($shownum > 20)) $shownum = 10;
- if (($actcat) && (is_category())) {
- $cats = get_query_var('cat');
- }
- if (($actcat) && (is_single())) {
- $cats = '';
- foreach (get_the_category() as $catt) {
- $cats .= $catt->cat_ID.' ';
- }
- $cats = str_replace(" ", ",", trim($cats));
- }
- if (!intval($cats)) $cats='';
- $query = "cat=$cats&showposts=$shownum&post_type=$show_type&offset=$postoffset";
- $posts = get_posts($query); //get posts
- if ($reverseorder) $posts = array_reverse($posts);
- $postlist = '';
- $height = $height ? ' height: ' . $height .'px;' : '';
- $width = $width ? ' width: ' . $width . 'px;' : '';
- $hw = (!empty($height) || !empty($width)) ? 'style="'.$width.$height.'"' : '';
- foreach ($posts as $post) {
- if ($showtime) { $time = ' '. date($format,strtotime($post->post_date)); }
- $post_title = stripslashes($post->post_title);
- if ($excerptlength) {
- $excerpt = $post->post_excerpt;
- $text = $post->post_content;
- $text = strip_shortcodes( $text );
- $text = str_replace(']]>', ']]>', $text);
- $text = strip_tags($text);
- $excerpt_length = 100;
- $words = explode(' ', $text, $excerpt_length + 1);
- if ( '' == $excerpt ) {
- if (count($words) > $excerpt_length) {
- array_pop($words);
- $text = implode(' ', $words);
- }
- $excerpt = $text;
- }
- $afterexcerpt_html = '';
- // Original code for Advanced Recent Posts Mod
- // if ($afterexcerptlink) $afterexcerpt_html = '<a href="' . get_permalink($post->ID) . '">' . $afterexcerpt . '</a>';
- // Customised display fixes for Advanced Recent Posts Mod
- if ($afterexcerptlink)
- $afterexcerpt_html = '<span class="special_read_more_link">
- <br />
- <br />
- <strong>
- <span style="color: #7030a0;">></span><span style="color: #808080;">></span>
- </strong>
- <a href="' . get_permalink($post->ID) . '">' . $afterexcerpt . '</a></span>';
- // End of customised display
- else $afterexcerpt_html = $afterexcerpt;
- if ($excerptlengthwords > 0 ) {
- $words = array_splice($words, 0, $excerptlengthwords);
- $excerpt = implode(' ', $words);
- }elseif(strlen($excerpt) > $excerptlength) {
- $excerpt = mb_substr($excerpt, 0, $excerptlength);
- }
- $excerpt = $separator . ($spot == 'spot3' ? '<span class="date">'.$time.'</span> ' : '') . $excerpt . $afterexcerpt_html;
- }
- $image = '';
- $img = '';
- if ($cusfield) {
- $cusfield = esc_attr($cusfield);
- $img = get_post_meta($post->ID, $cusfield, true);
- }
- if (!$img && $firstimage) {
- $match_count = preg_match_all("/<img[^']*?src=\"([^']*?)\"[^']*?>/", $post->post_content, $match_array, PREG_PATTERN_ORDER);
- $img = count($match_array['1']) > 0 ? $match_array[1][0] : false;
- }
- if (!$img && $atimage) {
- $p = array(
- 'post_type' => 'attachment',
- 'post_mime_type' => 'image',
- 'numberposts' => 1,
- 'order' => 'ASC',
- 'orderby' => 'menu_order ID',
- 'post_status' => null,
- 'post_parent' => $post->ID
- );
- $attachments = get_posts($p);
- if ($attachments) {
- $imgsrc = wp_get_attachment_image_src($attachments[0]->ID, 'thumbnail');
- $img = $imgsrc[0];
- }
- }
- if (!$img && $defimage)
- $img = $defimage;
- // Customised display fixes for Advanced Recent Posts Mod
- $postlist .= '<li>'.($spot == 'spot1' ? '<span class="date">'.$time.'</span> ' : '');
- if (!$hideposttitle) $postlist .= '<a href="' . get_permalink($post->ID) . '" title="'. $post_title .'" >' . $post_title .'</a>';
- $author_data = get_userdata($post->post_author);
- $postlist .= ($showauthor ? ' by '.$author_data->display_name : '') . ($spot == 'spot2' ? ' <span class="date">'.$time.'</span>' : '') ;
- if ($img)
- $image = '<a href="' . get_permalink($post->ID) . '" title="'. $post_title .'" ><img src="' . $img . '" title="' . $post_title . '" class="recent-posts-thumb" ' . $hw . ' /></a>';
- $postlist .= ( '<p>' .$image ) . ( $excerpt . "</p>" ) . '</li>';
- // End of customised display
- // Original code for Advanced Recent Posts Mod
- // $postlist .= '<li>'.($spot == 'spot1' ? '<span class="date">'.$time.'</span> ' : '');
- // $postlist .= $image;
- // if (!$hideposttitle) $postlist .= '<a href="' . get_permalink($post->ID) . '" title="'. $post_title .'" >' . $post_title .'</a>';
- // $author_data = get_userdata($post->post_author);
- // $postlist .= ($showauthor ? ' by '.$author_data->display_name : '') . ($spot == 'spot2' ? ' <span class="date">'.$time.'</span>' : '') . $excerpt . "</li>";
- }// end foreach()
- if ($echo)
- echo '<ul class="advanced-recent-posts">' . $postlist . '</ul>';
- else
- return '<ul class="advanced-recent-posts">' . $postlist . '</ul>';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement