전체 게시판에서 최근 게시물 대상으로 인기글 뽑기 정보
전체 게시판에서 최근 게시물 대상으로 인기글 뽑기
본문
전체 테이블에서 최근 지정한 시간에 들어 있는
게시물 대상으로 wr_hit수가 큰 것을 뽑아 옵니다.
대상 게시물 최대 수는 최근 것 100개입니다.
기존 latest() 스킨에서 사용할 변수는
$list[ $i]['hit']
$list[ $i]['name']
$list[$i][href]
$list[$i][subject]
입니다.
소스입니다.
lib/topofall.lib.php
<?php
if (!defined('_GNUBOARD_')) exit;
/* 사용법
<?=topofall('latest skin name', '불러 올 갯수', '제목 길이')?>
by *** 개인정보보호를 위한 이메일주소 노출방지 ***
*/
function topofall($skin_dir="", $rows=10, $subject_len=40) {
function cmp($a, $b)
{
if ($a['hit'] == $b['hit']) {
return 0;
}
return ($a['hit'] > $b['hit']) ? -1 : 1;
}
global $config; //함수외부에서 정의된 전역변수 $config를 불러옴
global $g4; //함수외부에서 정의된 전역변수 $g4를 불러옴
if ($skin_dir) //만약에 $skin_dir의 값이 있다면
$latest_skin_path = "$g4[path]/skin/latest/$skin_dir"; //해당 $skin_dir의 디랙토리의 스킨사용
else //그렇지 않다면?
$latest_skin_path = "$g4[path]/skin/latest/$config[cf_latest_skin]"; //기본스킨사용
$sqln= "select bo_table, wr_id from {$g4['board_new_table']} where bn_datetime > ( now() - interval 48 hour) and bn_id > 1 order by bn_id desc limit 100";
$resn= mysql_query( $sqln);
$sqlall= array();
if( $resn) while( $row= mysql_fetch_assoc( $resn)) {
$sqlall[]="select wr_name, wr_subject, wr_hit, '{$row['bo_table']}' bo_table, wr_id from g4_write_{$row['bo_table']} where wr_id='{$row['wr_id']}' ";
}
if( count( $sqlall) > 0) {
$usql= implode( ' union all ', $sqlall);
$listall = array(); //$list에 담는다
$result = sql_query($usql);
for ($i=0; $row = sql_fetch_array($result); $i++) //사용자함수로 불러올 갯수대로 for문을 돌림
$listall[$i] = array( 'hit'=> $row['wr_hit'], 'name'=>$row['wr_name'],
'href'=>$g4['bbs'].'/board.php?bo_table='.$row['bo_table'].'&wr_id='.$row['wr_id'],
'subject'=>conv_subject( $row['wr_subject'], $subject_len) );
usort( $listall, 'cmp');
$list= array_slice( $listall, 0, $rows);
} else $list=array();
ob_start();
include "$latest_skin_path/latest.skin.php";
$content = ob_get_contents();
ob_end_clean();
return $content; //$content에 반환
}
?>
2008.05.09
버그: mysql 4.1 미만에서는 링크에 bo_table값이 잘못 들어 갈 수 있습니다.
게시물이 없는 경우 수정
2008.05.10 새 버젼 댓글에 추가 했습니다.
버그: 비밀글 출력이 됩니다.
2
댓글 12개


마우스로 copy&paste하세요. ^^

상단에 include_once("$g4[path]/lib/topofall.lib.php");
이렇게 불러왔습니다.
다음과 같은 오류가 발생합니다.
1065 : Query was empty
error file : /index.php

이 조건에 맞는 게시물이 없었나 봅니다.


<?php
if (!defined('_GNUBOARD_')) exit;
/* 사용법
<?=topofall("latest skin name", 불러올갯수, 제목길이)?>
by *** 개인정보보호를 위한 이메일주소 노출방지 ***
*/
function cmp($a, $b) {
if ($a['hit'] == $b['hit']) { return 0; }
return ($a['hit'] > $b['hit']) ? -1 : 1;
}
function cmp2($a, $b) {
if ($a['hit'] == $b['hit']) { return 0; }
return ( strlen($a) > strlen($b)) ? -1 : 1;
}
function topofall($skin_dir="", $rows=10, $subject_len=40) {
global $config; //함수외부에서 정의된 전역변수 $config를 불러옴
global $g4; //함수외부에서 정의된 전역변수 $g4를 불러옴
if ($skin_dir) //만약에 $skin_dir의 값이 있다면
$latest_skin_path = "$g4[path]/skin/latest/$skin_dir"; //해당 $skin_dir의 디랙토리의 스킨사용
else //그렇지 않다면?
$latest_skin_path = "$g4[path]/skin/latest/$config[cf_latest_skin]"; //기본스킨사용
$sqln= "select bo_table, wr_id from {$g4['board_new_table']} where bn_datetime > ( now() - interval 48 hour) and bn_id > 1 order by bn_id desc limit 100";
$resn= mysql_query( $sqln);
$sqlall= array();
$max_len=0;
$max_idx=0;
$idx=0;
if( $resn) while( $row= mysql_fetch_assoc( $resn)) {
$sqlall[]="select wr_name, wr_subject, wr_hit, '{$row['bo_table']}' bo_table, wr_id from g4_write_{$row['bo_table']} where wr_id='{$row['wr_id']}' ";
// 4.1 이하 버젼에서만 필요
$this_len= strlen( $row['bo_table']);
if( $this_len> $max_len) { $max_len= $this_len; $max_idx=$idx; }
$idx++;
}
if( count( $sqlall) > 0 ) {
// 4.1 이하 버젼에서만 필요
$sql_tmp= $sqlall[0];
$sqlall[0]= $sqlall[ $max_idx];
$sqlall[ $max_idx]= $sql_tmp;
$usql= implode( ' union all ', $sqlall);
$listall = array(); //$list에 담는다
$result = sql_query($usql);
for ($i=0; $row = sql_fetch_array($result); $i++) //사용자함수로 불러올 갯수대로 for문을 돌림
$listall[$i] = array( 'hit'=> $row['wr_hit'], 'name'=>$row['wr_name'],
'href'=>$g4['bbs'].'/board.php?bo_table='.$row['bo_table'].'&wr_id='.$row['wr_id'],
'subject'=>conv_subject( $row['wr_subject'], $subject_len) );
usort( $listall, 'cmp');
$list= array_slice( $listall, 0, $rows);
} else $list= array();
ob_start();
include "$latest_skin_path/latest.skin.php";
$content = ob_get_contents();
ob_end_clean();
return $content; //$content에 반환
}
?>


멋지네요
그런데 출력하지 말아야 할 게시판도 출력이 되네요..
출력하지 말아야할 게시판을 정하거나..
출력해야할 게시판 을 지정하여 출력 할려면 어떻게 해야될까요??

$resn= mysql_query( $sqln);
... and bn_id > 1 and bo_table not in ( 'but1', 'but2', 'but3') ....
조건 하나 추가하면 될 거 같습니다.


코멘트 않 뽑아 오는법 없나여 ?
그리고 썸네일이 않나오네요..이거 꼭 필요한데..
좀 해결좀 해주세요..ㅜ,.ㅠ