Created
June 15, 2013 19:01
-
-
Save cpswsg/5789179 to your computer and use it in GitHub Desktop.
WordPress Widget Recent Posts personalizado.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class My_Recent_Posts_Widget extends WP_Widget_Recent_Posts { | |
function widget($args, $instance) { | |
extract( $args ); | |
$title = apply_filters('widget_title', empty($instance['title']) ? __('Tópicos recentes') : $instance['title'], $instance, $this->id_base); | |
if( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) ) | |
$number = 5; | |
$r = new WP_Query( apply_filters( 'widget_posts_args', array( 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true ) ) ); | |
if( $r->have_posts() ) : | |
$before_title = '<h2 class="header"><span>'; | |
$after_title = '</span></h2>'; | |
echo $before_widget; | |
if( $title ) echo $before_title . $title . $after_title; ?> | |
<div class="widget recent"> | |
<?php while( $r->have_posts() ) : $r->the_post(); ?> | |
<article class="post"> | |
<!-- .row-fluid --> | |
<div class="row-fluid"> | |
<!-- .span3 --> | |
<div class="span3"> | |
<?php if ( has_post_thumbnail() ) : ?> | |
<a href="<?php the_permalink() ?>"><?php the_post_thumbnail( 'thumb'); ?></a> | |
<?php else: ?> | |
<a href="<?php the_permalink() ?>"><img src="http://placehold.it/640x640&text=sem foto" alt="sem foto"></a> | |
<?php endif; ?> | |
</div> | |
<!-- /.span3 --> | |
<!-- /.span9 --> | |
<div class="span9"> | |
<p><strong><a href="<?php the_permalink() ?>"><?php the_title() ?></a></strong></p> | |
<p class="meta"><?php the_time(get_option('date_format')); ?></p> | |
<p class="comments"><a href="<?php comments_link(); ?>"><?php comments_number( 'Deixe o seu comentário', '1 Comentário', '% Comentários' ); ?></a></p> | |
</div> | |
<!-- .span9 --> | |
</div> | |
<!-- /.row-fluid --> | |
</article> | |
<?php endwhile; ?> | |
</div> | |
<?php | |
echo $after_widget; | |
wp_reset_postdata(); | |
endif; | |
} | |
} | |
function my_recent_widget_registration() { | |
unregister_widget( 'WP_Widget_Recent_Posts' ); | |
register_widget( 'My_Recent_Posts_Widget' ); | |
} | |
add_action('widgets_init', 'my_recent_widget_registration'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
selamat malam