2012-01-20 4 views
0

나는 다음과 같은 코드가 있습니다 기본적으로 나는 post.I 지금 또한 얻을에만 해당 게시물 query_posts('posts_per_page=1&cat=1');의 attachements을 얻고 싶은 목록을 어디에만이 게시물에 대한 attachements을 얻기

<?php 

    include('includes/index.php'); 
    get_header(); 

?> 
    <section> 
    <div class="text"> 
<?php 

    while (have_posts()): 
    the_post(); 
    if (get_the_title() == 'Archive') query_posts('posts_per_page=1&cat=1'); 
    $category = get_the_category(); 
    if ($category[0]->name) echo '<h1>'.$category[0]->name.'</h1>'; 
    $attachments = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' =>'image')); 
    foreach ($attachments as $attachment_id => $attachment): 
     $image = wp_get_attachment_url($attachment_id, 'medium'); 
     echo $image."<br />"; 
    endforeach; 
    the_content(); 
    endwhile; 

?> 
<?php edit_post_link('Click here in order to edit this page'); ?> 
    </div><!--END /.text--> 
    </section> 
</div><!-- end clearfix--> 
<?php get_footer(); ?> 

이 코드는 page.php에를 페이지 첨부 파일. 어떻게 할 수 있습니까?

+0

:

<ul> <?php if (have_posts()) : while (have_posts()) : the_post(); $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID ); $attachments = get_posts($args); if ($attachments) { foreach ($attachments as $attachment) { echo '<li>'; echo wp_get_attachment_image($attachment->ID, 'full'); echo '<p>'; echo apply_filters('the_title', $attachment->post_title); echo '</p></li>'; } } endwhile; endif; ?> </ul> 

출처 : 그것은 (query_posts 유사) get_posts의 사용 현재 게시물의 모든 첨부 파일을 검색 할 수를 보여줍니다 특정 게시물. http://codex.wordpress.org/Function_Reference/WP_Query를 참조하십시오. – hakre

답변

0

다음은 데모 용으로 간단한 예제입니다. 당신이 그것을 싶습니다 query_posts (또는 더 나은 사용자 지정 쿼리 개체)를 이야기함으로써 Codex: Display Images as a list

관련 문제