Question

Below is one page of a Joomla 1.5 extension another developer created quickly that ultimately works like the core Joomla Related Articles but a bit more custom. The code is not very pretty but it works. It shows the title and date for the latest 5 articles that are tagged with the same tag on the current page being viewed. The only problem is it shows articles from 2013 and 2012, since there are only a couple 2013 articles. So ultimately it should show 5 related items only from the current year. So if its 2013 (which it is), and there are only 4 articles from 2013 it should only show those 4.

On the line: for($y=2001; $y <= $intYear; $y++) I tried changing 2001 to 2013 but didn't change anything on the front end. Tried changing to 2014 and didn't change anything either.

The other option I was thinking was on the line: $objDb->setQuery("SELECT sectionid, catid, title if there was a way to say WHERE created='$currentYear' kind of thing.

Once again the code is not pretty and imagine the performance not so great, but looking for a quick fix to this issue, until the whole module can be replaced with a better solution later on. Any help would be most appreaciated!

<?php
// Include the syndicate functions only once
//require_once (dirname(__FILE__).DS.'helper.php');
//
//$list = modRelatedItemsHelper::getList($params);
//
//if (!count($list)) {
//  return;
//}
//
//$showDate = $params->get('showDate', 0);
//
//require(JModuleHelper::getLayoutPath('mod_related_items'));


// no direct access

defined('_JEXEC') or die('Restricted access');

// Include the syndicate functions only once
include_once( dirname(__FILE__).DS.'helper.php' );

if( !defined('NL') )
 { define('NL', "\n"); }

$prmRptShowFilter=$params->get('rpt_show_filter');
$prmRptSection=$params->get('rpt_section');
$prmRptCategory=$params->get('rpt_category');
$prmRptDateFormat=$params->get('rpt_date_format');


$arrMonths=array();
$arrMonths[1]='January';
$arrMonths[2]='February';
$arrMonths[3]='March';
$arrMonths[4]='April';
$arrMonths[5]='May';
$arrMonths[6]='June';
$arrMonths[7]='July';
$arrMonths[8]='August';
$arrMonths[9]='September';
$arrMonths[10]='October';
$arrMonths[11]='November';
$arrMonths[12]='December';

$arrYears=array();
$intYear=date(Y);
for($y=2001; $y <= $intYear; $y++)
 { $arrYears[]=$y; }

$varArticleId=JRequest::getVar('id');
$objDb=&JFactory::getDBO();

//--- Database Script ---//
$objDb->setQuery("SELECT sectionid, catid, title FROM #__content WHERE id='$varArticleId' LIMIT 1");
$rows=$objDb->loadObjectList();
$section_id=$rows[0]->sectionid;
$cat_id=$rows[0]->catid;
//--- Database Script ---//

$arrList=modGtSidebarCustomHelper::getList($params);

?>
<style type="text/css">
#idForm1 {
 float: right;
}
#idForm1 ul {
 margin: 0;
 padding: 0;
 list-style: none;
 clear: both;
}
#idForm1 li {
 float: left;
 margin: 0 1px 0 0;
 padding: 0;
}
#idGtReportDisplayB {
    text-align:left;
    margin:3px 5px;
}
#idGtReportDisplayB a:hover {
 text-decoration: underline;
    font-weight: normal;    
}

#idGtReportDisplayB span.zoom-link {
 display: none; 
}
#idGtReportDisplayB dl, 
#idGtReportDisplayB dl dt, 
#idGtReportDisplayB dl dd {
    padding: 0px 5px 0px 5px;
    margin: 0;
}

#idGtReportDisplayB dd {
    color: #680e0e;
}

#idGtReportDisplayB dl {
  width: 284px;
    padding-bottom: 15px;   
}

#idNoRelatedLatestNews {
 display: none;
}

</style>
<div id="idGtReportDisplayB">
<?php
 $strDisplay='';
 $prmRptDateFormat='n/j/Y';

 if( !empty($arrList) )
  {
   $strDisplay.='<h2>Recent News</h2>'. NL;

   $numSize=sizeof($arrList);
   for($x=0; ($x < $numSize) && ($x <= 5); $x++)
    {
     $tmpDtm=strtotime($arrList[$x]->created);

     $strDisplay.='<dl>'. NL;
     $strDisplay.=' <dt><a href="'. $arrList[$x]->route .'">'. $arrList[$x]->title .'</a></dt>'. NL;
     $strDisplay.=' <dd>'. date($prmRptDateFormat, $tmpDtm) .'</dd>'. NL;
     $strDisplay.='</dl>'. NL;
    }

   echo($strDisplay);
  }
 else
  {
#   include( dirname(__FILE__).DS.'..'.DS.'mod_latestnews'.DS.'mod_latestnews.php' );
?>
<style type="text/css">
#idNoRelatedLatestNews {
  display: block;
}
</style>
<?
  }
?>
    </ul>
</div>
Was it helpful?

Solution 2

Since there wasn't much of any response from the community on this one, I ultimately created a hack that resolved the issue for now. In which I added the article year as the class name to each dl and then through css just hid the old year I didn't want. While not ideal it works and hopefully will be replacing all the code soon enough anyway.

OTHER TIPS

Try something like,

$current_year = date('Y');
$objDb->setQuery("SELECT sectionid, catid, title FROM #__content WHERE id='$varArticleId'  AND  YEAR(created_on) = $current_year ");

It will load only current year data ..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top