붉은바람

최신글 공지사항을 최상위,상위,위에 노출하는 latest 함수

· 2018-01-22 (월) 10:22:53 · 11806 · 26

최신글 공지사항을 최상위,상위,위에 노출하는 latest 함수입니다. 

다른건 약간에 버그가 있는것 같아, 제가 만들어 봤습니다. 

만약 게시판 글이 2개만 있는데 둘다 공지사항글이 2개 일시, 리스트에 4개가 노출됩니다. 

그러면 최신글에도 4개가 노출되던데 그 버그 수정하여 올렸습니다. 

latest 함수는 latest_notice 이므로 사용하시고자 하신는분들은 

함수호출시 

<?=latest_notice("basic","free",5,20) ?> 

위와같이 함수호출명만 변경하시면 됩니다. 


아래의 코드는 /lib/latest.lib.php에 기존거 지우지마시고 밑에다가 추가로 넣어주시면됩니다. 
 

 

[code]

function latest_notice($skin_dir='', $bo_table, $rows=10, $subject_len=40, $cache_time=1, $options='')
{
    global $g5;

    if (!$skin_dir) $skin_dir = 'basic';

    if(preg_match('#^theme/(.+)$#', $skin_dir, $match)) {
        if (G5_IS_MOBILE) {
            $latest_skin_path = G5_THEME_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];
            if(!is_dir($latest_skin_path))
                $latest_skin_path = G5_THEME_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];
            $latest_skin_url = str_replace(G5_PATH, G5_URL, $latest_skin_path);
        } else {
            $latest_skin_path = G5_THEME_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];
            $latest_skin_url = str_replace(G5_PATH, G5_URL, $latest_skin_path);
        }
        $skin_dir = $match[1];
    } else {
        if(G5_IS_MOBILE) {
            $latest_skin_path = G5_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
            $latest_skin_url  = G5_MOBILE_URL.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
        } else {
            $latest_skin_path = G5_SKIN_PATH.'/latest/'.$skin_dir;
            $latest_skin_url  = G5_SKIN_URL.'/latest/'.$skin_dir;
        }
    }

    $cache_fwrite = false;
    if(G5_USE_CACHE) {
        $cache_file = G5_DATA_PATH."/cache/latest-{$bo_table}-{$skin_dir}-{$rows}-{$subject_len}.php";

        if(!file_exists($cache_file)) {
            $cache_fwrite = true;
        } else {
            if($cache_time > 0) {
                $filetime = filemtime($cache_file);
                if($filetime && $filetime < (G5_SERVER_TIME - 3600 * $cache_time)) {
                    @unlink($cache_file);
                    $cache_fwrite = true;
                }
            }

            if(!$cache_fwrite)
                include($cache_file);
        }
    }

    if(!G5_USE_CACHE || $cache_fwrite) {
        $list = array();

        $sql = " select * from {$g5['board_table']} where bo_table = '{$bo_table}' ";
        $board = sql_fetch($sql);
        $bo_subject = get_text($board['bo_subject']);
                

                $arr_notice = explode(",", trim($board[bo_notice]));
        $str_notice = implode("','",$arr_notice);
        $str_notice = "'".$str_notice."'";
        $sql_search = "";
        if(count($str_notice) > 0){
            $sql_search = " and wr_id not in ($str_notice) ";
        }

        $tmp_write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
        $sql = " select * from {$tmp_write_table} where wr_is_comment = 0 $sql_search order by wr_num limit 0, {$rows} ";
            
        $result = sql_query($sql);
                $tmp_i = 0;
                $i = 0;
                for ($k=0; $k<count($arr_notice); $k++)
                {
                        if (trim($arr_notice[$k])=='') continue;

                        $row = sql_fetch(" select * from $tmp_write_table where wr_id = '$arr_notice[$k]' ");

                        if (!$row[wr_id]) continue;
                        $list[$i] = get_list($row, $board, $latest_skin_url, $subject_len);
                        $list[$i][is_notice] = true;
                        $list[$i][board] = $board[bo_table];
                        $list[$i][href] = G5_BBS_URL.substr($list[$i][href],1,strlen($list[$i][href]));
                        $i++;
                        $tmp_i++;
                }
                while ($row = sql_fetch_array($result)){

                    if($tmp_i >= $rows){
                        break;
                    }
                    
                    $list[$i] = get_list($row, $board, $latest_skin_url, $subject_len);
                    $list[$i][board] = $board[bo_table];
                    $list[$i][href] = G5_BBS_URL.substr($list[$i][href],1,strlen($list[$i][href]));
                    $i++;
                    $tmp_i++;
                }

        if($cache_fwrite) {
            $handle = fopen($cache_file, 'w');
            $cache_content = "<?php\nif (!defined('_GNUBOARD_')) exit;\n\$bo_subject='".$bo_subject."';\n\$list=".var_export($list, true)."?>";
            fwrite($handle, $cache_content);
            fclose($handle);
        }
    }

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

    return $content;
}

[/code]

|

댓글 26개

붉은바람님 감사합니다.
2018-01-22 (월) 21:13:43
헐 작품입니다.
헐 작품입니다.
2018-01-23 (화) 19:34:58
감사합니다^^
2018-01-25 (목) 09:20:14
수고하셨습니다.
2018-01-29 (월) 22:32:23
수고하셨습니다.
2018-01-30 (화) 22:10:34
감사합니다.
추천, 스크랩하고 갑니다.
감사합니다.
감사합니다!
감사합니다 잘나오네요
2018-07-02 (월) 22:36:07
안녕하세요.
이팁을 그누보드 5.3버전에 적용하니 불러오기는 제대로 불러오는데,
링크가 좀 이상합니다.
혹시 제대로 나오게 하는 방법이 없을까요?

링크가
http://도메인명/bbs/board.php?bo_table=free&wr_id=8
이렇게 걸려야 하는데,

아래처럼 걸립니다.
http://도메인명/bbsttp://도메인명/bbs/board.php?bo_table=free&wr_id=8
저도 동일증상으로 한참 찾아봐도 없어서 내용중 69번과 80번을 지우니 잘 되는군요. 원 글과 중복된듯 합니다.
// $list[$i][href] = G5_BBS_URL.substr($list[$i][href],1,strlen($list[$i][href]));
2018-07-07 (토) 13:43:07
얀카님 정말 감사합니다.
덕분에 해결되었습니다.
저도 덕분에 해결했네요 감사합니다 !!
좋은 팁입니다...
미미라클캣
2018-09-14 (금) 14:17:02
정말 감사합니다. 그누보드 처음 테스트중인데 큰도움이 되네요.
영카트5.3.1.9에서 작업중인데요. 몰라용님같은 상황이 발생해서 얀키님의 69, 80번을 주석처리 했는데도 링크 에러가 납니다. 도와주세요~
아~어느 버전부터인지 몰라도 5.3.1.9에서는 이팁을 사용안해도 게시물이 중복되는 현상이 없네요~ ^^
감사합니다
추천, 스크랩하고 갑니다.
감사합니다.
감사합니다. ^^
좋은 정보 감사합니다 ! 덕분에 손쉽게 해결할 수 있었습니다 ㅠㅠㅠ
유용한 정보 감사합니다!!!!!
감사합니다!! 필요한 작업이었는데 덕분에 빨리 끝냈습니다!!
멋진 팁이네요.
2023-04-24 (월) 11:17:54
감사합니다.
댓글을 작성하시려면 로그인이 필요합니다.

그누보드5 팁자료실

2,788건
+
제목 글쓴이 날짜 조회
18-01-29 조회 7,799
18-01-29 조회 1만
18-01-27 조회 6,168
18-01-22 조회 1.2만
18-01-22 조회 6,354
18-01-21 조회 4만
18-01-19 조회 8,438
18-01-19 조회 6,305
18-01-19 조회 8,724
18-01-18 조회 6,517
18-01-18 조회 6,274
18-01-18 조회 8,533
18-01-17 조회 7,822
18-01-12 조회 9,684
18-01-11 조회 6,686
18-01-10 조회 1만
18-01-09 조회 7,026
18-01-07 조회 8,440
18-01-07 조회 1만
18-01-07 조회 9,116
18-01-06 조회 8,649
18-01-06 조회 9,029
18-01-05 조회 8,131
18-01-05 조회 7,329
18-01-03 조회 1.9만
18-01-03 조회 6,065
18-01-02 조회 1.4만
18-01-01 조회 1.3만
18-01-01 조회 7,165
17-12-29 조회 9,648