비너스웹진 게시판 게시글에 사진없을 경우 기본 썸네일 지정하는 방법 알고 싶습니다.

안녕하세요. 스레드 봇님!

비너스웹진 게시판을 쓰고 있습니다.

사용하다 보니 게시글에 사진없을 경우 썸네일이 아무것도 안나타나는 경우가 있던데

이렇게 게시글에 사진이 없더라도 기본 특정 이미지를 자동으로 썸네일로 넣는 방법이 있는지 알고 싶습니다. ^^

워드프레스 에러 기술지원 서비스 전문가에게 맡기세요
좋은 정보와 인맥을 동시에, 워드프레스 사용자 단톡방 참여하기
  • 안녕하세요~^^

    KBoard 플러그인 최신 버전을 사용 중이시라면

    kboard_content_get_thumbnail 필터로 썸네일이 없을 때 기본 썸네일을 설정하실 수 있습니다.

     

    워드프레스 관리자 -> 외모(테마 디자인) -> 테마 편집기 페이지에서 functions.php 파일 하단에

    아래의 코드를 추가해보시겠어요?

    add_filter('kboard_content_get_thumbnail', 'my_kboard_content_get_thumbnail', 10, 4);
    function my_kboard_content_get_thumbnail($thumbnail_url, $width, $height, $content){
    	$board = $content->getBoard();
    
    	if(!$thumbnail_url && $board->id == '1'){ // 실제 게시판 id로 변경해주세요.
    		$thumbnail_url = '이미지주소';
    	}
    	
    	return $thumbnail_url;
    }

    위의 코드에서 $board->id == '1' 부분은 실제 게시판 id로 적용하신 후

    이미지주소 부분에는 실제 이미지 주소로 교체해서 확인해보시겠어요?

    고맙습니다.

  • <?php 
    function theme_enqueue_styles() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
        wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( 'parent-style' ) );
    }
    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    
    
    add_filter('kboard_list_where', 'today_best_kboard_list_where', 10, 3);
    function today_best_kboard_list_where($where, $board_id, $content_list){
    	$keyword = kboard_keyword();
    	$target = kboard_target();
    	
    	if($board_id == '21'){ // 실제 적용될 베스트 게시판의 ID값으로 변경해주세요.
    		$vote = '3';
    		if($keyword){
    			$keyword = "%{$keyword}%";
    			if($target){
    				$where = "`vote`>='{$vote}' AND `{$target}` LIKE '{$keyword}' AND `parent_uid`='0' AND `notice`='' AND (`status`='' OR `status` IS NULL OR `status`='pending_approval')";
    			}
    			else{
    				$where = "`vote`>='{$vote}' AND (`title` LIKE '{$keyword}' OR `content` LIKE '{$keyword}' OR `member_display` LIKE '{$keyword}') AND `parent_uid`='0' AND `notice`='' AND (`status`='' OR `status` IS NULL OR `status`='pending_approval')";
    			}
    		}
    		else{
    			$where = "`vote`>='{$vote}' AND `parent_uid`='0' AND `notice`='' AND (`status`='' OR `status` IS NULL OR `status`='pending_approval')";
    		}
    	}
    	
    	if($board_id == '22'){ // 실제 적용될 베스트 오브 베스트 게시판의 ID값으로 변경해주세요.
    		$vote = '5';
    		if($keyword){
    			$keyword = "%{$keyword}%";
    			if($target){
    				$where = "`vote`>='{$vote}' AND `{$target}` LIKE '{$keyword}' AND `parent_uid`='0' AND `notice`='' AND (`status`='' OR `status` IS NULL OR `status`='pending_approval')";
    			}
    			else{
    				$where = "`vote`>='{$vote}' AND (`title` LIKE '{$keyword}' OR `content` LIKE '{$keyword}' OR `member_display` LIKE '{$keyword}') AND `parent_uid`='0' AND `notice`='' AND (`status`='' OR `status` IS NULL OR `status`='pending_approval')";
    			}
    		}
    		else{
    			$where = "`vote`>='{$vote}' AND `parent_uid`='0' AND `notice`='' AND (`status`='' OR `status` IS NULL OR `status`='pending_approval')";
    		}
    	}
    	
    	if($board_id == '61'){ // 실제 게시판 id로 적용해주세요.
    		if($keyword){
    			$keyword = "%{$keyword}%";
    			if($target){
    				$where .= "OR `board_id` IN ('20','9','24','25','26','13','14','15','17','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','45','46','47','50','51','52','53','54','55','56','57','58','59','62') AND `{$target}` LIKE '{$keyword}' AND `parent_uid`='0' AND `notice`='' AND (`status`='' OR `status` IS NULL OR `status`='pending_approval')";
    			}
    			else{
    				$where .= "OR `board_id` IN ('20','9','24','25','26','13','14','15','17','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','45','46','47','50','51','52','53','54','55','56','57','58','59','62') AND (`title` LIKE '{$keyword}' OR `content` LIKE '{$keyword}' OR `member_display` LIKE '{$keyword}') AND `parent_uid`='0' AND `notice`='' AND (`status`='' OR `status` IS NULL OR `status`='pending_approval')";
    			}
    		}
    		else{
    			$where .= " OR `board_id` IN ('20','9','24','25','26','13','14','15','17','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','45','46','47','50','51','52','53','54','55','56','57','58','59','62')";
    		}
    	}
    	
    	return $where;
    }
    
    add_filter('kboard_allowed_board_id', 'my_kboard_allowed_board_id1', 10, 2);
    function my_kboard_allowed_board_id1($allowed_board_id, $board_id){
    	if($allowed_board_id == '21'){ // 베스트 게시판
    		$allowed_board_id = array('21','22','61','20','9','24','25','26','13','14','15','17','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','45','46','47','50','51','52','53','54','55','56','57','58','59','62'); // 자신과 다른 게시판의 ID값을 입력
    	}
    	else if($allowed_board_id == '22'){ // 베스트 오브 베스트 게시판
    		$allowed_board_id = array('22','21','61','20','9','24','25','26','13','14','15','17','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','45','46','47','50','51','52','53','54','55','56','57','58','59','62'); // 자신과 다른 게시판의 ID값을 입력
    	}
                 else if($allowed_board_id == '61'){ // 베스트 오브 베스트 게시판
    		$allowed_board_id = array('22','21','61','20','9','24','25','26','13','14','15','17','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','45','46','47','50','51','52','53','54','55','56','57','58','59','62'); // 자신과 다른 게시판의 ID값을 입력
    	}
    	return $allowed_board_id;
    }
    
    
    
    
    add_filter('kboard_list_where', 'today_best_kboard_list_where', 10, 3);
    function today_best_kboard_kboard_list_where($where, $board_id, $content_list){
        $keyword = kboard_keyword();
        $target = kboard_target();
        
        if(in_array($board_id, array('21','22','61'))){ // 실제 적용될 게시판의 ID값으로 변경해주세요.
            $date = date('Ym01000000', current_time('timestamp')); // 이번달 시작 날짜 기준
            if($keyword){
                $keyword = "%{$keyword}%";
                if($target){
                    $where = "`date`>='{$date}' AND `{$target}` LIKE '{$keyword}' AND `parent_uid`='0' AND `notice`='' AND (`status`='' OR `status` IS NULL OR `status`='pending_approval')";
                }
                else{
                    $where = "`date`>='{$date}' AND (`title` LIKE '{$keyword}' OR `content` LIKE '{$keyword}' OR `member_display` LIKE '{$keyword}') AND `parent_uid`='0' AND `notice`='' AND (`status`='' OR `status` IS NULL OR `status`='pending_approval')";
                }
            }
            else{
                $where = "`date`>='{$date}' AND `parent_uid`='0' AND `notice`='' AND (`status`='' OR `status` IS NULL OR `status`='pending_approval')";
            }
        }
        
        return $where;
    }
    
    
    
    add_filter('kboard_content_get_thumbnail', 'my_kboard_content_get_thumbnail', 10, 3);
    function my_kboard_content_get_thumbnail($thumbnail_url, $width, $height, $content){
    	$board = $content->getBoard();
    
    	if(!$thumbnail_url && $board->id =='22','21','61','20','9','24','25','26','13','14','15','17','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','45','46','47','50','51','52','53','54','55','56','57','58','59','62'){ // 실제 게시판 id로 변경해주세요.
    		$thumbnail_url = 'https://lomon.com/wp-content/uploads/kboard_attached/16/201908/5d4d995d461768214488.png';
    	}
    	
    	return $thumbnail_url;
    }
    

    필터가 많아서 그런지 Parse error: syntax error, unexpected ',' in /lomon/www/wp-content/themes/Avada-child/functions.php on line 112

    The site is experiencing technical difficulties. 오류가 뜨네요 ㅠ

  • 안녕하세요.

    워드프레스에서 필터는 여러 개 추가하셔도 문제 되지 않습니다.

    올려주신 코드를 보니 코드를 잘못 수정하신 듯합니다.

    여러 개의 게시판에 적용하실 땐 $board->id == '1' 부분을

    in_array($board->id, array('1','2','3')) 이런 식으로 교체해서 확인해보시겠어요?

    고맙습니다.

  • <?php 
    function theme_enqueue_styles() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
        wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( 'parent-style' ) );
    }
    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    
    
    add_filter('kboard_list_where', 'today_best_kboard_list_where', 10, 3);
    function today_best_kboard_list_where($where, $board_id, $content_list){
    	$keyword = kboard_keyword();
    	$target = kboard_target();
    	
    	if($board_id == '21'){ // 실제 적용될 베스트 게시판의 ID값으로 변경해주세요.
    		$vote = '3';
    		if($keyword){
    			$keyword = "%{$keyword}%";
    			if($target){
    				$where = "`vote`>='{$vote}' AND `{$target}` LIKE '{$keyword}' AND `parent_uid`='0' AND `notice`='' AND (`status`='' OR `status` IS NULL OR `status`='pending_approval')";
    			}
    			else{
    				$where = "`vote`>='{$vote}' AND (`title` LIKE '{$keyword}' OR `content` LIKE '{$keyword}' OR `member_display` LIKE '{$keyword}') AND `parent_uid`='0' AND `notice`='' AND (`status`='' OR `status` IS NULL OR `status`='pending_approval')";
    			}
    		}
    		else{
    			$where = "`vote`>='{$vote}' AND `parent_uid`='0' AND `notice`='' AND (`status`='' OR `status` IS NULL OR `status`='pending_approval')";
    		}
    	}
    	
    	if($board_id == '22'){ // 실제 적용될 베스트 오브 베스트 게시판의 ID값으로 변경해주세요.
    		$vote = '5';
    		if($keyword){
    			$keyword = "%{$keyword}%";
    			if($target){
    				$where = "`vote`>='{$vote}' AND `{$target}` LIKE '{$keyword}' AND `parent_uid`='0' AND `notice`='' AND (`status`='' OR `status` IS NULL OR `status`='pending_approval')";
    			}
    			else{
    				$where = "`vote`>='{$vote}' AND (`title` LIKE '{$keyword}' OR `content` LIKE '{$keyword}' OR `member_display` LIKE '{$keyword}') AND `parent_uid`='0' AND `notice`='' AND (`status`='' OR `status` IS NULL OR `status`='pending_approval')";
    			}
    		}
    		else{
    			$where = "`vote`>='{$vote}' AND `parent_uid`='0' AND `notice`='' AND (`status`='' OR `status` IS NULL OR `status`='pending_approval')";
    		}
    	}
    	
    	if($board_id == '61'){ // 실제 게시판 id로 적용해주세요.
    		if($keyword){
    			$keyword = "%{$keyword}%";
    			if($target){
    				$where .= "OR `board_id` IN ('20','9','24','25','26','13','14','15','17','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','45','46','47','50','51','52','53','54','55','56','57','58','59','62') AND `{$target}` LIKE '{$keyword}' AND `parent_uid`='0' AND `notice`='' AND (`status`='' OR `status` IS NULL OR `status`='pending_approval')";
    			}
    			else{
    				$where .= "OR `board_id` IN ('20','9','24','25','26','13','14','15','17','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','45','46','47','50','51','52','53','54','55','56','57','58','59','62') AND (`title` LIKE '{$keyword}' OR `content` LIKE '{$keyword}' OR `member_display` LIKE '{$keyword}') AND `parent_uid`='0' AND `notice`='' AND (`status`='' OR `status` IS NULL OR `status`='pending_approval')";
    			}
    		}
    		else{
    			$where .= " OR `board_id` IN ('20','9','24','25','26','13','14','15','17','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','45','46','47','50','51','52','53','54','55','56','57','58','59','62')";
    		}
    	}
    	
    	return $where;
    }
    
    add_filter('kboard_allowed_board_id', 'my_kboard_allowed_board_id1', 10, 2);
    function my_kboard_allowed_board_id1($allowed_board_id, $board_id){
    	if($allowed_board_id == '21'){ // 베스트 게시판
    		$allowed_board_id = array('21','22','61','20','9','24','25','26','13','14','15','17','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','45','46','47','50','51','52','53','54','55','56','57','58','59','62'); // 자신과 다른 게시판의 ID값을 입력
    	}
    	else if($allowed_board_id == '22'){ // 베스트 오브 베스트 게시판
    		$allowed_board_id = array('22','21','61','20','9','24','25','26','13','14','15','17','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','45','46','47','50','51','52','53','54','55','56','57','58','59','62'); // 자신과 다른 게시판의 ID값을 입력
    	}
                 else if($allowed_board_id == '61'){ // 베스트 오브 베스트 게시판
    		$allowed_board_id = array('22','21','61','20','9','24','25','26','13','14','15','17','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','45','46','47','50','51','52','53','54','55','56','57','58','59','62'); // 자신과 다른 게시판의 ID값을 입력
    	}
    	return $allowed_board_id;
    }
    
    
    
    
    add_filter('kboard_list_where', 'today_best_kboard_list_where', 10, 3);
    function today_best_kboard_kboard_list_where($where, $board_id, $content_list){
        $keyword = kboard_keyword();
        $target = kboard_target();
        
        if(in_array($board_id, array('21','22','61'))){ // 실제 적용될 게시판의 ID값으로 변경해주세요.
            $date = date('Ym01000000', current_time('timestamp')); // 이번달 시작 날짜 기준
            if($keyword){
                $keyword = "%{$keyword}%";
                if($target){
                    $where = "`date`>='{$date}' AND `{$target}` LIKE '{$keyword}' AND `parent_uid`='0' AND `notice`='' AND (`status`='' OR `status` IS NULL OR `status`='pending_approval')";
                }
                else{
                    $where = "`date`>='{$date}' AND (`title` LIKE '{$keyword}' OR `content` LIKE '{$keyword}' OR `member_display` LIKE '{$keyword}') AND `parent_uid`='0' AND `notice`='' AND (`status`='' OR `status` IS NULL OR `status`='pending_approval')";
                }
            }
            else{
                $where = "`date`>='{$date}' AND `parent_uid`='0' AND `notice`='' AND (`status`='' OR `status` IS NULL OR `status`='pending_approval')";
            }
        }
        
        return $where;
    }
    
    
    
    add_filter('kboard_list_where', 'today_best_kboard_list_where', 10, 3);
    function today_best_kboard_kboard_list_where($where, $board_id, $content_list){
        $keyword = kboard_keyword();
        $target = kboard_target();
        
        if(in_array($board_id, array('21','22','61'))){ // 실제 적용될 게시판의 ID값으로 변경해주세요.
            $date = date('Ym01000000', current_time('timestamp')); // 이번달 시작 날짜 기준
            if($keyword){
                $keyword = "%{$keyword}%";
                if($target){
                    $where = "`date`>='{$date}' AND `{$target}` LIKE '{$keyword}' AND `parent_uid`='0' AND `notice`='' AND (`status`='' OR `status` IS NULL OR `status`='pending_approval')";
                }
                else{
                    $where = "`date`>='{$date}' AND (`title` LIKE '{$keyword}' OR `content` LIKE '{$keyword}' OR `member_display` LIKE '{$keyword}') AND `parent_uid`='0' AND `notice`='' AND (`status`='' OR `status` IS NULL OR `status`='pending_approval')";
                }
            }
            else{
                $where = "`date`>='{$date}' AND `parent_uid`='0' AND `notice`='' AND (`status`='' OR `status` IS NULL OR `status`='pending_approval')";
            }
        }
        
        return $where;
    }
    
    
    
    add_filter('kboard_content_get_thumbnail', 'my_kboard_content_get_thumbnail', 10, 3);
    function my_kboard_content_get_thumbnail($thumbnail_url, $width, $height, $content){
    	$board = $content->getBoard();
    
    	if(!$thumbnail_url && in_array($board->id, array('22','21','61','20','9','24','25','26','13','14','15','17','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','45','46','47','50','51','52','53','54','55','56','57','58','59','62')){ // 실제 게시판 id로 변경해주세요.
    		$thumbnail_url = 'https://lomon.com/wp-content/uploads/kboard_attached/16/201908/5d4d995d461768214488.png';
    	}
    	
    	return $thumbnail_url;
    }
    
    

    알려주신 코드를 array로 수정해서 올렸는데...

    여전히 Parse error: syntax error, unexpected ';' in /lomon/www/wp-content/themes/Avada-child/functions.php on line 138

    The site is experiencing technical difficulties. 에러코드가 뜨네요 ㅠ

  • 안녕하세요.

    코드를 잘못 수정하신 듯합니다.

    올려주신 코드 중 '62')) 부분을 '62')))로 교체해서 확인해보시겠어요?

    코드 수정 시 소괄호, 중괄호 열고 닫힘을 잘 확인해보세요.

     

    또, 워드프레스 필터는 여러 개 사용하실 수 있지만

    PHP 함수명은 중복해서 사용하시면 안 됩니다.

    today_best_kboard_list_where 부분을 today_best_kboard_list_where1, today_best_kboard_list_where2, today_best_kboard_list_where3 이런 식으로

    중복되지 않게 코드를 모두 수정해보시겠어요?

    고맙습니다.

  • 스레드봇님 고맙습니다. 위에 알려주신 괄호 닫힘 오류가 하나 있었고,

    그래도 오류가 나길레 다시 체크해보니

    add_filter('kboard_content_get_thumbnail', 'my_kboard_content_get_thumbnail', 10, 3) 

    ->add_filter('kboard_content_get_thumbnail', 'my_kboard_content_get_thumbnail', 10, 4)로 수정하니 잘 됩니다. 

    정말 정말 정말 고맙습니다. 맛있는 점심식사 하셔요~! ^^

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