Respuesta a: query_posts

Inicio Foros WordPress Programación query_posts Respuesta a: query_posts

#52795

smarullo
Participante

Amplio con el codigo de la funcion….

function padd_theme_widget_recent_posts($args = ”) {
global $wpdb, $wp_locale;

$defaults = array(
‘limit’ => ”,
‘format’ => ‘html’, ‘before’ => ”,
‘after’ => ”, ‘show_post_count’ => false,
‘echo’ => 1, ‘show_date’ => true, ‘date_format’ => ‘F j, Y’
);

$r = wp_parse_args($args,$defaults);
extract($r, EXTR_SKIP);

if (” == $type) {
$type = ‘monthly’;
}

if (” != $limit) {
$limit = absint($limit);
$limit = ‘ LIMIT ‘ . $limit;
}

$where = apply_filters(‘getarchives_where’,”WHERE post_type = ‘post’ AND post_status = ‘publish'”,$r);
$join = apply_filters(‘getarchives_join’,””, $r);

$output = ”;

$orderby = “post_date DESC “;
$query = “SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit”;
$key = md5($query);
$cache = wp_cache_get(‘padd_recent_posts’,’general’);

if (!isset($cache[ $key ])) {
$arcresults = $wpdb->get_results($query);
$cache[$key] = $arcresults;
wp_cache_set(‘padd_recent_posts’,$cache,’general’);
} else {
$arcresults = $cache[$key];
}
if ($arcresults) {
foreach ((array) $arcresults as $arcresult) {
if ($arcresult->post_date != ‘0000-00-00 00:00:00’ ) {
$url = get_permalink($arcresult);
$arc_title = $arcresult->post_title;
if ($arc_title) {
$text = strip_tags(apply_filters(‘the_title’, $arc_title));
} else {
$text = $arcresult->ID;
}
$img = trim(get_the_post_thumbnail($arcresult->ID, PADD_THEME_SLUG . ‘-aside’));
$def = get_template_directory_uri() . ‘/images/thumbnail-aside.jpg’;
if (empty($img)) {
$img = ‘Thumbnail‘;
}
$output .= ‘

  • ‘;
    $output .= ‘ID) . ‘” title=”Permalink to ‘ . $text . ‘”>’ . $img . ‘‘;
    $output .= ‘ID) . ‘” title=”Permalink to ‘ . $text . ‘” class=”post-title”>’ . $text . ‘ ‘;
    $output .= ‘<span class=”meta”>’;
    $output .= sprintf(__(‘Posted on %s’, PADD_THEME_SLUG), date(__(‘F j, Y’, PADD_THEME_SLUG), strtotime($arcresult->post_date)));
    $output .= ‘
  • ‘;
    //$output .= get_archives_link($url, $text, $format, $before, ‘ – ‘ . date($date_format,strtotime($arcresult->post_date)) . $after);
    }
    }
    }

    if ($echo) {
    echo $output;
    } else {
    return $output;
    }
    }

    Pin It on Pinterest

    Ir al contenido