서브페이지 브레드크럼(네비게이션) 채택완료

안녕하세요 그누보드 초보자입니다.

 

그누보드로 홈페이지를 구축하려고 하는데

조건이 서브페이지에 브레드크럼(네비게이션?)이 있어야 한다고 합니다.

브레드크럼으로 현재 페이지의 메뉴명을 자동으로 불러와야 하는데

만드는 방법이 따로 있나요?(참고할만한 링크라도...) 아니면 직접 만들 수 밖에 없나요?

답변 1개

채택된 답변
+20 포인트

* /head.php 또는 /theme/[테마명]/head.php 메뉴 출력 코드 이후 적당한 위치에 삽입

Copy
<?php
// 메인페이지가 아닌 경우에만 브레드크럼 표시
if (!defined('_INDEX_')) {
    // 현재 URL 정보 가져오기
    $current_url = $_SERVER['REQUEST_URI'];
    
    // 파라미터 추출
    $bo_table = isset($_GET['bo_table']) ? $_GET['bo_table'] : '';
    $co_id = isset($_GET['co_id']) ? $_GET['co_id'] : '';
    
    // 현재 페이지 정보 초기화
    $depth1 = null;
    $depth2 = null;
    $depth1_name = '';
    $depth2_name = '';
    $breadcrumb_html = '';
    
    // 현재 페이지가 속한 메뉴 찾기
    foreach ($menu_datas as $i => $row) {
        if (empty($row)) continue;
        
        // 1차 메뉴 링크와 현재 URL 비교
        if (($bo_table && strpos($row['me_link'], 'bo_table='.$bo_table) !== false) || 
            ($co_id && strpos($row['me_link'], 'co_id='.$co_id) !== false) || 
            (!$bo_table && !$co_id && strpos($current_url, $row['me_link']) !== false)) {
            $depth1 = $i;
            $depth1_name = $row['me_name'];
            break;
        }
        
        // 2차 메뉴 링크와 현재 URL 비교
        if (isset($row['sub']) && is_array($row['sub'])) {
            foreach ($row['sub'] as $j => $row2) {
                if (empty($row2)) continue;
                
                if (($bo_table && strpos($row2['me_link'], 'bo_table='.$bo_table) !== false) || 
                    ($co_id && strpos($row2['me_link'], 'co_id='.$co_id) !== false) || 
                    (!$bo_table && !$co_id && strpos($current_url, $row2['me_link']) !== false)) {
                    $depth1 = $i;
                    $depth2 = $j;
                    $depth1_name = $row['me_name'];
                    $depth2_name = $row2['me_name'];
                    break 2;
                }
            }
        }
    }
    
    // 브레드크럼 구성
    if ($depth1_name) {
        $breadcrumb_html = '<div class="breadcrumb">';
        $breadcrumb_html .= '<a href="'.G5_URL.'">홈</a>';
        
        if ($depth1_name) {
            $breadcrumb_html .= ' &gt; <a href="'.$menu_datas[$depth1]['me_link'].'">'.$depth1_name.'</a>';
        }
        
        if ($depth2_name) {
            $breadcrumb_html .= ' &gt; <strong>'.$depth2_name.'</strong>';
        }
        
        $breadcrumb_html .= '</div>';
        
        // 브레드크럼 출력
        echo $breadcrumb_html;
    }
}
?>

Copy
.breadcrumb {
    padding: 10px 0;
    margin-bottom: 15px;
    font-size: 14px;
}

.breadcrumb a {
    color: #666;
}

.breadcrumb strong {
    color: #333;
    font-weight: 600;
}
로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

답변 감사드립니다!

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

답변을 작성하려면 로그인이 필요합니다.

로그인
🐛 버그신고