Foros del Web » Programando para Internet » PHP »

Mostrar artículos en orden descendente por fecha

Estas en el tema de Mostrar artículos en orden descendente por fecha en el foro de PHP en Foros del Web. hola gente.. quiero mostrar 5 articulos relacionado por fecha y en orden descendente .. actualmente me muestra en orden ascendente.. aunque tengo la duda si ...
  #1 (permalink)  
Antiguo 07/05/2015, 11:15
 
Fecha de Ingreso: junio-2008
Mensajes: 82
Antigüedad: 15 años, 9 meses
Puntos: 2
Mostrar artículos en orden descendente por fecha

hola gente.. quiero mostrar 5 articulos relacionado por fecha y en orden descendente.. actualmente me muestra en orden ascendente.. aunque tengo la duda si me muestra p or id... no soy un experto en php.. por ello la consulta

me muestra asi



este es el archivo helper.php

Código PHP:
Ver original
  1. defined('_JEXEC') or die;
  2.  
  3. require_once JPATH_SITE . '/components/com_content/helpers/route.php';
  4.  
  5. /**
  6.  * Helper for mod_related_items
  7.  *
  8.  * @package     Joomla.Site
  9.  * @subpackage  mod_related_items
  10.  * @since       1.5
  11.  */
  12. abstract class ModRelatedItemsHelper
  13. {
  14.     /**
  15.      * Get a list of related articles
  16.      *
  17.      * @param   JRegistry  &$params  module parameters
  18.      *
  19.      * @return array
  20.      */
  21.     public static function getList(&$params)
  22.     {
  23.         $db = JFactory::getDbo();
  24.         $app = JFactory::getApplication();
  25.         $user = JFactory::getUser();
  26.         $groups = implode(',', $user->getAuthorisedViewLevels());
  27.         $date = JFactory::getDate();
  28.         $maximum = (int) $params->get('maximum', 5);
  29.  
  30.         $option = $app->input->get('option');
  31.         $view = $app->input->get('view');
  32.  
  33.         $temp = $app->input->getString('id');
  34.         $temp = explode(':', $temp);
  35.         $id = $temp[0];
  36.  
  37.         $nullDate = $db->getNullDate();
  38.         $now = $date->toSql();
  39.         $related = array();
  40.         $query = $db->getQuery(true);
  41.  
  42.         if ($option == 'com_content' && $view == 'article' && $id)
  43.         {
  44.             // Select the meta keywords from the item
  45.             $query->select('metakey')
  46.                 ->from('#__content')
  47.                 ->where('id = ' . (int) $id);
  48.             $db->setQuery($query);
  49.  
  50.             if ($metakey = trim($db->loadResult()))
  51.             {
  52.                 // Explode the meta keys on a comma
  53.                 $keys = explode(',', $metakey);
  54.                 $likes = array();
  55.  
  56.                 // Assemble any non-blank word(s)
  57.                 foreach ($keys as $key)
  58.                 {
  59.                     $key = trim($key);
  60.  
  61.                     if ($key)
  62.                     {
  63.                         $likes[] = $db->escape($key);
  64.                     }
  65.                 }
  66.  
  67.                 if (count($likes))
  68.                 {
  69.                     // Select other items based on the metakey field 'like' the keys found
  70.                     $query->clear()
  71.                         ->select('a.id')
  72.                         ->select('a.title')
  73.                         ->select('DATE_FORMAT(a.created, "%Y-%m-%d") as created')
  74.                         ->select('a.catid')
  75.                         ->select('cc.access AS cat_access')
  76.                         ->select('cc.published AS cat_state');
  77.  
  78.                     // Sqlsrv changes
  79.                     $case_when = ' CASE WHEN ';
  80.                     $case_when .= $query->charLength('a.alias', '!=', '0');
  81.                     $case_when .= ' THEN ';
  82.                     $a_id = $query->castAsChar('a.id');
  83.                     $case_when .= $query->concatenate(array($a_id, 'a.alias'), ':');
  84.                     $case_when .= ' ELSE ';
  85.                     $case_when .= $a_id . ' END as slug';
  86.                     $query->select($case_when);
  87.  
  88.                     $case_when = ' CASE WHEN ';
  89.                     $case_when .= $query->charLength('cc.alias', '!=', '0');
  90.                     $case_when .= ' THEN ';
  91.                     $c_id = $query->castAsChar('cc.id');
  92.                     $case_when .= $query->concatenate(array($c_id, 'cc.alias'), ':');
  93.                     $case_when .= ' ELSE ';
  94.                     $case_when .= $c_id . ' END as catslug';
  95.                     $query->select($case_when)
  96.                         ->from('#__content AS a')
  97.                         ->join('LEFT', '#__content_frontpage AS f ON f.content_id = a.id')
  98.                         ->join('LEFT', '#__categories AS cc ON cc.id = a.catid')
  99.                         ->where('a.id != ' . (int) $id)
  100.                         ->where('a.state = 1')
  101.                         ->where('a.access IN (' . $groups . ')');
  102.                     $concat_string = $query->concatenate(array('","', ' REPLACE(a.metakey, ", ", ",")', ' ","'));
  103.  
  104.                     // Remove single space after commas in keywords)
  105.                     $query->where('(' . $concat_string . ' LIKE "%' . implode('%" OR ' . $concat_string . ' LIKE "%', $likes) . '%")')
  106.                         ->where('(a.publish_up = ' . $db->quote($nullDate) . ' OR a.publish_up <= ' . $db->quote($now) . ')')
  107.                         ->where('(a.publish_down = ' . $db->quote($nullDate) . ' OR a.publish_down >= ' . $db->quote($now) . ')');
  108.  
  109.                     // Filter by language
  110.                     if (JLanguageMultilang::isEnabled())
  111.                     {
  112.                         $query->where('a.language in (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')');
  113.                     }
  114.  
  115.                     $db->setQuery($query, 0, $maximum);
  116.                     $temp = $db->loadObjectList();
  117.  
  118.                     if (count($temp))
  119.                     {
  120.                         foreach ($temp as $row)
  121.                         {
  122.                             if ($row->cat_state == 1)
  123.                             {
  124.                                 $row->route = JRoute::_(ContentHelperRoute::getArticleRoute($row->slug, $row->catslug));
  125.                                 $related[] = $row;
  126.                             }
  127.                         }
  128.                     }
  129.  
  130.                     unset ($temp);
  131.                 }
  132.             }
  133.         }
  134.  
  135.         return $related;
  136.     }
  137. }

y este es el otro archivo

Código PHP:
Ver original
  1. defined('_JEXEC') or die;
  2.  
  3. // Include the syndicate functions only once
  4. require_once __DIR__ . '/helper.php';
  5.  
  6. $cacheparams = new stdClass;
  7. $cacheparams->cachemode = 'safeuri';
  8. $cacheparams->class = 'ModRelatedItemsHelper';
  9. $cacheparams->method = 'getList';
  10. $cacheparams->methodparams = $params;
  11. $cacheparams->modeparams = array('id' => 'int', 'Itemid' => 'int');
  12.  
  13. $list = JModuleHelper::moduleCache($module, $params, $cacheparams);
  14.  
  15. if (!count($list))
  16. {
  17.     return;
  18. }
  19.  
  20. $moduleclass_sfx = htmlspecialchars($params->get('moduleclass_sfx'));
  21. $showDate = $params->get('showDate', 0);
  22.  
  23. require JModuleHelper::getLayoutPath('mod_related_items', $params->get('layout', 'default'));
  #2 (permalink)  
Antiguo 07/05/2015, 12:44
Avatar de carlos_belisario
Colaborador
 
Fecha de Ingreso: abril-2010
Ubicación: Venezuela Maracay Aragua
Mensajes: 3.156
Antigüedad: 14 años
Puntos: 461
Respuesta: Mostrar artículos en orden descendente por fecha

buenas, pues imagino que el objeto que estas usando para armar el query tendrá un método order donde puedes hacer lo que quieres, en teoría sería solo buscar la documentación del mismo y agregarlo al script
__________________
aprende d tus errores e incrementa tu conocimientos
it's not a bug, it's an undocumented feature By @David
php the right way
  #3 (permalink)  
Antiguo 07/05/2015, 13:30
 
Fecha de Ingreso: junio-2008
Mensajes: 82
Antigüedad: 15 años, 9 meses
Puntos: 2
Respuesta: Mostrar artículos en orden descendente por fecha

Cita:
Iniciado por carlos_belisario Ver Mensaje
buenas, pues imagino que el objeto que estas usando para armar el query tendrá un método order donde puedes hacer lo que quieres, en teoría sería solo buscar la documentación del mismo y agregarlo al script
solo hay 3 archivos.. los 2 que indico aca y otro archivo .. un xml para una configuración basica y no hay mas archivos.. y cuando digo configuración basica del xml .. solo tiene para configurar la cantidad de articulos a mostrar.. que por defecto viene 5.. como muestra en el helper.php

Última edición por leoncito34; 07/05/2015 a las 14:38
  #4 (permalink)  
Antiguo 08/05/2015, 07:27
 
Fecha de Ingreso: junio-2008
Mensajes: 82
Antigüedad: 15 años, 9 meses
Puntos: 2
Respuesta: Mostrar artículos en orden descendente por fecha

alguien sabe como solucionar este tema?.. alguno que sepa mucho de php

Etiquetas: fecha, html, orden, select, sql
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 14:28.