2014-07-09 4 views
-2

나는 WordPress에서 단축 코드의 PHP 출력을 계산하려고합니다. 이 짧은 코드가 생성되는 실제 PHP를 알아야 템플릿에 코드를 하드 코딩 할 수 있습니다.PHP를 일반 텍스트로 출력하는 방법 알아보기

내가 그 단축 코드에 대한 책임이있는 기능을 찾았지만 그래서 난 다시 그것을

add_shortcode("thumbnailgrid", "thumbnailgrid_handler"); 

add_filter('query_vars', 'tbpage_vars'); 


function tbpage_vars($qvars) 
{ 
    $qvars[] = 'tg_page'; 
    return $qvars; 
} 


//This is what takes the shortcode and generates the php 
function thumbnailgrid_handler($atts) { 

    wp_enqueue_style('thumbnailgrid', plugins_url('css/thumbnailgrid.css', __FILE__)); 
    $tg = new thumbnailgrid(); 
    $output = $tg->thumbnailgrid_function($atts); 

    return $output; 
} 

class thumbnailgrid 
{ 
    function thumbnailgrid_function($atts) { 
     wp_reset_query(); 
     if ($atts) 
     { 
      extract(shortcode_atts(array(
       'height' => '',     
       'width' => '' 
      ), $atts)); 
      unset($atts["height"]); 
      unset($atts["width"]); 

      $the_query = new WP_Query($atts); 
     } 


     else 
     { 
      $the_query = new WP_Query('posts_per_page = -1'); 
     } 


    $ret = '<div class="thumbnailblock"><div class="thumbnailgridcontainer">'; 
    $style = ""; 
    if ($height || $width) 
    { 
     $style = ' style="'; 
     if ($height) 
      $style .= 'height:' .$height . ';'; 

     if ($width) 
      $style .= 'width:' .$width . ';'; 
     $style .= '"'; 
    } 
     while ($the_query->have_posts()) :$the_query->the_post(); 
     $titlelength = 20; 
     $permalink = get_permalink(); 
     $title = get_the_title(); 
     //$thumbnail = get_the_post_thumbnail(); 
     $image_id = get_post_thumbnail_id(); 
     $image_url = wp_get_attachment_image_src($image_id,'thumbnail', true); 
     if ($image_id) 
      $thumbnail = '<img src="' .$image_url[0] .'"' .$style . '/>'; 
     else 
      $thumbnail = ''; 
     $tt = $title; 
     $im = '<div class="postimage"' .$style .'> 
      <a href="'. $permalink .'" title="'.$title.'">'. $thumbnail .'</a> 
      </div><!-- .postimage -->'; 

      $ret .= 
      '<div class="griditemleft"' .$style .'>' 
      . $im ; 

      $ret .= '<div class="postimage-title"> 
       <a href="'. $permalink .'" title="'. $title .'">'.$tt .'</a> 
      </div> 
     </div><!-- .griditemleft -->'; 



    endwhile; 
    wp_reset_postdata(); 
    $ret .= '</div></div>'; 
    return $ret; 
} 

function bkthumbnailgrid_function($atts) { 
    if ($atts) 
    { 
     extract(shortcode_atts(array(
      'height' => '',     
      'width' => '' 
     ), $atts)); 
     unset($atts["height"]); 
     unset($atts["width"]); 

     $the_query = new WP_Query($atts); 
    } 
    $style = ""; 
    if ($height || $width) 
    { 
     $style = ' style="'; 
     if ($height) 
      $style .= 'height:' .$height . ';'; 

     if ($width) 
      $style .= 'width:' .$width . ';'; 
     $style .= '"'; 
    } 
    $titlelength = 20; // Length of the post titles shown below the thumbnails 

    $bookmarks = get_bookmarks($atts); 

    $ret = ''; 
    $titlelength = 20; 
    foreach ($bookmarks as $bookmark) { 



     $permalink = $bookmark->link_url; 
     $title = $bookmark->link_name; 
     $target = $bookmark->link_target; 
     $thumbnail = $bookmark->link_image; 
     if ($target != '') 
     { 
      $target = ' target="' .$target .'"'; 


     } 

     if (strlen($title) > $titlelength) 
      $tt = mb_substr($title, 0, $titlelength) . ' ...'; 
     else 
      $tt = $title; 
      $im = '<div class="postimage"' .$style .'> 
       <a href="'. $permalink .'" title="'.$title.'"'. $target .'><img src="'. $thumbnail .'"' . $style .'/></a> 
      </div><!-- .postimage -->'; 
      $ret .= 
      '<div class="griditemleft"' .$style .'>' 
      . $im . 
      '<div class="postimage-title"> 
       <a href="'. $permalink .'" title="'. $title .'">'.$tt .'</a> 
      </div> 
     </div><!-- .griditemleft -->'; 


    } 
    wp_reset_postdata(); 
    return $ret; 
} 
} 

를 복사 할 수는 일반 텍스트로 PHP는 에코 가능한 경우 알 필요가, 나는 반향 방법이 필요합니다 또는 원본 PHP를 출력하여 일반 텍스트로 출력하여 복사 할 수 있습니다.

+2

많은 코드 및 대부분의 개발자는 도움의 경로에 추가 클릭을 추가하지 않으려합니다. 가장 문제가되는 영역 및 질문 본문의 게시물에 코드를 최소화하는 것이 좋습니다 –

+0

코드를 인쇄하려고합니까, 아니면 변수를 값으로 설정하여 인쇄하려고합니까? – sharf

+0

코드 만 있으면됩니다. – user2185136

답변

0
<?php 

header('Content-type: text/plain'); 

print file_get_contents("somepage.php"); 

?> 
관련 문제