년월일별 아카이브 리스트 만들기
0. 문서 아카이브 리스트를 만듭니다. 연도별, 월별, 일별로 몇 개의 문서가 있는지 count도 됩니다. 라이믹스에서 테스트했습니다.
1. 준비물:
- /modules/document/queries 폴더의
- getYearlyArchivedList.xml
- getMonthlyArchivedList.xml
- getDailyArchivedList.xml
- /modules/document/queries 폴더의
- document.model.php
- /modules/board 폴더의
- board.class.php
2. 단, getYearlyArchivedList.xml은 없으므로 다음과 같은 소스로 새로 만들어줘야 합니다.
<tables>
<table name="documents" />
</tables>
<columns>
<column name="substr(regdate,1,4)" alias="year" />
<column name="count(*)" alias="count" />
</columns>
<conditions>
<condition operation="in" column="module_srl" var="module_srl" filter="number" />
<condition operation="like_prefix" column="regdate" var="regdate" pipe="and" />
</conditions>
<groups>
<group column="substr(regdate,1,4)" />
</groups>
</query>
3. getDailyArchivedList.xml도 형식에 알맞게 수정해주면 좋습니다.
- 1행의 <query id="getMonthlyArchivedList" action="select">을 다음과 같이 수정
- 6행의 <column name="substr(regdate,1,8)" alias="month" />을 다음과 같이 수정
4. documet.model.php의 847행쯤(getDailyArchivedList 함수 다음 부분)에 다음을 삽입합니다.
* Bringing a year on the status of the yaerly posts
* @param object $obj
* @return object
*/
function getYearlyArchivedList($obj)
{
if($obj->mid)
{
$oModuleModel = getModel('module');
$obj->module_srl = $oModuleModel->getModuleSrlByMid($obj->mid);
unset($obj->mid);
}
// Module_srl passed the array may be a check whether the array
$args = new stdClass;
if(is_array($obj->module_srl)) $args->module_srl = implode(',', $obj->module_srl);
else $args->module_srl = $obj->module_srl;
$args->regdate = $obj->regdate;
$output = executeQuery('document.getYearlyArchivedList', $args);
if(!$output->toBool()) return $output;
if(!is_array($output->data)) $output->data = array($output->data);
return $output;
}
5. board.class.php의 12행을 다음으로 교체합니다.
즉, array에 regdate를 추가해준 것이죠.
6. 이로써 모든 사전 준비가 끝났습니다.
7. 레이아웃 스킨이나 게시판 스킨 등의 적절한 위치에 다음의 소스를 삽입하고, 각자 취향에 따라 css나 js를 활용해서 스타일링하시면 됩니다.
$args = new stdClass;
$args->module_srl = $module_info->module_srl;
$oDocumentModel = &getModel('document');
$year = $oDocumentModel->getYearlyArchivedList($args);
$month = $oDocumentModel->getMonthlyArchivedList($args);
$day = $oDocumentModel->getDailyArchivedList($args);
}
<div loop="array_reverse($year->data)=>$key1,$val1" class="archive-yearly">
<a href="{getUrl('','mid',$mid,'search_target','regdate','search_keyword',$val1->year)}">
{zdate($val1->year,'Y')}({number_format($val1->count)})
</a>
<div loop="array_reverse($month->data)=>$key2,$val2" cond="zdate($val2->month,'Y')==zdate($val1->year,'Y')" class="archive-monthly">
<a href="{getUrl('','mid',$mid,'search_target','regdate','search_keyword',$val2->month)}">
{zdate($val2->month,'F')}({number_format($val2->count)})
</a>
<div loop="array_reverse($day->data)=>$key3,$val3" cond="zdate($val3->day,'Ym')==zdate($val2->month,'Ym')" class="archive-daily">
<a href="{getUrl('','mid',$mid,'search_target','regdate','search_keyword',$val3->day)}">
{zdate($val3->day,'jS')}({number_format($val3->count)})
</a>
</div>
</div>
</div>
- $args->module_srl 정의 부분에서 $module_info->module_srl은 현재 로딩된 모듈의 srl을 가져오는 것이므로, 다른 모듈을 불러오거나 포함하고 싶을 땐 본인 취향에 맞춰 응용하면 됩니다. 예: '143, 145' 로 하면 143번과 145번 모듈에서 문서를 가져 옵니다.
8. 스크린샷 : jQuery의 toggleClass와 slideToggle을 활용한 접기/펴기
- 이상입니다.

댓글 9
ex) 2017년 3월 첫재쭈 인기게시글 나열등..