하나의 카테고리에서 두개의 카테고리 상품출력하기 - 연관카테고리기능(?) > 영카트5 팁자료실

영카트5 팁자료실

하나의 카테고리에서 두개의 카테고리 상품출력하기 - 연관카테고리기능(?) 정보

하나의 카테고리에서 두개의 카테고리 상품출력하기 - 연관카테고리기능(?)

첨부파일

list.99.skin.php (5.0K) 18회 다운로드 2015-09-14 11:56:26

본문

http://sir.co.kr/qa/89295 에 문의글 올라온 것을 보고 간단히 만들어봤습니다.

basic 스킨의 list.10.skin.php 을 복사해서 만든 것이므로 다른 리스트 스킨을 사용하시는 분들은 올려드린 파일의 12라인~48라인을 기존의 사용하시는 리스트 스킨파일의 for 루프문이 시작되는 부분을 대체해 넣어주시면 됩니다.

그리고 ca_id, ca_id2, ca_id3 를 설정하시듯이 카테고리 설정의 여분필드 ca_1, ca_2, ca_3 에 카테고리번호값들을 설정해주시면 됩니다. 일단은 문의글에서 한줄에 4개라고 지정하셔서 $relate_caid_start 변수에 4를 지정해서 기존의 카테고리 상품을 4개까지만 출력되고 그 이후 상품은 연관카테고리로 지정하신 ca_1, ca_2, ca_3 의 상품이 기존 카테고리의 설정값 1행이미지수, 이미지행수의 값에 맞게 출력되도록 되어 있습니다. 문의글대로 하시려면 두가지값을 각각 4와 1로 설정하시면 기존 카테고리 4개, 연관카테고리 4개의 상품이 출력될 것입니다.

스킨파일이긴 한데.. 스킨게시판에 올리기엔 간단한 내용이라 팁 자료실에 올립니다.
아래는 올려드린 파일의 소스입니다.
12~48라인을 참고하시면 됩니다.

아.. 이 파일은 당연히도(?) /skin/shop/사용하시는 스킨 또는 없으면 basic/ 디렉토리에 올려주시면 됩니다.


<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가

// add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
add_stylesheet('', 0);

// 관련상품 스킨은 사품을 한줄에 하나만 표시하며 해당 상품에 관련상품이 등록되어 있는 경우 기본으로 7개까지 노출합니다.
?>


<?php
/**
 * 연관카테고리 출력하기
 * @refer ca_1 : ca_id 숫자
 * @refer ca_2 : ca_id2 숫자
 * @refer ca_3 : ca_id3 숫자
 * @variable relate_caid_start : 기존의 카테고리 출력갯수 숫자
 * @etc : 기타 참조하는 값들은 기존의 카테고리 설정값을 따른다.
 */
$relate_caid_start = 4;
$sql = " select * from {$g5['g5_shop_category_table']} where ca_id = '".$this->ca_id."' and ca_use = '1'  ";
$ca = sql_fetch($sql);

if ($ca['ca_1'] || $ca['ca_2'] || $ca['ca_3']) {
    $where_ca_id = $where2 = array();
    if ($ca['ca_1']) {
        $where_ca_id[] = " ca_id like '{$ca['ca_1']}%' ";
    }
    if ($ca['ca_2']) {
        $where_ca_id[] = " ca_id2 like '{$ca['ca_2']}%' ";
    }
    if ($ca['ca_3']) {
        $where_ca_id[] = " ca_id3 like '{$ca['ca_3']}%' ";
    }
    $where2[] = " ( " . implode(" or ", $where_ca_id) . " ) ";
    $sql_where = " where " . implode(" and ", $where2);

    if ($this->order_by) {
        $sql_order = " order by {$this->order_by} ";
    }

    $sql_select = " select * from `{$g5['g5_shop_item_table']}` ";
    $sql_limit = " limit " . $this->from_record . " , " . ($this->list_mod * $this->list_row);
    $sql = $sql_select . $sql_where . $sql_order . $sql_limit;
    $result2 = sql_query($sql);
}

for ($i=1; $row = ($i>$relate_caid_start && $result2) ? sql_fetch_array($result2) : sql_fetch_array($result); $i++) {
    $href = G5_SHOP_URL.'/item.php?it_id='.$row['it_id'];
    if ($list_mod >= 2) { // 1줄 이미지 : 2개 이상
        if ($i%$list_mod == 0) $sct_last = ' sct_last'; // 줄 마지막
        else if ($i%$list_mod == 1) $sct_last = ' sct_clear'; // 줄 첫번째
        else $sct_last = '';
    } else { // 1줄 이미지 : 1개
        $sct_last = ' sct_clear';
    }

    if ($i == 1) {
        if ($this->css) {
            echo "css}\">\n";
        } else {
            echo "\n";
        }
   }

    $list_top_pad = 20;
    $list_right_pad = 10;
    $list_bottom_pad = 20;
    $list_left_pad = $this->img_width + 10;
    $list_real_width = 740;
    $list_width = $list_real_width - $list_right_pad - $list_left_pad;
    $list_height = $this->img_height - $list_top_pad - $list_bottom_pad;

    echo "\n";

    if ($this->href) {
        echo "href}{$row['it_id']}\" class=\"sct_a\">\n";
    }

    if ($this->view_it_img) {
        echo get_it_image($row['it_id'], $this->img_width, $this->img_height, '', '', stripslashes($row['it_name']))."\n";
    }

    if ($this->href) {
        echo "
\n";
    }

    if ($this->view_it_icon) {
        echo "".item_icon($row)."
\n";
    }

    if ($this->view_it_id) {
        echo "<".stripslashes($row['it_id']).">
\n";
    }

    if ($this->href) {
        echo "href}{$row['it_id']}\" class=\"sct_a\">\n";
    }

    if ($this->view_it_name) {
        echo stripslashes($row['it_name'])."\n";
    }

    if ($this->href) {
        echo "
\n";
    }

    if ($this->view_it_basic && $row['it_basic']) {
        echo "".stripslashes($row['it_basic'])."
\n";
    }

    if ($this->view_it_cust_price || $this->view_it_price) {

        echo "\n";

        if ($this->view_it_cust_price && $row['it_cust_price']) {
            echo "".display_price($row['it_cust_price'])."\n";
        }

        if ($this->view_it_price) {
            echo display_price(get_price($row), $row['it_tel_inq'])."\n";
        }

        echo "
\n";

    }

    if ($this->view_sns) {
        $sns_url  = G5_SHOP_URL.'/item.php?it_id='.$row['it_id'];
        $sns_title = get_text($row['it_name']).' | '.get_text($config['cf_title']);
        echo "";
        echo get_sns_share_link('facebook', $sns_url, $sns_title, G5_SHOP_SKIN_URL.'/img/sns_fb_s.png');
        echo get_sns_share_link('twitter', $sns_url, $sns_title, G5_SHOP_SKIN_URL.'/img/sns_twt_s.png');
        echo get_sns_share_link('googleplus', $sns_url, $sns_title, G5_SHOP_SKIN_URL.'/img/sns_goo_s.png');
        echo "
\n";
    }

    // 관련상품
    echo "".relation_item($row['it_id'], 70, 0, 5)."
\n";

    echo "\n";
}

if ($i > 1) echo "\n";

if($i == 1) echo "등록된 상품이 없습니다.
\n";
?>

추천
1

댓글 2개

전체 392
영카트5 팁자료실 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT