下面是一个Joomla 1.5扩展的一页,其他开发人员迅速创建,最终像核心Joomla相关文章一样工作,但有点更自定义。代码不是很漂亮,但它的工作原理。它显示最近5篇文章的标题和日期,这些文章在当前正在浏览的页面上使用相同的标记进行标记。唯一的问题是它显示2013年和2012年的文章,因为只有2013年的几篇文章。所以最终它应该只显示当年的5个相关项目。因此,如果它的2013年(这是),并且从2013年只有4篇文章,它应该只显示那些4.限制Joomla 1.5数据库查询到本年度
在线上:for($y=2001; $y <= $intYear; $y++)
我试图改变2001年至2013年,但没有改变任何东西在前端。试图改变到2014年,也没有改变任何东西。
我在想的另一个选项是:$objDb->setQuery("SELECT sectionid, catid, title
如果有一种方法可以说WHERE created ='$ currentYear'类的东西。
再一次,代码并不漂亮,想象一下性能不是很好,但是寻找一个快速解决这个问题的方法,直到后面的整个模块可以被更好的解决方案替代。任何帮助将最受欢迎!
<?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>
这里没有运气。要注意的是,Joomla至少1.5没有“created_on”只有一个“创建”,但尝试将上述从“created_on”更改为“创建”,仍然没有运气。 – cchiera