Advertisement
Guest User

Customised Display for Advanced Recent Posts Mod

a guest
Feb 19th, 2012
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.23 KB | None | 0 0
  1. if( !function_exists('yg_recentposts')) {
  2.       function yg_recentposts($args = '', $echo = true) {
  3.             global $wpdb;
  4.             $defaults = yg_recentposts_defaults();
  5.             $args = wp_parse_args( $args, $defaults );
  6.             extract($args);
  7.            
  8.             $hideposttitle = (bool) $hideposttitle;
  9.             $separator = $separator;
  10.             $afterexcerpt = $afterexcerpt;
  11.             $afterexcerptlink = (bool) $afterexcerptlink;
  12.             $show_type = $show_type;
  13.  
  14.             $shownum = (int) abs($shownum);
  15.             if(isset($limit) && $shownum == 10) $shownum = (int) $limit;
  16.             $postoffset = (int) abs($postoffset);
  17.             $reverseorder = (int) abs($reverseorder);
  18.             $firstimage = (bool) $firstimage;
  19.             $showauthor = (bool) $showauthor;
  20.             $showtime = (bool) $showtime;
  21.  
  22.             $spot = esc_attr($spot);
  23.  
  24.             $atimage = (bool) $atimage;
  25.             $defimage = esc_url($defimage);
  26.             $format = esc_attr($format);
  27.             $time = '';
  28.             $width = (int) $width;
  29.             $height = (int) $height;
  30.             $w = (int) $w;
  31.             $h = (int) $h;
  32.             if ($width > $w) {
  33.                 $width = $width; $height = $height;
  34.             } else {
  35.                 $width = $w; $height = $h; 
  36.             }
  37.            
  38.             $excerptlength = (int) abs($excerpt);
  39.             $excerptlengthwords = (int) abs($excerptlengthwords);
  40.             $excerpt = '';
  41.             $cats = str_replace(" ", "", esc_attr($cats));
  42.             if (($shownum < 1 ) || ($shownum > 20)) $shownum = 10;
  43.  
  44.                 if (($actcat) && (is_category())) {
  45.                     $cats = get_query_var('cat');
  46.                 }
  47.                 if (($actcat) && (is_single())) {
  48.                     $cats = '';
  49.                     foreach (get_the_category() as $catt) {
  50.                         $cats .= $catt->cat_ID.' ';
  51.                     }
  52.                     $cats = str_replace(" ", ",", trim($cats));
  53.                 }
  54.                
  55.                 if (!intval($cats)) $cats='';
  56.                 $query = "cat=$cats&showposts=$shownum&post_type=$show_type&offset=$postoffset";
  57.                 $posts = get_posts($query); //get posts
  58.  
  59.                 if ($reverseorder) $posts = array_reverse($posts);
  60.                 $postlist = '';
  61.                 $height = $height ? ' height: ' . $height .'px;' : '';
  62.                 $width = $width ? ' width: ' . $width . 'px;' : '';
  63.                 $hw = (!empty($height) || !empty($width)) ? 'style="'.$width.$height.'"' : '';
  64.              
  65.                 foreach ($posts as $post) {
  66.                     if ($showtime) { $time = ' '. date($format,strtotime($post->post_date)); }
  67.                     $post_title = stripslashes($post->post_title);
  68.                     if ($excerptlength) {
  69.                         $excerpt = $post->post_excerpt;
  70.                         $text = $post->post_content;
  71.                         $text = strip_shortcodes( $text );
  72.                         $text = str_replace(']]>', ']]&gt;', $text);
  73.                         $text = strip_tags($text);
  74.                         $excerpt_length = 100;
  75.                         $words = explode(' ', $text, $excerpt_length + 1);
  76.                         if ( '' == $excerpt ) {
  77.                             if (count($words) > $excerpt_length) {
  78.                                 array_pop($words);
  79.                                 $text = implode(' ', $words);
  80.                             }
  81.                             $excerpt = $text;
  82.                         }
  83.                         $afterexcerpt_html = '';
  84.  
  85.                         // Original code for Advanced Recent Posts Mod
  86.                         // if ($afterexcerptlink) $afterexcerpt_html = '<a href="' . get_permalink($post->ID) . '">' . $afterexcerpt . '</a>';
  87.  
  88.                         // Customised display fixes for Advanced Recent Posts Mod  
  89.                         if ($afterexcerptlink)
  90.                         $afterexcerpt_html = '<span class="special_read_more_link">
  91.                         <br />
  92.                         <br />
  93.                         <strong>
  94.                         <span style="color: #7030a0;">&gt;</span><span style="color: #808080;">&gt;</span>
  95.                         </strong>
  96.                         <a href="' . get_permalink($post->ID) . '">' . $afterexcerpt . '</a></span>';
  97.                         // End of customised display
  98.  
  99.                         else $afterexcerpt_html = $afterexcerpt;
  100.                         if ($excerptlengthwords > 0 ) {
  101.                             $words = array_splice($words, 0, $excerptlengthwords);
  102.                             $excerpt = implode(' ', $words);
  103.                         }elseif(strlen($excerpt) > $excerptlength) {
  104.                             $excerpt = mb_substr($excerpt, 0, $excerptlength);
  105.                         }
  106.                         $excerpt = $separator . ($spot == 'spot3' ? '<span class="date">'.$time.'</span> ' : '') . $excerpt . $afterexcerpt_html;
  107.                     }
  108.                     $image = '';
  109.                     $img = '';
  110.                     if ($cusfield) {
  111.                         $cusfield = esc_attr($cusfield);
  112.                         $img = get_post_meta($post->ID, $cusfield, true);
  113.                     }
  114.            
  115.                     if (!$img && $firstimage) {
  116.                         $match_count = preg_match_all("/<img[^']*?src=\"([^']*?)\"[^']*?>/", $post->post_content, $match_array, PREG_PATTERN_ORDER);       
  117.                         $img = count($match_array['1']) > 0 ? $match_array[1][0] : false;
  118.                     }
  119.                     if (!$img && $atimage) {
  120.                         $p = array(
  121.                             'post_type' => 'attachment',
  122.                             'post_mime_type' => 'image',
  123.                             'numberposts' => 1,
  124.                             'order' => 'ASC',
  125.                             'orderby' => 'menu_order ID',
  126.                             'post_status' => null,
  127.                             'post_parent' => $post->ID
  128.                          );
  129.                         $attachments = get_posts($p);
  130.                         if ($attachments) {
  131.                             $imgsrc = wp_get_attachment_image_src($attachments[0]->ID, 'thumbnail');
  132.                             $img = $imgsrc[0];
  133.                         }            
  134.                      }
  135.                          
  136.                     if (!$img && $defimage)
  137.                         $img = $defimage;
  138.  
  139.                     // Customised display fixes for Advanced Recent Posts Mod                  
  140.                     $postlist .=  '<li>'.($spot == 'spot1' ? '<span class="date">'.$time.'</span> ' : ''); 
  141.  
  142.                     if (!$hideposttitle) $postlist .= '<a href="' . get_permalink($post->ID) . '" title="'. $post_title .'" >' . $post_title .'</a>';
  143.                         $author_data = get_userdata($post->post_author);
  144.                     $postlist .= ($showauthor ? ' by '.$author_data->display_name : '') . ($spot == 'spot2' ? ' <span class="date">'.$time.'</span>' : '') ;               
  145.                     if ($img)
  146.                         $image = '<a href="' . get_permalink($post->ID) . '" title="'. $post_title .'" ><img src="' . $img . '" title="' . $post_title . '" class="recent-posts-thumb" ' . $hw . ' /></a>';
  147.  
  148.                     $postlist .= ( '<p>' .$image ) . ( $excerpt . "</p>" ) . '</li>';
  149.                     // End of customised display           
  150.  
  151.                     // Original code for Advanced Recent Posts Mod
  152.                     // $postlist .=  '<li>'.($spot == 'spot1' ? '<span class="date">'.$time.'</span> ' : '');
  153.                     // $postlist .= $image;
  154.                     // if (!$hideposttitle) $postlist .= '<a href="' . get_permalink($post->ID) . '" title="'. $post_title .'" >' . $post_title .'</a>';
  155.                     // $author_data = get_userdata($post->post_author);
  156.                     // $postlist .= ($showauthor ? ' by '.$author_data->display_name : '') . ($spot == 'spot2' ? ' <span class="date">'.$time.'</span>' : '') . $excerpt . "</li>";
  157.  
  158.                 }// end foreach()          
  159.  
  160.             if ($echo)
  161.                 echo '<ul class="advanced-recent-posts">' . $postlist . '</ul>';
  162.             else
  163.                 return '<ul class="advanced-recent-posts">' . $postlist . '</ul>';
  164.     }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement