Advertisement
Guest User

Untitled

a guest
Mar 28th, 2012
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. public function getWidgetContent ($instance)
  2. {
  3. $instance = $this->setDefalutValues( $instance );
  4.  
  5. $widgetContent = '';
  6. $queryArgs = array('showposts' => $instance['number'], 'nopaging' => 0, 'post_status' => 'publish', 'caller_get_posts' => 1);
  7. if ( $instance['category'] != -1 ) {
  8. $queryArgs['cat'] = $instance['category'];
  9. }
  10. $r = new WP_Query($queryArgs);
  11. if ($r->have_posts()) {
  12. while ($r->have_posts()) {
  13. $r->the_post();
  14. $permalink = get_permalink();
  15. $postID = get_the_ID();
  16. $postTitle = esc_attr( get_the_title() ? get_the_title() : $postID );
  17. $postLink = sprintf('<a href="%s" title="%s" class="post-link">%s</a>', $permalink, $postTitle, $postTitle);
  18. $thumbnail = '';
  19. $postDate = '';
  20. if ( $instance['thumbs'] == 'yes' ) {
  21. $postDate = sprintf( '<span class="widget-post-meta">%s &bull; %s</span>', get_the_author_link(), get_the_time(get_option('date_format')) );
  22. }
  23. if ( $instance['thumbs'] == 'yes' && has_post_thumbnail() ) {
  24. $thumbnail = get_the_post_thumbnail( $postID, 'post-thumbnail-small', array('class'=>'thumbnail') );
  25. $thumbnail = sprintf('<a href="%1$s" class="thumb-post-link">%2$s</a>', $permalink, $thumbnail);
  26. }
  27. $widgetContent .= '<li>' . $thumbnail . $postLink . $postDate . '</li>';
  28. }
  29. $thumbsClass = ( $instance['thumbs'] == 'yes' ) ? ' with-thumbnails' : ' no-thumb';
  30. $widgetContent = sprintf('<ul class="mw-widget-recent-posts-list%s">%s</ul>', $thumbsClass, $widgetContent);
  31. wp_reset_postdata();
  32. }
  33. return $widgetContent;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement