갤러리 쇼트코드에서_post_thumbnail 제외
이 코드를 사용하여 페이지에 간단한 갤러리를 만듭니다.
<?php echo do_shortcode('[gallery itemtag="ul" icontag="li" size="full" columns="0" link="file" ]'); ?>
현재 문제는 최종 사용자가 미디어 페이지를 통해 이미지를 업로드한 후 이 이미지를 피처링 이미지로 선택해야 한다는 것입니다.
쇼트 코드의 제외 리스트에 피처 이미지의 ID를 추가하는 것으로 해결할 수 있는 것은 알고 있습니다만, 이 ID를 자동적으로 취득하는 방법은 무엇입니까?
function exclude_thumbnail_from_gallery($null, $attr)
{
if (!$thumbnail_ID = get_post_thumbnail_id())
return $null; // no point carrying on if no thumbnail ID
// temporarily remove the filter, otherwise endless loop!
remove_filter('post_gallery', 'exclude_thumbnail_from_gallery');
// pop in our excluded thumbnail
if (!isset($attr['exclude']) || empty($attr['exclude']))
$attr['exclude'] = array($thumbnail_ID);
elseif (is_array($attr['exclude']))
$attr['exclude'][] = $thumbnail_ID;
// now manually invoke the shortcode handler
$gallery = gallery_shortcode($attr);
// add the filter back
add_filter('post_gallery', 'exclude_thumbnail_from_gallery', 10, 2);
// return output to the calling instance of gallery_shortcode()
return $gallery;
}
add_filter('post_gallery', 'exclude_thumbnail_from_gallery', 10, 2);
<?php $id = get_post_thumbnail_id(get_the_ID()); // gets the post thumbnail ID ?>
<?php echo do_shortcode('[gallery exclude='.$id.' link="file" itemtag="div" icontag="span" captiontag="p" size="thumbnail" columns="4" ]'); ?>
어때요?
echo do_shortcode('[gallery exclude="' . get_post_thumbnail_id( $post->ID ) . '"]');
언급URL : https://stackoverflow.com/questions/4337999/exclude-the-post-thumbnail-from-gallery-shortcode
'programing' 카테고리의 다른 글
| Oracle의 null 문자열과 빈 문자열 비교 (0) | 2023.03.26 |
|---|---|
| 정의되지 않은 함수 create_function 호출 (0) | 2023.03.26 |
| npm init react-app 사용 시 시작 후 즉시 도커 컨테이너가 빠져나갑니다. (0) | 2023.03.26 |
| jQuery 체크 워드프레스_logged_in cookie (0) | 2023.03.26 |
| Wordpress JsonAPI - /wp-json/을(를) 이 서버에서 찾을 수 없습니다. (0) | 2023.03.26 |