2017-04-13 9 views
1

: 그래서워드 프레스 중첩 단축 코드 나는 다음과 같은 단축 코드 사용하고자하는 내용

[section] 
<h1>Section body content</h1> 
[section_footer]<p>Section footer content</p>[/section_footer] 
[/section] 

, 내가 추가 한 다음 단축 코드 콜백 :

function sec_cb ($att, $content = null) { 
// ... 
return 
' 
<section> 
<div class="sec-body"> 
'.strip_shortcodes($content).' 
</div> 
'.do_shortcode($content).' 
</section> 
'; 
} 

function sec_footer_cb ($atts, $content = null) { 
return 
' 
<div class="sec-footer"> 
'.$content.' 
</div> 
'; 
} 
add_shortcode('section', 'sec_cb'); 
add_shortcode('section_footer', 'sec_footer_cb'); 

그러나 출력은 다음과 같습니다

<section> 
<div class="sec-body"> 
    <h1>Section body content</h1> 
</div> 
<h1>Section body content</h1> 
<div class="sec-footer"> 
    <p>Section footer content</p> 
</div> 
</section> 

어떻게 해결할 수 있으며 꼬리말에 짧은 꼬리말 콘텐츠 만 인쇄 할 수 있습니까?

+0

두 함수를 동일한 후크'do_shortcode'에 등록했을 수도 있습니다. 게시물을 업데이트하고'sec_cb' 및'sec_footer_cb' 함수를 호출하는 방법/위치를 설정하십시오. –

+0

안녕하세요 @JoseCarlosRamosCarmenates, 업데이트를 확인하십시오 – DDE

+0

바로 지금 올바른 내용을 보도록 푸터에 인쇄하고 있습니다 : '

Section footer content

'섹션 콘텐츠가

섹션 바디 콘텐츠

'과 같은 섹션 콘텐츠가 없습니다. 출력물이 필요하십니까? –

답변

0

ob_start()ob_get_contents()ob_end_clean()을 추가하십시오. 코드를 수정하십시오. 시도해보고 작동하는지 알려주십시오.

function sec_cb ($att, $content = null) { 
    // ... 
    ob_start(); 
    echo '<section> 
      <div class="sec-body"> 
       '.strip_shortcodes($content).' 
      </div> 
      '.do_shortcode($content).' 
      </section>'; 
    $eval_result = ob_get_contents(); 
    ob_end_clean(); 
    return $eval_result; 
} 

function sec_footer_cb ($atts, $content = null) { 
    ob_start(); 
    echo '<div class="sec-footer"> 
      '.$content.' 
     </div>'; 
    $eval_result = ob_get_contents(); 
    ob_end_clean(); 
    return $eval_result; 
} 

add_shortcode('section', 'sec_cb'); 
add_shortcode('section_footer', 'sec_footer_cb'); 
+0

감사합니다 @ JoseCarlosRamosCarmenates, 출력은 정확히 동일합니다 : ( – DDE

+0

@DDE 출력은 어떻게됩니까? –