Joomla后台“最新文章”模块,虽然可以选择按修改或创建时间呈现文章列表,但无论哪种排序方式,都只能显示原作者和创建时间,看起来很不直观。

本站对其源代码进行了简单修改,实现了根据选择排序方式不同,而自动呈现原作者或编者,及其创建或修改时间。

1、首先修改\administrator\modules\mod_latest\src\Helper\LatestHelper.php文件:

(1)在line44---$model->setState()中添加a.modified, a.modified_by字段;//在$model中添加“修改日期”和“编者”

(2)在line93---foreach ($items as &$item){}中添加如下代码://根据排序方式直接输入相应的用户名和时间

if($params->get('ordering') = 'm_dsc'){

	$item->author_name  = Factory::getUser($item->modified_by)->get('name');

	$item->created	    = $item->modified;

}

2、其次修改\administrator\modules\mod_latest\tmpl\default.php文件:

(1)在line18插入:根据参数选择判断该显示“修改”或“创建”用户和日期的代码:

if ($params->get('ordering')=='m_dsc'){

	$name	= Text::_('JGLOBAL_FIELD_MODIFIED_BY_LABEL');

	$time	= Text::_('JGLOBAL_FIELD_MODIFIED_LABEL');

}else {

	$name	= Text::_('JAUTHOR');

	$time	= Text::_('JGLOBAL_FIELD_CREATED_LABEL');

	}

(2)修改如下两行代码://根据排序方式呈现不同的表头文字

原来:

<th scope="col" class="w-20"><?php echo Text::_('JAUTHOR'); ?></th>

改为:

<th scope="col" class="w-20"><?php echo $name; ?></th>

原来:

<th scope="col" class="w-20"><?php echo $name; ?></th>

改为:

<th scope="col" class="w-20"><?php echo $time; ?></th>

如此,完成!

暂无评论