2015-01-26 2 views
-2

아래에 표시된 것처럼 PHP 함수를 echo 문이나 다른 방법으로 넣을 방법을 찾으려고합니다.echo 함수에 PHP 단축 코드 넣기

<?php 
if (have_posts()) : 
    $i = 0; 
    $featuredPostNumber = 4; 
    while (have_posts()) : the_post(); 
     $i++; 
     if($i==$featuredPostNumber){ 
      echo '<a href="#"><div class="post-tweet"><h3><?php echo do_shortcode('[get_tweet_timeline username="crearegroup" number="3" showlinks="true" newwindow="true" nofollow="true" avatar="true"]'); ?></h3></div></a>' ; 
     } 

     else{ 
      get_template_part('content', get_post_format()); 
     } 
     endwhile; 

    endif; 
    ?> 
+1

문자열 연결 http://php.net/manual/en/language.operators.string 동일하게 유효

<a><div><h3><?php echo do_shortcode('[get_tweet_timeline username="crearegroup" number="3" showlinks="true" newwindow="true" nofollow="true" avatar="true"]'); ?> </h3></div></a> 

. PHP – Schleis

답변

2

바로 연결할 값 :

echo 'Some part of a string' . 
    do_shortcode(//function call 
     '[get_tweet_timeline username="crearegroup" number="3" showlinks="true" newwindow="true" nofollow="true" avatar="true"]' 
    ) . '</h3></div></a>' ; //rest of the string 

cf the manual, look for the "concatenation operator", 그것은

echo 언어 구조입니다 쉽게, 그래서 사용하는 것이 더 효율적이지만 경우에 사용 할 수 있습니다 printf (및 기타 기능 : sprintf 또는 vsprintf) :

printf(
    'Some part of a string %s Rest of the string', 
    do_shortcode(
     '[get_tweet_timeline username="crearegroup" number="3" showlinks="true" newwindow="true" nofollow="true" avatar="true"]' 
    ) 
); 

이렇게하면 지루한 연결을 지루하게 연결하는 것보다 코드를 멋지게 유지할 수 있습니다.

는 또 다른 대안은 마크 업 및 PHP에 혼합하는 것입니다 :