2014-12-01 1 views
1

다음 코드는 내 index.php 페이지에서 모든 페이지를 가져 와서 변경합니다. 문제는 내가 콘텐츠를 보여주기 위해 the_content()을 사용하지 않고 echo $page->post_content()을 사용했다는 것입니다. 내 페이지에 연락처 양식 7을 포함시켜야하지만 여기에 다른 질문으로는 the_content()이없는 경우 단축 코드가 작동하지 않습니다.루프에서 the_content()를 사용하지 않고 워드 프레스 단축 코드를 렌더링하십시오.

제 질문은 여기에 어떤 트릭이든 연락처 양식을 어떻게 표시 할 수 있습니까?

$pages = get_pages($args); 
foreach ($pages as $page){ 
    // Override Homepage 
    if($page->ID == 5){ 
     $page->post_content = file_get_contents(get_template_directory_uri().'/includes/homepage-override.php'); 
    } 
    // Check if it is menu page 
    if($page->post_parent == 169){ 
     $page->post_content = file_get_contents(get_template_directory_uri().'/includes/location-menu-page.php?location='.$page->post_title); 
    } 
    // Calling Gallery Images 
    if($page->ID == 23){ 
     $page->post_content = file_get_contents(get_template_directory_uri().'/includes/gallery-page.php'); 
    } 

    // Calling about page 
    //if($page->ID == 7 || $page->ID == 17 || $page->ID == 29){ 
    if(has_post_thumbnail($page->ID)): 
     $image = wp_get_attachment_image_src(get_post_thumbnail_id($page->ID), 'single-post-thumbnail'); 
     $dom = new DOMDocument(); 
     @$dom->loadHTML($page->post_content); 
     $imgs = $dom->getElementsByTagName("img"); 
     foreach($imgs as $img){ 
      $img->setAttribute('src' , $image[0]); 
      break; 
     //} 
    } 
    $page->post_content = $dom->saveHTML(); 
    endif; 
    echo $page->post_content; 
    //the_content(); This is not working 
} 

답변

6

당신은 post_contentthe_content 필터를 적용 할 수 있습니다 :

<?php echo apply_filters('the_content', $page->post_content); ?> 

또한 가능하다 do_shortcode()에 :

의 index.php 파일이나 기능에
<?php echo do_shortcode($page->post_content); ?> 
+0

같은? –

+0

'$ page-> post_content'를'echo '할 때마다 이것을 넣을 수 있습니다. – rnevius

+0

당신은 위대하다 : D 그 덕분에 –

관련 문제