테스트 사이트 - 개발 중인 베타 버전입니다

[G4] 최신글 - 랜덤게시물 추출 방법 - [2006.03.19 1차 수정]

· 20년 전 · 10660 · 44
1. extend 디렉토리에 developer.lib.php을 올립니다.

2. developer.lib.php 파일 내용은 다음과 같습니다.

===================================== developer.lib.php =====================================
<?
//랜덤게시물 추출 방법
function r_latest($skin_dir="", $bo_table, $rows=10, $subject_len=40)
{
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 = " select * from $g4[board_table] where bo_table = '$bo_table'";
$board = sql_fetch($sql);

$tmp_write_table = $g4['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
$sql = " select * from $tmp_write_table where wr_is_comment = 0 order by rand() desc limit 0, $rows ";
//explain($sql);
$result = sql_query($sql);
for ($i=0; $row = sql_fetch_array($result); $i++)
$list[$i] = get_list($row, $board, $latest_skin_path, $subject_len);

ob_start();
include "$latest_skin_path/latest.skin.php";
$content = ob_get_contents();
ob_end_clean();

return $content;
}
?>
=============================================================================

3. 불러오고자 하는 곳에서 아래와 같이 불러옵니다.
<?=r_latest("최신글스킨명", 테이블명, 불러올갯수, 제목길이);?>
(적용예제) <?=r_latest("img", bbs, 5, 70);?>

[2006.03.19 1차 수정]
- 버전 업그레이드로 인한 랜덤이 제대로 적용 안되던것 수정

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

댓글 44개

bbking
20년 전
좋은 팁을 이제사 보네요...^^
원하던거~~감사
저에게는 꼭 필요한 것이었는데.....
감사합니다.
까만도둑님 멋지십니다. ^^b
와우~*

'까만도둑'님께서도 정말 숨가쁘게 달려 가시네요^^;

목록보기에 관한 부분은 나름대로 관리자님의 '태클(?!)'이라 여겨집니다만...
g4가 정말로 안정궤도에 오르면 구현되지 않을까 조심스레 짐작해 봅니다^^;
20년 전
팁텍게시판에 목록보기는 언제쯤 될까나........
한 동안 웹을 접하지 못 하여 홈피 하나 만들려고 다시 잡으니
어리둥절 한데 많은 도움이 되고있습니다..
감사합니다 까만도독님!!
오류 뜨는데요 ㅡㅡ"
Warning: Cannot modify header information - headers already sent by (output started at d:\program\apm_setup\htdocs\gnuboard4\extend\developer.lib.php:36) in d:\program\apm_setup\htdocs\gnuboard4\head.sub.php on line 44

Warning: Cannot modify header information - headers already sent by (output started at d:\program\apm_setup\htdocs\gnuboard4\extend\developer.lib.php:36) in d:\program\apm_setup\htdocs\gnuboard4\head.sub.php on line 46

Warning: Cannot modify header information - headers already sent by (output started at d:\program\apm_setup\htdocs\gnuboard4\extend\developer.lib.php:36) in d:\program\apm_setup\htdocs\gnuboard4\head.sub.php on line 47

Warning: Cannot modify header information - headers already sent by (output started at d:\program\apm_setup\htdocs\gnuboard4\extend\developer.lib.php:36) in d:\program\apm_setup\htdocs\gnuboard4\head.sub.php on line 48

Warning: Cannot modify header information - headers already sent by (output started at d:\program\apm_setup\htdocs\gnuboard4\extend\developer.lib.php:36) in d:\program\apm_setup\htdocs\gnuboard4\head.sub.php on line 49

Warning: Cannot modify header information - headers already sent by (output started at d:\program\apm_setup\htdocs\gnuboard4\extend\developer.lib.php:36) in d:\program\apm_setup\htdocs\gnuboard4\head.sub.php on line 50
아틸라
19년 전
그러네요, lib 파일만 올리면,,
공백을 없애세요...

마지막 부분을

ob_start();
include "$latest_skin_path/latest.skin.php";
$content = ob_get_contents();
ob_end_clean();
return $content; } ?>

요런 식으로 하세요.