페이지에서이 단축 코드를 여러 번 사용할 때마다 모든 단축 코드가 addpad 클래스와 인라인 스타일 출력을받습니다. 속성을 가진 짧은 코드 만 코드를 출력하도록하려면 어떻게해야합니까? 가 동일한 경우Wordpress PHP 단축 코드
는 대신이 설정되어있는 경우 체크extract(shortcode_atts(array(
'bg' => '', // $bg default is '' if it wasn't found
'text' => '', // $text default is '' if it wasn't found
), $atts));
확인 :이 설정되지 않은 경우이 라인에서, 당신은 $bg
의 기본을 지정하기 때문에
function block_one_third($atts, $content = null) {
extract(shortcode_atts(array(
'bg' => '',
'text' => '',
), $atts));
if (isset($bg) || isset($text)){ $style = ' style="background-color:'. $bg .';color:'. $text .'"';}
if (isset($bg) || isset($text)) { $padit = ' addpad'; }
return '<div class="one_third'. $padit .'"'. $style .'>' . do_shortcode($content) . '</div>';
}
add_shortcode('one_third', 'block_one_third');
[one_third]
Block 1 - Should have NO additional class or inline style
[/one_third]
[one_third bg="red"]
Block 2 WITH additional html output
[/one_third]
[one_third_last]
Block 3 - Should have NO additional class or inline style
[/one_third_last]
'one_third_last'에 대한 단축 코드가 있습니까? – Chris
예, 죄송합니다.이 의견을 보지 못했습니다. 나는 마지막 하나를 one_third로 변경하고 여전히 똑같은 문제를 겪었다. –