Programación

Foro WordPress » WordPress » Programación

query_posts (3 mensajes)

Acerca de este hilo

Tags

Etiquetas:

  1. smarullo

    1.0
    Antiguedad: May 2011
    Mensajes: 2

    offline

    Publicado hace 12 meses
    #

    Estimados, necesito su ayuda...

    tengo el siguiente php de una parte de mi sitio:

    <div id="latestposts">
    <div id="latestposts-pad">
    <div class="title">
    <h3><?php echo __('Latest Posts', PADD_THEME_SLUG); ?></h3>
    </div>
    <div class="interior">

      <?php padd_theme_widget_recent_posts('limit=3'); ?>

    </div>
    </div>
    </div>

    lo que quiero hacer es limitar a que se muestren nada mas los post e X categoria
    ya que me esta mostrando todos, la unica limitacion que tiene es q me muestra nada mas que los ultimos 3.
    probe incertandole <?php query_posts("cat=-6"); ?> pero me siguen apareciendo los post de esa categoria.

    Gracias, Apreciaria su ayuda.

  2. smarullo

    1.0
    Antiguedad: May 2011
    Mensajes: 2

    offline

    Publicado hace 12 meses
    #

    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 .= '

  3. ';
    $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 .= '
  4. ';
    //$output .= get_archives_link($url, $text, $format, $before, ' - ' . date($date_format,strtotime($arcresult->post_date)) . $after);
    }
    }
    }

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

  • LGrusin

    Moderador
    Antiguedad: Feb 2011
    Mensajes: 1.801

    offline

    Publicado hace 12 meses
    #

    Quizás estos hilos te interesen.

    Posts de una o varias categorías Con paginación. Lo tienes al final porque ese hilo contiene más cosas.

    ultimo-post-de-varias-categorias-en-una-sola-consulta Otra forma de hacerlo sin paginación, se puede modificar para mostrar más posts y más categorías.

    Un saludo

  • Responder

    Debes Identificarte para publicar.

    Foro WordPress » WordPress » Programación