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

최신글 댓글 뽑기

· 5년 전 · 4149 · 4

[그누보드 5.3.2.8 버전에서 사용하였습니다 ]

 

 

latest_com.lib.php 등의 파일명으로 아래 소스저장 

 

<?php
if (!defined('_GNUBOARD_')) exit;

// 최신글 추출
// $cache_time 캐시 갱신시간
function latestSortComment($skin_dir='', $bo_table, $rows=10, $sort = "wr_datetime desc", $subCut = 99)
  {
      global $g5;
      $subject_len=40;
      $cache_time=1;

      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;
          }
      }
      if(1) {
          $list = array();

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

          $tmp_write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
          $sql = " select * from {$tmp_write_table} where wr_is_comment = 1 order by $sort limit 0, {$rows} ";
          $result = sql_query($sql);
          for ($i=0; $row = sql_fetch_array($result); $i++) {
              try {
                  unset($row['wr_password']);     //패스워드 저장 안함( 아예 삭제 )
              } catch (Exception $e) {
              }
              $row['wr_email'] = '';              //이메일 저장 안함
              if (strstr($row['wr_option'], 'secret')){           // 비밀글일 경우 내용, 링크, 파일 저장 안함
                  $row['wr_content'] = $row['wr_link1'] = $row['wr_link2'] = '';
                  $row['file'] = array('count'=>0);
              }
              $list[$i] = get_list($row, $board, $latest_skin_url, $subject_len);
              $sql = " select * from {$tmp_write_table} where wr_is_comment = 0 and wr_id = '{$row["wr_parent"]}' limit 1";
              $result2 = sql_fetch($sql);
              $list[$i]["parent"] = $result2;
          }

          if($cache_fwrite) {
              $handle = fopen($cache_file, 'w');
              $caches = array(
                  'list' => $list,
                  'bo_subject' => sql_escape_string($bo_subject),
                  );
              $cache_content = "<?php if (!defined('_GNUBOARD_')) exit; ?>\n\n";
              $cache_content .= base64_encode(serialize($caches));  //serialize

              fwrite($handle, $cache_content);
              fclose($handle);

              @chmod($cache_file, 0640);
          }
      }
      for ($i=0;$i<count($list);$i++){

        $list[$i]["subject"] = conv_subject($list[$i]['wr_content'], $subCut, '…');
      }

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

      return $content;
  }

?>
 

 

 

 

 

$sort = "wr_datetime desc" 는 wr_datetime desc : 날짜 최근것 부터

https://sir.kr/g4_tiptech/22813#c_25044 이글을 참고하셔서 맞게 수정하시면 됩니다 .

 

 

최신글 스킨 latest.skin.php 내에 추가 

  $sub = "<font style='color:#000000;'>[".$list[$i]['parent']["wr_subject"]."]</font>"; 

글 제목을 불러옵니다 

 

 <?php
            if ($list[$i]['icon_secret']) echo "<i class=\"fa fa-lock\" aria-hidden=\"true\"></i> ";
            //echo $list[$i]['icon_reply']." ";
            echo "<a href=\"".$list[$i]['href']."\" class=\"lt_tit\">";
            $sub = "<font style='color:#000000;'>[".$list[$i]['parent']["wr_subject"]."]</font>";
          if ($list[$i]['is_notice'])
              echo "<span class=title><strong>$sub".$list[$i]['subject']."</strong>";
          else
           echo "<span class=title>$sub".$list[$i]['subject']."</span>";

                // if ($list[$i]['link']['count']) { echo "[{$list[$i]['link']['count']}]"; }
                // if ($list[$i]['file']['count']) { echo "<{$list[$i]['file']['count']}>"; }

           // if ($list[$i]['icon_new']) echo " <span class=\"new_icon\">NEW</span>";
           // if ($list[$i]['icon_file']) echo " <i class=\"fa fa-download\" aria-hidden=\"true\"></i>" ;
           // if ($list[$i]['icon_link']) echo " <i class=\"fa fa-link\" aria-hidden=\"true\"></i>" ;
          //  if ($list[$i]['icon_hot']) echo " <i class=\"fa fa-heart\" aria-hidden=\"true\"></i>";

            echo "</a>";

            ?>

 

 

아직 초보이기 때문에 질문은 받지 않습니다  ㅡㅡ 

 

 

최신글 들어갈 곳 상단에 불러오기 

include_once G5_LIB_PATH."/latest_com.lib.php";

 

 

 <?php

        // 이 함수가 바로 최신글을 추출하는 역할을 합니다.

        // 사용방법 : latest(스킨, 게시판아이디, 출력라인, 글자수);

        // 테마의 스킨을 사용하려면 theme/basic 과 같이 지정

        echo latestSortComment('최근게시물스킨명', '게시판', 출력라인, 글자수);

    

 ?>

 

 

 

개인저장용 ^^ 

댓글 작성

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

로그인하기

댓글 4개

5년 전
감사합니다. ^^
감사합니다. ^----------------^;
5년 전
감사합니다
감사합니다

게시글 목록

번호 제목
24318
24317
24315
24309
24294
24293
24277
24262
24260
24253
24251
24236
24233
24228
24226
24221
24214
24203
24201
24199
24196
24195
24194
24192
24191
24187
24185
24183
24172
24168