[이윰] View 페이지에서 이전글, 다음글 버튼에 제목과 썸네일을 가져오기

페이지 정보

shadow2fox 1,541 2 2 2021.01.10 13:18

평점

  • - 평점 : 5점 (2명 참여)

본문

View 페이지에서 이전글, 다음글 버튼에 제목과 썸네일을 가져오기
전체목록보이기 사용 체크 유무에 상관없이 View 페이지에서 이전글, 다음글의 버튼이 보이고 각 버튼에 마우스를 올렸을 때 첨부된 이미지, 에디터 이미지, 동영상 썸네일, 외부 이미지 썸네일이 나오도록 해 보자.
 
외부 이미지의 썸네일도 보여지도록 아래 링크의 선행작업이 필요하다.
https://yadolee.com/bbs/board.php?bo_table=tip&wr_id=817


1. 그누보드/bbs/view.php를 열어 if (!$board['bo_use_list_view']) {를 검색하여 아래와 같이 수정한다.

수정 전

if (!$board['bo_use_list_view']) {
    if ($sql_search)
        $sql_search = " and " . $sql_search;

    // 윗글을 얻음
    $sql = " select wr_id, wr_subject, wr_datetime from {$write_table} where wr_is_comment = 0 and wr_num = '{$write['wr_num']}' and wr_reply < '{$write['wr_reply']}' {$sql_search} order by wr_num desc, wr_reply desc limit 1 ";
    $prev = sql_fetch($sql);
    // 위의 쿼리문으로 값을 얻지 못했다면
    if (! (isset($prev['wr_id']) && $prev['wr_id'])) {
        $sql = " select wr_id, wr_subject, wr_datetime from {$write_table} where wr_is_comment = 0 and wr_num < '{$write['wr_num']}' {$sql_search} order by wr_num desc, wr_reply desc limit 1 ";
        $prev = sql_fetch($sql);
    }

    // 아래글을 얻음
    $sql = " select wr_id, wr_subject, wr_datetime from {$write_table} where wr_is_comment = 0 and wr_num = '{$write['wr_num']}' and wr_reply > '{$write['wr_reply']}' {$sql_search} order by wr_num, wr_reply limit 1 ";
    $next = sql_fetch($sql);
    // 위의 쿼리문으로 값을 얻지 못했다면
    if (! (isset($next['wr_id']) && $next['wr_id'])) {
        $sql = " select wr_id, wr_subject, wr_datetime from {$write_table} where wr_is_comment = 0 and wr_num > '{$write['wr_num']}' {$sql_search} order by wr_num, wr_reply limit 1 ";
        $next = sql_fetch($sql);
    }
}
수정 후

// 주석처리, 전체목록보이기 체크시에도 이전글 다음글 버튼 나타내기
//if (!$board['bo_use_list_view']) {
    if ($sql_search)
        $sql_search = " and " . $sql_search;

    // 윗글을 얻음
    //$sql = " select wr_id, wr_subject, wr_datetime from {$write_table} where wr_is_comment = 0 and wr_num = '{$write['wr_num']}' and wr_reply < '{$write['wr_reply']}' {$sql_search} order by wr_num desc, wr_reply desc limit 1 ";
    //추가, 여분필드도 가져오기
    $sql = " select wr_id, wr_subject, wr_datetime, wr_4 from {$write_table} where wr_is_comment = 0 and wr_num = '{$write['wr_num']}' and wr_reply < '{$write['wr_reply']}' {$sql_search} order by wr_num desc, wr_reply desc limit 1 ";
    $prev = sql_fetch($sql);
    // 위의 쿼리문으로 값을 얻지 못했다면
    if (! (isset($prev['wr_id']) && $prev['wr_id'])) {
        //$sql = " select wr_id, wr_subject, wr_datetime from {$write_table} where wr_is_comment = 0 and wr_num < '{$write['wr_num']}' {$sql_search} order by wr_num desc, wr_reply desc limit 1 ";
        //추가, 여분필드도 가져오기
        $sql = " select wr_id, wr_subject, wr_datetime, wr_4 from {$write_table} where wr_is_comment = 0 and wr_num < '{$write['wr_num']}' {$sql_search} order by wr_num desc, wr_reply desc limit 1 ";
        $prev = sql_fetch($sql);
    }

    // 아래글을 얻음
    //$sql = " select wr_id, wr_subject, wr_datetime from {$write_table} where wr_is_comment = 0 and wr_num = '{$write['wr_num']}' and wr_reply > '{$write['wr_reply']}' {$sql_search} order by wr_num, wr_reply limit 1 ";
    //추가, 여분필드도 가져오기
    $sql = " select wr_id, wr_subject, wr_datetime, wr_4 from {$write_table} where wr_is_comment = 0 and wr_num = '{$write['wr_num']}' and wr_reply > '{$write['wr_reply']}' {$sql_search} order by wr_num, wr_reply limit 1 ";
    $next = sql_fetch($sql);
    // 위의 쿼리문으로 값을 얻지 못했다면
    if (! (isset($next['wr_id']) && $next['wr_id'])) {
        //$sql = " select wr_id, wr_subject, wr_datetime from {$write_table} where wr_is_comment = 0 and wr_num > '{$write['wr_num']}' {$sql_search} order by wr_num, wr_reply limit 1 ";
        //추가, 여분필드도 가져오기
        $sql = " select wr_id, wr_subject, wr_datetime, wr_4 from {$write_table} where wr_is_comment = 0 and wr_num > '{$write['wr_num']}' {$sql_search} order by wr_num, wr_reply limit 1 ";
        $next = sql_fetch($sql);
    }
//}

2. 그누보드5/eyoom/user_program/board/view.skin.php를 열어 적당한 위치에 아래 소스를 넣는다.


// 이전글 프리뷰
if (isset($prev['wr_id']) && $prev['wr_id']) {
    $prev_img = get_list_thumbnail($bo_table, $prev['wr_id'], $board['bo_gallery_width'], $board['bo_gallery_height']);
    if($prev_img['src']) {
        $prev['img_content'] = "<img class='img-responsive' src='".$prev_img['src']."' alt='".$prev_img['alt']."'>";
        $prev['img_src'] = $prev_img['src'];
    } else {
        // wr_4 unserialize
        $prev_wr_4 = unserialize($prev['wr_4']);
        if(!$prev_wr_4) $prev_wr_4 = array();
        if($prev['wr_4']) {
            $prev_img['src'] = $prev_wr_4['thumb_src'];
            if($prev_img['src']) {
                $prev['img_content'] = "<img class='img-responsive' src='".$prev_img['src']."'>";
                $prev['img_src'] = $prev_img['src'];
            } else {
                $prev_img['src'] = $prev_wr_4['extimg_thumb'];
                if($prev_img) {
                    $prev['img_content'] = "<img class='img-responsive' src='".$prev_img['src']."'>";
                    $prev['img_src'] = $prev_img['src'];
                }
            }
        }
    }
}

// 다음글 프리뷰
if (isset($next['wr_id']) && $next['wr_id']) {
    $next_img = get_list_thumbnail($bo_table, $next['wr_id'], $board['bo_gallery_width'], $board['bo_gallery_height']);
    if($next_img['src']) {
        $next['img_content'] = "<img class='img-responsive' src='".$next_img['src']."' alt='".$next_img['alt']."'>";
        $next['img_src'] = $next_img['src'];
    } else {
        // wr_4 unserialize
        $next_wr_4 = unserialize($next['wr_4']);
        if(!$next_wr_4) $next_wr_4 = array();
        if($next['wr_4']) {
            $next_img['src'] = $next_wr_4['thumb_src'];
            if($next_img['src']) {
                $next['img_content'] = "<img class='img-responsive' src='".$next_img['src']."'>";
                $next['img_src'] = $next_img['src'];
            } else {
                $next_img['src'] = $next_wr_4['extimg_thumb'];
                if($next_img) {
                    $next['img_content'] = "<img class='img-responsive' src='".$next_img['src']."'>";
                    $next['img_src'] = $next_img['src'];
                }
            }
        }
    }
}

3. 변경하고자 하는 스킨의 view.skin.html을 열어 이전글과 다음글을 아래와 같이 수정한다.

수정 전

            <!--{? _prev_href}--><li><a href="{_prev_href}" class="btn-e btn-e-light-grey" type="button">이전글</a></li><!--{/}-->
            <!--{? _next_href}--><li><a href="{_next_href}" class="btn-e btn-e-light-grey" type="button">다음글</a></li><!--{/}-->
수정 후

            <!--{? _prev_href}--><li><a href="{_prev_href}" class="btn btn-danger" type="button"{? !C.G5_IS_MOBILE} data-trigger="hover" data-placement="top auto" title="<i class='far fa-arrow-alt-circle-up'></i> {_prev_wr_subject}" data-toggle="popover" {? _prev_img}data-content="<div class='prev-img'>{_prev.img_content}</div>"{/}{/}>다음글</a></li><!--{/}-->
            <!--{? _next_href}--><li><a href="{_next_href}" class="btn btn-warning" type="button"{? !C.G5_IS_MOBILE} data-trigger="hover" data-placement="top auto" title="<i class='far fa-arrow-alt-circle-down'></i> {_next_wr_subject}" data-toggle="popover" {? _next_img}data-content="<div class='next-img'>{_next.img_content}</div>"{/}{/}>이전글</a></li><!--{/}-->
참고로 위 다음글과 이전글의 버튼 문구가 뒤바뀐 걸 알 수 있는데 버튼 위치나 순서상의 선택이니 본인 판단에 따르도록 하자.

팝업 스타일 정의하도록 view.skin.html 상단에 아래 css를 넣는다.

.popover{max-width:174px}
{? !_prev_img && !_next_img}.popover-content{display:none}{:}.popover-content{display:contents}{/}
.popover-title{font-size:11px;letter-spacing:-1px;line-height:1em;text-overflow:ellipsis;white-space:nowrap;word-wrap:normal;overflow:hidden;background:#fff;border-bottom:none}
.popover-content .prev-img, .popover-content .next-img{overflow:hidden;max-height:125px;border-bottom-left-radius:5px;border-bottom-right-radius:5px}

마우스 오버 시 팝업이 작동하도록 view.skin.html 하단 쪽에 아래 스크립트를 넣는다.

$(document).ready(function(){
    $('[data-toggle="popover"]').popover({html:true,container:'.board-view-atc',delay:{show:0,hide:0},animation:false});
    $('[data-toggle="popover"]').on('shown.bs.popover', function () {
        $('.popover-content .prev-img').addClass('animated flipInX');
        $('.popover-content .next-img').addClass('animated flipInX');
    })
});
추천인 2
  • 내사랑
  • 하늘구장
10
shadow2fox - 회원등급 : 자연/Level 142 - 포인트 : 2,539,682
레벨 142
경험치 3,034,631

Progress Bar 74%

- 가입일 : 2015-03-10 12:21:44
- 서명 : 인간에게 가장 큰 선물은 자기 자신에게 기회를 주는 것이다. - 크리스 가드너, Chris Gardner -
- 자기소개 : There's never a shortcut to happiness.

댓글2

하늘구장님의 댓글

하늘구장 2021.01.10 22:50

와우 감사합니다 좋아요

내사랑님의 댓글

내사랑 2021.01.10 14:23

멋진 팁 감사합니다 무조건 추천 적용해 보았는데 외부 이미지가 들어간 과거의 게시글은 여분필드 wr_4에 정보가 없어서 안나오더라구요 그래서 노가다로 작업하느라 진이 다 빠졌네요

축하합니다. 첫 댓글로 19경험치를 획득하였습니다.

Total 241113 페이지
제목 글쓴이 날짜 조회 추천
이윰  댓글+2 PATH만 지원되는 filemtime을 curl 이용하여  URL을 지원하도록 확장하기 shadow2fox 2023.06.13 273 2
이윰  댓글+2 비메오 썸네일 추출 올바르게 적용하기 shadow2fox 2023.04.24 456 2
이윰  댓글+2 date 시간 형식으로 출력(~전) 올바르게 해결하기 shadow2fox 2023.03.10 429 2
이윰  댓글+5 유튜브 "이 동영상은 볼 수 없습니다" 해결하기 shadow2fox 2023.02.20 979 3
이윰  댓글+2 Prism.js 플러그인 사용 시 HTML 주석 처리가 삭제되는 문제 해결하기 shadow2fox 2022.04.24 534 2
이윰  댓글+7🏆 유튜브 플레이리스트(playlist) 썸네일 추출과 올바르게 적용하기 shadow2fox 2021.09.01 2,496 3
이윰  댓글+2🏆 이윰빌더 짧은주소를 그누보드 짧은주소로 교체하기 shadow2fox 2021.08.26 1,433 2
이윰  댓글+4🏆 📸 유튜브 썸네일 생성 개선하기 루루아빠 2021.06.24 3,463 3
이윰  댓글+2🏆 글, 댓글 작성시 불필요한 앞뒤 공백 제거해 DB에 저장하기 shadow2fox 2021.06.21 1,168 2
이윰  댓글+3🏆 첨부 이미지 alt 속성 값 게시글 제목으로 보여주기 shadow2fox 2021.06.11 1,152 2
이윰  댓글+3🏆 게시글 검색 단위에 맞는 메뉴 추가하기 shadow2fox 2021.05.18 1,662 2
이윰  댓글+2🏆 글 작성 시 alt 태그 게시글 제목으로 DB에 저장하기 shadow2fox 2021.05.05 1,442 2
이윰  댓글+4🏆 다중 태그 입력 올바르게 shadow2fox 2021.03.12 1,965 2
이윰  댓글+1🏆 PHP 8.x Fatal error : 중괄호 사용으로 인한 json.class.php 오류 shadow2fox 2021.02.17 1,834 1
이윰  댓글+3🏆 PHP 8.x 지원을 위한 암호화, 복호화 함수 shadow2fox 2021.02.16 2,573 3
이윰  댓글+2🏆 게시글 작성 중복 방지하기 shadow2fox 2021.02.03 1,676 2
이윰  댓글+2🏆 🚩 View 페이지에서 이전글, 다음글 버튼에 제목과 썸네일을 가져오기 shadow2fox 2021.01.10 1,542 2
이윰  댓글+5🏆 게시글 작성 시 외부 이미지를 저장하여 썸네일화하기 shadow2fox 2021.01.01 2,520 2
이윰  댓글+2🏆 EXIF 정보 이미지 넓이에 맞게 조정하기 shadow2fox 2020.11.21 1,809 2
이윰  댓글+2🏆 추천 베스트 최신글에서 블라인드 게시글은 제외하기 shadow2fox 2020.11.13 1,419 2