Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/12/2015, 17:46
Avatar de kakashi20
kakashi20
 
Fecha de Ingreso: septiembre-2009
Mensajes: 616
Antigüedad: 14 años, 7 meses
Puntos: 15
Exclamación Filtrar archive.php por custom post type

Tengo este codigo en el function.php el cual me crear la lista de los meses en los cuales se han creado post asi:

Código PHP:
Ver original
  1. function twentyeleven_get_archives_callback($item, $index, $currYear) {
  2.     global $wp_locale;
  3.  
  4.     if ( $item['year'] == $currYear ) {
  5.         $url = get_month_link( $item['year'], $item['month'] );
  6.         // translators: 1: month name, 2: 4-digit year
  7.         $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($item['month']), $item['year']);
  8.         $text = substr($text,0,3);
  9.         echo get_archives_link($url, $text);
  10.     }
  11. }
  12.  
  13. function twentyeleven_get_archives() {
  14.     global $wpdb;
  15.  
  16.     $query = "SELECT YEAR(post_date) AS <code>year</code> FROM $wpdb->posts WHERE <code>post_type</code> = 'post' AND <code>post_status</code> = 'publish' GROUP BY <code>year</code> ORDER BY <code>year</code> DESC limit 4";
  17.     $arcresults = $wpdb->get_results($query);
  18.     $years = array();
  19.  
  20.     if ($arcresults) {
  21.         foreach ( (array)$arcresults as $arcresult ) {
  22.             array_push($years, $arcresult->year);
  23.         }
  24.     }
  25.  
  26.     $query = "SELECT YEAR(post_date) as <code>year</code>, MONTH(post_date) as <code>month</code> FROM $wpdb->posts WHERE <code>post_type</code> = 'post' AND <code>post_status</code> = 'publish' GROUP BY <code>year</code>, <code>month</code> ORDER BY <code>year</code> DESC, <code>month</code> ASC";
  27.     $arcresults = $wpdb->get_results($query, ARRAY_A);
  28.     $months = array();
  29.  
  30.     if ( $arcresults ) {
  31.         foreach ($years as $year) {
  32.                     //My Display
  33.             //echo "\t<li>\n\t\t<a href=\"#\">$year</a>\n\t\t<ul>\n";
  34.             //array_walk($arcresults, "twentyeleven_get_archives_callback", $year);
  35.             //echo "\t\t</ul>\n\t</li>\n";
  36.  
  37.                     //Your Display
  38.             echo "\t<div class='listYearArchive'><span class='yearArchive'>$year</span>\n\t<ul class='listMonthArchive'>\n";
  39.             array_walk($arcresults, "twentyeleven_get_archives_callback", $year);
  40.             echo "\t</ul></div>\n";
  41.         }
  42.     }
  43. }
2015 nov dec
2104 may nov dec

"nov" "dec" son link el cual me muestra en la url: http://www.xxx.com/2015/11 los post de esa fecha.

Esto usando archive.php

La pregunta es: como podria hacer esto mismo pero filtrando estos link por custom post type ??