K보드 댓글 목록 출력 숏코드 Pagination 적용 방법

운영자님 안녕하세요.

아래와 같이 댓글목록을 출력하는 숏코드를 만들었습니다. 아래 숏코드를 사용하면 아래 링크와 같이 특정 사용자의 댓글 목록이 출력됩니다.

https://www.oppadu.com/user-comments/?target_uid=1

현재 숏코드에는 30개 limit을 걸어서 출력하는데, 이 limit을 해제하고 게시판처럼 pagination을 줘서 불러오면 좋을 듯 한데,

막상 적용하려니 게시판 플러그인의 어느 부분을 참고하면 좋을 지 모르겠습니다.

아래 명령문에 k보드 게시판 형태의 pagination을 어떻게 추가할 수 있는지 알 수 있을까요? ㅜ

기존 게시판 플러그인에서 참고할 부분을 말씀해주시면 연구해서 반영해보겠습니다.

항상 빠르고 정확한 답변 진심으로 감사드립니다.

<?php
/***********************************************
 * K보드 사용자 댓글 목록 출력
 **********************************************/
add_shortcode('myuser_kboard_comment', 'myuser_kboard_comment_shortcode');
function myuser_kboard_comment_shortcode($atts) {
	
	extract(shortcode_atts(array(
		'limit'   => '30',
	), $atts));
	
	global $wpdb;
	
	$user_id = isset($_GET['target_uid']) ? esc_sql($_GET['target_uid']) : ''; 
	$where[] = "`user_uid`='{$user_id}'";
	
	$where = implode(' AND ', $where);
	$results = $wpdb->get_results("SELECT `uid` FROM `{$wpdb->prefix}kboard_comments` WHERE {$where} ORDER BY `created` DESC LIMIT {$limit}");
	$output = '' ;
	$output .= '<div id="kboard-default-list">';

	if(!$results){
		$output .= '<div class="kboard-list"><p>작성한 댓글이 없습니다.</p></div>';
		$output .= '</div>';
	}
	else{
		
		$url = new KBUrl();
		$i = count($results);
		
		$output .= '<div class="kboard-list"><table>';
		$output .= '<thead><tr>';
		$output .= '<td class="kboard-list-uid">번호</td>';		
		$output .= '<td class="kboard-list-title">댓글</td>';
		$output .= '<td class="kboard-list-date">날짜</td>';
		$output .= '</tr></thead>';
		
		foreach($results as $row){
			$output .= '<tbody><tr>';
			
			$comment = new KBComment();
			$comment->initWithUID($row->uid);
			$document = new KBContent();
			$document->initWithUID($comment->content_uid);
			$new = '';
			$selected = '';
			
			if($document->isNew()) {
				$new = '<span class="kboard-default-new-notify">New</span>';
			}
			
			if($comment->Selected == 1) {
				$selected = '<span class="selected-text"><i class="fas fa-medal"></i> 채택된 답변</span>';
			}
			
			$output .= '<td class="kboard-list-uid">' .$i-- . '</td>';	
			$output .= '<td class="kboard-list-title"><a href="'.$url->getDocumentRedirect($comment->content_uid).'" target="_blank">';
			$output .= '<div class="kboard-list-content-title">'. $new . ' ' .$document->title . ' ' . $selected . '</div>';
			$output .= $comment->content;
			$output .= '</a></td>';
			$output .= '<td class="kboard-list-date"><div class="myuser-comment-item-date">' . date('Y.m.d', strtotime($comment->created)) . '</td>';
			
			$output .= '</tr>';
		}
		
		$output .= '</tbody></table></div>';
		$output .= '</div>';
	}
	
	return $output;
}

 

워드프레스 에러 기술지원 서비스 전문가에게 맡기세요
워드프레스 에러 기술지원 서비스 전문가에게 맡기세요
  • 빠른 답변 감사드립니다.

    Paging 확인해서 숏코드 완성했습니다.^^

    댓글목록 숏코드가 필요한 다른 분께 도움이 되었으면 좋겠습니다.

    감사합니다.

    <?php
    /***********************************************
     * K보드 사용자 댓글 목록 출력
     **********************************************/
    add_shortcode('myuser_kboard_comment', 'myuser_kboard_comment_shortcode');
    function myuser_kboard_comment_shortcode($atts) {
    	
    	extract(shortcode_atts(array(
    		'limit'   => '',
    	), $atts));
    	
    	global $wpdb;
    	
    	$user_id = isset($_GET['target_uid']) ? esc_sql($_GET['target_uid']) : ''; 
    	if(isset($_GET['pageid'])){ 
    	$page_id = $_GET['pageid']; 
    	}else{ 
    	$page_id = 1; 
    	}
    	
    	$limit = 20;
    	$where[] = "`user_uid`='{$user_id}'";
    	$where = implode(' AND ', $where);
    	
    	$tot_results = $wpdb->get_results("SELECT `uid` FROM `{$wpdb->prefix}kboard_comments` WHERE {$where}");
    	$row_num = count($tot_results);
    	
    	$start_num = ($page_id -1) * $limit;
    	$results = $wpdb->get_results("SELECT `uid` FROM `{$wpdb->prefix}kboard_comments` WHERE {$where} ORDER BY `created` DESC LIMIT {$start_num}, {$limit}");
    	
    	$output = '' ;
    	$output .= '<div id="kboard-default-list">';
    
    	if(!$results){
    		$output .= '<div class="kboard-list"><p>작성한 댓글이 없습니다.</p></div>';
    		$output .= '</div>';
    	}
    	else{
    		
    		$url = new KBUrl();
    		$i = $row_num - $start_num;
    		
    		// 댓글 목록 출력
    		$output .= '<div class="kboard-list"><table>';
    		$output .= '<thead><tr>';
    		$output .= '<td class="kboard-list-uid">번호</td>';		
    		$output .= '<td class="kboard-list-title">댓글</td>';
    		$output .= '<td class="kboard-list-date">날짜</td>';
    		$output .= '</tr></thead>';
    		
    		foreach($results as $row){
    			$output .= '<tbody><tr>';
    			
    			$comment = new KBComment();
    			$comment->initWithUID($row->uid);
    			$document = new KBContent();
    			$document->initWithUID($comment->content_uid);
    			$new = '';
    			$selected = '';
    			
    			if($document->isNew()) {
    				$new = '<span class="kboard-default-new-notify">New</span>';
    			}
    			
    			if($comment->Selected == 1) {
    				$selected = '<span class="selected-text"><i class="fas fa-medal"></i> 채택된 답변</span>';
    			}
    			
    			$output .= '<td class="kboard-list-uid">' .$i-- . '</td>';	
    			$output .= '<td class="kboard-list-title"><a href="'.$url->getDocumentRedirect($comment->content_uid).'" target="_blank">';
    			$output .= '<div class="kboard-list-content-title">'. $new . ' ' .$document->title . ' ' . $selected . '</div>';
    			$output .= $comment->content;
    			$output .= '</a></td>';
    			$output .= '<td class="kboard-list-date"><div class="myuser-comment-item-date">' . date('Y.m.d', strtotime($comment->created)) . '</td>';
    			
    			$output .= '</tr>';
    		}
    		
    		$output .= '</tbody></table></div>';
    		
    		// 페이징
    		$output .= '<div class="kboard-pagination">';
    		$output .= '<ul class="kboard-pagination-pages">';
    		$output .= kboard_pagination($page_id, $row_num, $limit);
    		$output .= '</ul></div>';
    		
    		$output .= '</div>';
    	}
    	
    	return $output;
    }

     

  • 안녕하세요~^^

    KBoard 플러그인에서 페이징은 kboard_pagination 함수를 활용하고 있습니다.

    별도로 페이징 기능을 추가하시려면 kboard_pagination 함수를 참고해보시겠어요?

    해당 함수는

    FTP로 접속해서 /wp-content/plugins/kboard/helper/Pagination.helper.php 파일에서 확인해보실 수 있습니다.

    구글에 "PHP 페이징" 키워드로 검색해서 다른 자료들도 참고해보세요.

    고맙습니다.

좋은 정보와 인맥을 동시에, 워드프레스 사용자 단톡방 참여하기