허접 최신댓글 추출방법 정보
허접 최신댓글 추출방법본문
사용 예제사이트 - http://www.momnpapa.com (왼쪽 공지사항 밑에 최신댓글)
목적 - 최신 댓글을 실시간으로 볼 수 있으므로 댓글도 확인 할 수 있음
함수
// 최신댓글 추출
function latestAnswer($skin_dir="", $bo_table, $rows=10, $subject_len=40, $options="")
{
global $g4;
if ($skin_dir)
$latest_skin_path = "$g4[path]/skin/latest/$skin_dir";
else
$latest_skin_path = "$g4[path]/skin/latest/basic";
$list = array();
$sql_common = " from $g4[board_new_table] a, $g4[board_table] b, $g4[group_table] c
where a.bo_table = b.bo_table and b.gr_id = c.gr_id and b.bo_use_search = '1' ";
if ($gr_id)
$sql_common .= " and b.gr_id = '$gr_id' ";
$sql_common .= " and a.wr_id <> a.wr_parent ";
if ($mb_id)
$sql_common .= " and a.mb_id = '$mb_id' ";
$sql_order = " order by a.bn_id desc ";
if (!$page) $page = 1; // 페이지가 없으면 첫 페이지 (1 페이지)
$from_record = ($page - 1) * $rows; // 시작 열을 구함
$sql = " select a.*, b.bo_subject, c.gr_subject, c.gr_id
$sql_common
$sql_order
limit $from_record, $rows ";
$result = sql_query($sql);
for ($i=0; $row=sql_fetch_array($result); $i++)
{
$tmp_write_table = $g4[write_prefix] . $row[bo_table];
$comment = "";
$comment_link = "";
$row2 = sql_fetch(" select * from $tmp_write_table where wr_id = '$row[wr_id]' ");
$list[$i] = $row2;
$name = get_sideview($row2[mb_id], cut_str($row2[wr_name], $config[cf_cut_name]), $row2[wr_email], $row2[wr_homepage]);
// 당일인 경우 시간으로 표시함
$datetime = substr($row2[wr_datetime],0,10);
$datetime2 = $row2[wr_datetime];
if ($datetime == $g4[time_ymd])
$datetime2 = substr($datetime2,11,5);
else
$datetime2 = substr($datetime2,5,5);
$list[$i][gr_id] = $row[gr_id];
$list[$i][bo_table] = $row[bo_table];
$list[$i][name] = $name;
$list[$i][comment] = $comment;
$list[$i][href] = "./board.php?bo_table=$row[bo_table]&wr_id=$row2[wr_id]{$comment_link}";
$list[$i][datetime] = $datetime;
$list[$i][datetime2] = $datetime2;
$list[$i][gr_subject] = $row[gr_subject];
$list[$i][bo_subject] = $row[bo_subject];
$list[$i][subject] = conv_subject($row2[wr_content], $subject_len, "…");
}
ob_start();
include "$latest_skin_path/latest.skin.php";
$content = ob_get_contents();
ob_end_clean();
return $content;
}
이번에 아가 홈페이지 개편하면서...
최신글 추출하는 함수를 약간 응용해서 만들어 보았습니다.(좀 허접하네요...)
사용방법은 extend 디렉토리에
저같은 경우는 latestLast.lib.php 라는 파일 안에 이 함수 넣었구요...
사용방법은
include_once("$g4[path]/lib/latest.lib.php");
echo latestAnswer("gongji-basic", "", 5, 20);
이런식으로 작업 하시면 되고요...
스킨에서 대부분의 스킨이 테이블명이 제목에 오게 되어 있는데...
이부분 적당하게 수정하시면 될것 같네요...
스킨 디렉토리는 함수에서 보시듯이 skin/latest 이쪽 스킨을 사용하게 되어 있습니다.
적당한 폴더 생성 하시고 그 부분만 수정하셔도 될것 같네요...
목적 - 최신 댓글을 실시간으로 볼 수 있으므로 댓글도 확인 할 수 있음
함수
// 최신댓글 추출
function latestAnswer($skin_dir="", $bo_table, $rows=10, $subject_len=40, $options="")
{
global $g4;
if ($skin_dir)
$latest_skin_path = "$g4[path]/skin/latest/$skin_dir";
else
$latest_skin_path = "$g4[path]/skin/latest/basic";
$list = array();
$sql_common = " from $g4[board_new_table] a, $g4[board_table] b, $g4[group_table] c
where a.bo_table = b.bo_table and b.gr_id = c.gr_id and b.bo_use_search = '1' ";
if ($gr_id)
$sql_common .= " and b.gr_id = '$gr_id' ";
$sql_common .= " and a.wr_id <> a.wr_parent ";
if ($mb_id)
$sql_common .= " and a.mb_id = '$mb_id' ";
$sql_order = " order by a.bn_id desc ";
if (!$page) $page = 1; // 페이지가 없으면 첫 페이지 (1 페이지)
$from_record = ($page - 1) * $rows; // 시작 열을 구함
$sql = " select a.*, b.bo_subject, c.gr_subject, c.gr_id
$sql_common
$sql_order
limit $from_record, $rows ";
$result = sql_query($sql);
for ($i=0; $row=sql_fetch_array($result); $i++)
{
$tmp_write_table = $g4[write_prefix] . $row[bo_table];
$comment = "";
$comment_link = "";
$row2 = sql_fetch(" select * from $tmp_write_table where wr_id = '$row[wr_id]' ");
$list[$i] = $row2;
$name = get_sideview($row2[mb_id], cut_str($row2[wr_name], $config[cf_cut_name]), $row2[wr_email], $row2[wr_homepage]);
// 당일인 경우 시간으로 표시함
$datetime = substr($row2[wr_datetime],0,10);
$datetime2 = $row2[wr_datetime];
if ($datetime == $g4[time_ymd])
$datetime2 = substr($datetime2,11,5);
else
$datetime2 = substr($datetime2,5,5);
$list[$i][gr_id] = $row[gr_id];
$list[$i][bo_table] = $row[bo_table];
$list[$i][name] = $name;
$list[$i][comment] = $comment;
$list[$i][href] = "./board.php?bo_table=$row[bo_table]&wr_id=$row2[wr_id]{$comment_link}";
$list[$i][datetime] = $datetime;
$list[$i][datetime2] = $datetime2;
$list[$i][gr_subject] = $row[gr_subject];
$list[$i][bo_subject] = $row[bo_subject];
$list[$i][subject] = conv_subject($row2[wr_content], $subject_len, "…");
}
ob_start();
include "$latest_skin_path/latest.skin.php";
$content = ob_get_contents();
ob_end_clean();
return $content;
}
이번에 아가 홈페이지 개편하면서...
최신글 추출하는 함수를 약간 응용해서 만들어 보았습니다.(좀 허접하네요...)
사용방법은 extend 디렉토리에
저같은 경우는 latestLast.lib.php 라는 파일 안에 이 함수 넣었구요...
사용방법은
include_once("$g4[path]/lib/latest.lib.php");
echo latestAnswer("gongji-basic", "", 5, 20);
이런식으로 작업 하시면 되고요...
스킨에서 대부분의 스킨이 테이블명이 제목에 오게 되어 있는데...
이부분 적당하게 수정하시면 될것 같네요...
스킨 디렉토리는 함수에서 보시듯이 skin/latest 이쪽 스킨을 사용하게 되어 있습니다.
적당한 폴더 생성 하시고 그 부분만 수정하셔도 될것 같네요...
추천
3
3
댓글 12개
모든 그룹의 코멘트를 불러온다는것에 있어서 매우 멋집니다만!!! ㅜ...
어째선지 안되는군요... skin의 별도 수정이 필요합니까?
어째선지 안되는군요... skin의 별도 수정이 필요합니까?
스킨의 별도 수정이 필요 없거든요...ㅠ.ㅠ
제가 변경한 부분이...
$list[$i][subject] = conv_subject($row2[wr_content], $subject_len, "…");
이부분으로 일반적으로 제목이 들어가게 되어 있는 부분을 코멘트 내용으로 들어가게 바꾼것 뿐이거든요...
그리고 sql 문 약간 수정하구요...ㅠ.ㅠ
일단 스킨의 제목 란은 수정이 필요합니다.
스킨의 제목은 테이블명이 존재하지 않기 때문에 아무것도 안나오게 되거든요...
제가 변경한 부분이...
$list[$i][subject] = conv_subject($row2[wr_content], $subject_len, "…");
이부분으로 일반적으로 제목이 들어가게 되어 있는 부분을 코멘트 내용으로 들어가게 바꾼것 뿐이거든요...
그리고 sql 문 약간 수정하구요...ㅠ.ㅠ
일단 스킨의 제목 란은 수정이 필요합니다.
스킨의 제목은 테이블명이 존재하지 않기 때문에 아무것도 안나오게 되거든요...
종합 코멘트
잘되는 군요... 제가 꼭 필요한 기능이었습니다. 감사합니다. ^^
특정 그룹 혹은 게시판만 출력할순 없나요 ?
잘 사용하겠습니다^^
감사감사~!! 잘 배웠습니다~
$list[$i][href] = "./board.php?bo_table=$row[bo_table]&wr_id=$row2[wr_id]{$comment_link}";
->
$list[$i][href] = "./bbs/board.php?bo_table=$row[bo_table]&wr_id=$row2[wr_id]{$comment_link}";
->
$list[$i][href] = "./bbs/board.php?bo_table=$row[bo_table]&wr_id=$row2[wr_id]{$comment_link}";
$list[$i][href] = "./bbs/board.php?bo_table=$row[bo_table]&wr_id=$row2[wr_id]{$comment_link}";
->
$list[$i][href] = "$g4[bbs_path]/bbs/board.php?bo_table=$row[bo_table]&wr_id=$row2[wr_id]{$comment_link}";
^^
->
$list[$i][href] = "$g4[bbs_path]/bbs/board.php?bo_table=$row[bo_table]&wr_id=$row2[wr_id]{$comment_link}";
^^
최신 코멘트
$list[$i][href] = "$g4[bbs_path]/bbs/board.php?bo_table=$row[bo_table]&wr_id=$row2[wr_id]{$comment_link}";
->
$list[$i][href] = "$g4[bbs_path]/board.php?bo_table=$row[bo_table]&wr_id=$row2[wr_id]{$comment_link}";
^^
->
$list[$i][href] = "$g4[bbs_path]/board.php?bo_table=$row[bo_table]&wr_id=$row2[wr_id]{$comment_link}";
^^
ff