2011-11-22 5 views
2

콘텐츠 및 이미지 갤러리가있는 WordPress 페이지가 있습니다. 내 콘텐츠 인 print_r 때처럼 보여 난 갤러리 단축 코드 [갤러리 링크 = "파일"열 = "2"] 실측치 POST_CONTENT] 위의 반응에서갤러리에서 갤러리 이미지를 가져 오는 방법은 무엇입니까?

stdClass Object 
(
    [ID] => 4558 
    [post_author] => 1 
    [post_date] => 2011-09-22 05:34:44 
    [post_date_gmt] => 2011-09-22 05:34:44 
    [post_content] => 

Nayer has pursued her passion for art since childhood. 
She believes that art should have a positive influence in the world and on our life experiences. 
She studied in Persia at Tehran University and at California State University, Los Angeles. 



    [gallery link="file" columns="2"] 

     [post_title] => About the Water Artist 
     [post_excerpt] => 
     [post_status] => publish 
     [comment_status] => open 
     [ping_status] => open 
     [post_password] => 
     [post_name] => about-the-water-artist 
     [to_ping] => 
     [pinged] => 
     [post_modified] => 2011-11-22 04:59:58 
     [post_modified_gmt] => 2011-11-22 04:59:58 
     [post_content_filtered] => 
     [post_parent] => 0 
     [guid] => http://nagu.wordpress.net/?page_id=4558 
     [menu_order] => 0 
     [post_type] => page 
     [post_mime_type] => 
     [comment_count] => 0 
     [ancestors] => Array 
      (
      ) 

     [filter] => raw 
    ) 

이하. 이미지는 표시되지 않습니다.

게시물 콘텐츠의 짧은 코드를 사용하여 이미지 URL 만 추출 할 수 있습니까?

+0

나는 이것을 발견 하는데도 관심이있다. –

+0

@Jordan Rynard 나는 아래에 대답을 게시했다. 그것은 나를 위해 잘 작동합니다. –

답변

3

갤러리 코드에서 이미지를 추출하려면 아래 코드를 사용하십시오. 작동하고 있습니다.

<?php 
global $post; 
global $wp_query; 
    $currentPageCatId = get_cat_ID("pagename"); 
     $NewsCatPostsArray = query_posts('cat='.$currentPageCatId); 

     $current_news_postId = $NewsCatPostsArray[$i]->ID; 
             $current_news_postUrl = get_permalink($current_news_postId); 
             $query_images_args = array('post_type' => 'attachment', 'post_mime_type' =>'image', 'post_status' => 'inherit', 'posts_per_page' => -1,'post_parent' => $current_news_postId); 

             $query_images = new WP_Query($query_images_args); 
             $images = array(); 
             foreach ($query_images->posts as $image) { 
              $images[]= $image->guid; 
             } 
?> 
관련 문제