전체 사이트 게시물 수 , 조회수 출력하기 문의 드립니다
CMS/프레임워크 | Rhymix 2.0 |
---|---|
개발 언어 | PHP 7.4 |
안녕하세요!
사이트 레이아웃 페이지에
사이트에서 작성된 전체 게시물 숫자와 / 전체 조회수 숫자를 표시해보고 싶어서 정보를 찾아보고 있는데요
{@
$output = executeQueryArray('board.getBoardList');
$oDocumentModel = &getModel('document');
}
<block loop="$output->data=>$key,$val">
{@ $boards[$val->mid] = $val->module_srl}
</block>
<div loop="$boards=>$key,$val">
{@ $total_count = $oDocumentModel->getDocumentCount($val)}
{$key} - {(int)$total_count}
</div>
전체 게시물 숫자는 위와 같은 방법을 찾았는데
문제가
게시판 이름 - 숫자
게시판 이름 - 숫자
게시판 이름 - 숫자
이런식으로 전체가 다 나오는 문제가 있어서요
1. 그냥 게시판 이름 없이 총 게시판의 게시물 숫자 00 개 이렇게 하나만 출력할 수는 없을까요?
2. 사이트 전체 게시물 조회수 카운터 방법은 ㅜ 아무리 찾아봐도 안나와서요
방법 좀 알려주실수 있을까요!! ㅜ
감사합니다!!!
Maxter
Lv. 6
반가워요~
댓글 21
{@
$args->module_srl = 모듈번호;
$output = executeQuery('document.getDocumentCount', $args);
}
{$output->data->count}
2. 질문에 대한 답을 아직 못찾았네요 ㅜㅜ
이걸로 해보세요.
{@
$all_document_count = false;
$all_readed_count = false;
$board_list_output = executeQueryArray('board.getAllBoard');
if ( !empty($board_list_output->data) ):
$board_list = [];
foreach( $board_list_output->data as $val ):
$board_list[] = $val->module_srl;
endforeach;
$args = new stdClass;
$args->module_srl = $board_list;
$all_document_output = executeQueryArray('document.getDocumentList', $args, ['readed_count']);
if ( !empty($all_document_output->data) ):
$all_document_count = $all_document_output->total_count;
$all_readed_count = 0;
foreach( $all_document_output->data as $val ):
$all_readed_count = $all_readed_count + $val->readed_count;
endforeach;
endif;
endif;
}
총 게시물 수 : {$all_document_count}
게시물 총 조회수 : {$all_readed_count}
근데 리소스 많이 잡아먹겠는데요ㄷㄷ
캐시로 저장해서 활용하면 좋을 것 같은데, 게시물이 insert/delete될 때마다 그리고 조회될 때마다 캐시를 업데이트해줘야 해서 그것도 좀 번거롭긴 하겠어요.
출력 잘되네요! 정말 감사합니다!
좋은 하루 되세요!
관리자 > 콘텐츠 > 문서에 보시면 게시물 수가 나오는데 그 값이랑 저 코드의 값이랑 동일하신가요?
https://eond.com/xe/448400
오, 들어갔다가 이런 위젯을 봤어요. 위젯 스킨 예쁩니다~
https://xetown.com/questions/1726292#comment_1726482
생각해보니 직접 쿼리를 짜서 조회수 합계도 한번에 뽑아오는 게 좋을 것 같은데요.그건 다음 과제로 남겨둘게요ㅎㅎ
조회수 다 더하려면ㅎㅎ
아, 위의 방법은 조회수가 최근 20개 게시물에서만 합산이 되네요.
아래처럼 직접 쿼리를 돌리는 게 차라리 나을 것 같습니다.
$all_document_count = false;
$all_readed_count = false;
$board_list_output = executeQueryArray('board.getAllBoard');
if ( !empty($board_list_output->data) ):
$board_list = [];
foreach( $board_list_output->data as $val ):
$board_list[] = $val->module_srl;
endforeach;
$query = 'SELECT COUNT(readed_count) AS count, SUM(readed_count) AS sum FROM documents WHERE module_srl IN (' . implode(',', array_fill(0, count($board_list), '?')) . ')';
$oDB = DB::getInstance();
$stmt = $oDB->query($query, $board_list);
$result = $stmt->fetchAll()[0];
endif;
}
총 게시물 수 : {$result->count}
게시물 총 조회수 : {$result->sum}
참고: 제 경우에는 이렇게 나왔어요.
- 총 17개의 게시판 리스트 가져오는 데 걸리는 속도 : 0.0001 sec
- 총 405개 게시물을 카운트하고, 조회수 합계(46986)를 가져오는 데 걸리는 속도 : 0.0001 sec
맨 위에 false 값을 넣는 두 줄은 삭제해주세요~