wordpress Articulos categoria widgets "antiguas y nuevo" como?
Código PHP:
<?php
/*
Plugin Name: Articulos por categoria Firmas - Widget
Plugin URI: http://www.candemasjor.net
Description: Muestra los articulos de una categoria. Basado en el Widget de <a href="http://jameslao.com/2009/12/30/category-posts-widget-3-0/">James Lao Category Posts</a>
Author: Candemasjor.
Version: 1.0
Author URI: http://www.candemasjor.net
*/
// Register thumbnail sizes.
if ( function_exists('add_image_size') )
{
$sizes = get_option('sw_arti_cat_thumb_sizes');
if ( $sizes )
{
foreach ( $sizes as $id=>$size )
add_image_size( 'cat_post_thumb_size' . $id, $size[0], $size[1], true );
}
}
class ArticulosCategoriafirmas extends WP_Widget {
function ArticulosCategoriafirmas() {
parent::WP_Widget(false, $name='Articulos categoria firmas');
}
/**
* Displays category posts widget on blog.
*/
function widget($args, $instance) {
global $post;
$post_old = $post; // Save the post object.
extract( $args );
$sizes = get_option('sw_arti_cat_thumb_sizes');
// If not title, use the name of the category.
if( !$instance["title"] ) {
$category_info = get_category($instance["cat"]);
$instance["title"] = $category_info->name;
}
$valid_sort_orders = array('date', 'title', 'comment_count', 'random');
if ( in_array($instance['sort_by'], $valid_sort_orders) ) {
$sort_by = $instance['sort_by'];
$sort_order = (bool) $instance['asc_sort_order'] ? 'ASC' : 'DESC';
} else {
// by default, display latest first
$sort_by = 'date';
$sort_order = 'DESC';
}
// Get array of post info.
$cat_posts = new WP_Query(
"showposts=" . $instance["num"] .
"&cat=" . $instance["cat"] .
"&orderby=" . $sort_by .
"&order=" . $sort_order
);
// Excerpt length filter
$new_excerpt_length = create_function('$length', "return " . $instance["excerpt_length"] . ";");
if ( $instance["excerpt_length"] > 0 )
add_filter('excerpt_length', $new_excerpt_length);
echo $before_widget;
// Widget title
echo $before_title;
if( $instance["title_link"] )
echo '<a href="' . get_category_link($instance["cat"]) . '">' . $instance["title"] . '</a>';
else
echo $instance["title"];
echo $after_title;
// Post list
echo "<ul>\n";
while ( $cat_posts->have_posts() )
{
$cat_posts->the_post();
$author = get_userdata(get_the_author_id());
?>
<li class="cat-post-item">
<?php if ( $instance['author-bio-box'] ) : ?>
<?php the_author_meta('description'); ?><br/>
<?php endif; ?>
<a class="post-title" href="<?php the_permalink(); ?>" rel="bookmark" title="Enlace a <?php the_title_attribute(); ?>"><?php the_title(); ?></a><br/>
<?php if ( $instance['author_avatar'] ) : ?>
<p class="author-avatar"><?= get_avatar($author->user_email, 64) ?></p>
<?php endif; ?>
<?php
if (
function_exists('the_post_thumbnail') &&
current_theme_supports("post-thumbnails") &&
$instance["thumb"] &&
has_post_thumbnail()
) :
?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail( 'cat_post_thumb_size'.$this->id ); ?>
</a>
<?php endif; ?>
<?php if ( $instance['date'] ) : ?>
<p class="post-date"><?php the_time("j M Y"); ?></p>
<?php endif; ?>
<?php if ( $instance['excerpt'] ) : ?>
<?php the_excerpt(); ?>
<?php endif; ?>
<?php if ( $instance['author_name'] ) : ?>
<a class="author-name" href="<?= get_author_posts_url($author->ID, $author->user_nicename) ?>"><?= $author->first_name . ' ' . $author->last_name ?></a><br/><br/><br/><br/>
<?php endif; ?>
<?php if ( $instance['comment_num'] ) : ?>
<p class="comment-num">(<?php comments_number(); ?>)</p>
<?php endif; ?>
<br />
</li>
<?php
}
echo "</ul>\n aaaaaaaa";
echo $after_widget;
remove_filter('excerpt_length', $new_excerpt_length);
$post = $post_old; // Restore the post object.
}