계층형 카테고리를 게시판 왼쪽에 트리목록으로 출력하고 싶습니다.

https://imgur.com/a/FiIv3Ql

 

위 링크의 첫번째 이미지 처럼 게시판 왼쪽에 계층형 트리를 목록형으로 출력하고 싶습니다.

두번째 그림은 계층형 카테고리를 셋팅한거구요.

세번째 그림은 테스트코드를 작성해보았습니다.

네 번째 그림은 결과인데요. 이상하게 테스트2 카테고리 밑에 ㅁㄴㅇ나와야 하는데 첫번째 아이템의 자식들이 반복됩니다.

 

첫번째 이미지처럼 계층형 카테고리를 트리형태로 게시판 왼쪽에 목록으로 출력하고 싶은데 어떻게 해야 하나요?

추가적으로 각 카테고리별 게시물수도 표시하고 싶습니다.

좋은 정보와 인맥을 동시에, 워드프레스 사용자 단톡방 참여하기
좋은 정보와 인맥을 동시에, 워드프레스 사용자 단톡방 참여하기
  •  안녕하세요~^^

    올려주신 내용처럼 카테고리 계층형을 변경하시려면

    wp-content/plugins/kboard/skin/사용중인 스킨/list-category-tree-tab.php 파일 중 아래 코드 부분을

    		<div class="kboard-tree-category-wrap">
    			<?php $tree_category_list = $board->tree_category->getCategoryItemList()?>
    			<div class="kboard-search-option-wrap-<?php echo $board->tree_category->depth?> kboard-search-option-wrap type-tab">
    				<input type="hidden" name="kboard_search_option[tree_category_<?php echo $board->tree_category->depth?>][key]" value="tree_category_<?php echo $board->tree_category->depth?>">
    				<input type="hidden" name="kboard_search_option[tree_category_<?php echo $board->tree_category->depth?>][value]" value="<?php echo $board->tree_category->getCategoryNameWithDepth($board->tree_category->depth)?>">
    				<ul class="kboard-tree-category">
    					<li<?php if(!$board->tree_category->getCategoryNameWithDepth($board->tree_category->depth)):?> class="kboard-category-selected"<?php endif?>><a href="#" onclick="return kboard_tree_category_search('<?php echo $board->tree_category->depth?>', '')"><?php echo __('All', 'kboard')?></a></li>
    					<?php foreach($tree_category_list as $item):?>
    					<li<?php if($board->tree_category->getCategoryNameWithDepth($board->tree_category->depth) == $item['category_name']):?> class="kboard-category-selected"<?php endif?>><a href="#" onclick="return kboard_tree_category_search('<?php echo $board->tree_category->depth?>', '<?php echo $item['category_name']?>')"><?php echo $item['category_name']?></a></li>
    					<?php endforeach?>
    				</ul>
    			</div>
    			
    			<?php foreach($board->tree_category->getSelectedList() as $key=>$category_name):?>
    				<?php $tree_category_list = $board->tree_category->getCategoryItemList($category_name)?>
    				<?php if($tree_category_list):?>
    				<div class="kboard-search-option-wrap-<?php echo $board->tree_category->depth?> kboard-search-option-wrap type-tab">
    					<input type="hidden" name="kboard_search_option[tree_category_<?php echo $board->tree_category->depth?>][key]" value="tree_category_<?php echo $board->tree_category->depth?>">
    					<input type="hidden" name="kboard_search_option[tree_category_<?php echo $board->tree_category->depth?>][value]" value="<?php echo $board->tree_category->getCategoryNameWithDepth($board->tree_category->depth)?>">
    					<ul class="kboard-tree-category">
    						<li<?php if(!$board->tree_category->getCategoryNameWithDepth($board->tree_category->depth)):?> class="kboard-category-selected"<?php endif?>><a href="#" onclick="return kboard_tree_category_search('<?php echo $board->tree_category->depth?>', '')"><?php echo __('All', 'kboard')?></a></li>
    						<?php foreach($tree_category_list as $item):?>
    						<li<?php if($board->tree_category->getCategoryNameWithDepth($board->tree_category->depth) == $item['category_name']):?> class="kboard-category-selected"<?php endif?>><a href="#" onclick="return kboard_tree_category_search('<?php echo $board->tree_category->depth?>', '<?php echo $item['category_name']?>')"><?php echo $item['category_name']?></a></li>
    						<?php endforeach?>
    					</ul>
    				</div>
    				<?php endif?>
    			<?php endforeach?>
    		</div>

    아래 코드로 변경해보시겠어요?

    		<div class="kboard-tree-category-wrap">
    			<?php $tree_category_list = $board->tree_category->getCategoryItemList()?>
    			<div class="kboard-search-option-wrap-<?php echo $board->tree_category->depth?> kboard-search-option-wrap type-tab">
    				<input type="hidden" name="kboard_search_option[tree_category_1][key]" value="tree_category_1">
    				<input type="hidden" name="kboard_search_option[tree_category_1][value]" value="<?php echo $board->tree_category->getCategoryNameWithDepth('1')?>">
    				<ul class="kboard-tree-category">
    					<li <?php if(!$board->tree_category->getCategoryNameWithDepth($board->tree_category->depth)):?> class="kboard-category-selected"<?php endif?>><a href="#" onclick="return kboard_tree_category_search('<?php echo $board->tree_category->depth?>', '')"><?php echo __('All', 'kboard')?></a></li>
    					<?php foreach($tree_category_list as $item):?>
    					<li <?php if($board->tree_category->getCategoryNameWithDepth('1') == $item['category_name']):?> class="kboard-category-selected"<?php endif?>>
    						<a href="#" onclick="return kboard_tree_category_search('1', '<?php echo $item['category_name']?>')"><?php echo $item['category_name']?></a>
    
    						<?php foreach($board->tree_category->getSelectedList() as $key=>$category_name):?>
    							<?php $tree_category_list = $board->tree_category->getCategoryItemList($category_name)?>
    							<?php if($tree_category_list && $category_name == $item['category_name']):?>
    							<div class="kboard-search-option-wrap-<?php echo $board->tree_category->depth?> kboard-search-option-wrap type-tab">
    								<input type="hidden" name="kboard_search_option[tree_category_2][key]" value="tree_category_2">
    								<input type="hidden" name="kboard_search_option[tree_category_2][value]" value="<?php echo $board->tree_category->getCategoryNameWithDepth('2')?>">
    								<ul class="kboard-tree-category">
    									<?php foreach($tree_category_list as $item):?>
    									<li <?php if($board->tree_category->getCategoryNameWithDepth('2') == $item['category_name']):?> class="kboard-category-selected"<?php endif?>>
    										<a href="#" onclick="return kboard_tree_category_search('<?php echo $board->tree_category->depth?>', '<?php echo $item['category_name']?>')"><?php echo $item['category_name']?></a>
    									</li>
    									<?php endforeach?>
    								</ul>
    							</div>
    							<?php endif?>
    						<?php endforeach?>
    					</li>
    					<?php endforeach?>
    				</ul>
    			</div>
    		</div>

    위 코드는 1단 2단까지만 출력되도록 구성되어 있습니다. 

    이후 카테고리의 CSS는 적절히 조정하셔서 사용하시면 될 듯 합니다.

     

    카테고리별 게시글 수는 아래 링크를 참고해주시겠어요?

    https://www.cosmosfarm.com/threads/document/13544

    고맙습니다.

  • 감사합니다!
워드프레스 에러 기술지원 서비스 전문가에게 맡기세요