2012-11-21 23 views
2

의 내가 다른 페이지에서 내 워드 프레스에 액세스하려면 다음 코드를 사용하고 외부 함수를 사용 :워드 프레스 워드 프레스

<?php 

    include $_SERVER['DOCUMENT_ROOT'].'/wp-load.php'; 
    global $wpdb; 

    $image_ID = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_value = '6036' AND meta_key = '_wp_attached_file'"); 

    //regenerate thumbnail 
    $fullsizepath = get_attached_file($image_ID); 
    $metadata = wp_generate_attachment_metadata($image_ID, $fullsizepath); 
    wp_update_attachment_metadata($image_ID, $metadata); 

    ?> 

나는 다음과 같은 오류 얻을 :

Fatal error: Call to undefined function wp_generate_attachment_metadata() 

$ wpdb 쿼리 작품 벌금과 get_attached_file도. 유일한 문제는 wp_generate_attachment_metadata을 사용할 수 없다는 것입니다.

왜 그런 일이 일어날 지 누가 압니까? 뭔가를 포함하는 것을 잊었습니까?

편집 : 난 그냥 난 그냥 당신은 워드 프레스 환경을 설정하는 WP-블로그 header.php를 포함 할 필요가 include(ABSPATH . 'wp-admin/includes/image.php');

답변

1

잊었 깨달았다.

<?php 
    require('blog/wp-blog-header.php'); 
    $args = array('numberposts' => 5, 'post_status'=>"publish", 'post_type'=>"post", 'orderby'=>"post_date"); 
    $postslist = get_posts($args); 

    foreach ($postslist as $post) : setup_postdata($post); ?> 
     <ul class="headline"> 
      <li class="title"> 
       <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li> 
     </ul> 
    <?php endforeach; ?>