Kadence Blocks – Post Grid/Caoursel 블록의 요약에 링크 걸기
Kadence Blocks – Post Grid/Caoursel 의 요약글에는 링크가 제공되지 않습니다. 일반적으로 영미권에서는 요약에 링크를 제공하지 않는 UI가 많습니다.
방법 1. 스니펫 사용
get_the_excerpt filter 를 통해서 요약글에 링크를 제공할수는 있지만 이경우 모든곳에 링크가 걸리는 문제가 있습니다.
Kadence Blocks – Post Grid/Caoursel 에서 제공되는 요약글에 직접 링크를 추가해 주면 좋겠지만 플러그인을 수정하지 않는 이상 요약글 링크 추가는 불가능 합니다.
아래 예제 스니펫을 통해 Kadence Blocks – Post Grid/Caoursel 블럭에 링크가 포함된 요약글을 추가할수 있습니다.
$attributes[‘className’] 는 해당 블럭 추가 CSS 클래스 에서 등록된 값입니다.
해당 블럭에서만 동작할수 있도록 추가 CSS 클래스 명으로 동작 여부를 구분해줍니다.
Excerpt – Show Excerpt 는 와는 별도로 동작 하기 때문에 Show Excerpt 는 비활성화 해주시기 바랍니다.
add_action('kadence_blocks_post_loop_content', function ($attributes) {
//특정 블럭에서만 동작하기 위해 className 으로 구별해줍니다.
if ($attributes['className'] === 'home-loop-bottom') {
global $kadence_blocks_post_grid_get_excerpt_length;
// 블럭에서 요약글 Enable Custom Excerpt Length 를 활성화 한 경우
if ( isset( $attributes['excerptCustomLength'] ) && true === $attributes['excerptCustomLength'] ) {
$kadence_blocks_post_grid_get_excerpt_length = $attributes['excerptLength'];
add_filter( 'excerpt_length', 'kadence_blocks_post_get_custom_excerpt_length', 20 );
add_filter( 'excerpt_more', '__return_empty_string');
$excerpt = get_the_excerpt();
$link = get_permalink();
$style = 'text-decoration: none;color: inherit;';
echo sprintf("<a href='%s' style='%s'>%s</a>", $link , $style, $excerpt);
remove_filter( 'excerpt_length', 'kadence_blocks_post_get_custom_excerpt_length', 20 );
remove_filter( 'excerpt_more', '__return_empty_string');
} else {
echo get_the_excerpt();
}
}
},25);
function kadence_blocks_post_get_custom_excerpt_length() {
global $kadence_blocks_post_grid_get_excerpt_length;
return $kadence_blocks_post_grid_get_excerpt_length;
}
방법 2. 사이트팩 스타터 사용
단비 사이트팩 2.0 이상에 번들된 사이트팩 워커에는 위 기능이 내장되어 있습니다.
