2014-04-20 5 views
0

다음은 제가 작업하고있는 스크립트입니다. 사용자 정의 post_type을 사용하고 있습니다. 게시물에 나는 붙어있는 추천 이미지가 있지만 아래 스크립트에서 내 페이지에 이미지를 가져올 수 없습니다.WordPress 사용자 정의 게시 유형 기능 이미지

<?php 
     $myrows = $wpdb->get_results("SELECT * FROM nvi_posts 
     WHERE post_type = 'custom' AND post_status='publish'"); 
     foreach ($myrows as $row) {?> 
     <section class="custom <?php echo $row->post_name;?>"> 
      <div class="container"> 
       <div class="custom-item"> 
        <?php if (has_post_thumbnail($row->ID)) { ?> 
        <?php $image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full'); ?> 
        <img src="<?php echo $image[0]; ?>"/> 
        <?php } ?> 
        <h3><?php echo $row->post_title;?></h3> 
        <a href="<?php //the_permalink(); ?>" class="btn btn--hell">View</a> 
       </div> 
      </div> 
     </section> 
    <?php }?> 

답변

1

직접 작성해서는 안되며, 사용하려면 WP_Query을 사용해야합니다. 이것이 당신이하는 방법입니다.

<?php 
$wpbp = new WP_Query(array('post_type' => 'YOUR_CUSTOM_POST_TYPE_NAME')); 
if ($wpbp->have_posts()) : while ($wpbp->have_posts()) : $wpbp->the_post(); ?> 
    <section class="custom"> 
      <div class="container"> 
       <div class="custom-item"> 
       <?php if ((function_exists('has_post_thumbnail')) && (has_post_thumbnail())) : ?> 
        <?php the_post_thumbnail('full'); ?> 
       <?php endif; ?> 
       <h3><?php the_title(); ?></h3> 
       <a href="<?php //the_permalink(); ?>" class="btn btn--hell">View</a> 
      </div> 
     </div> 
    </section> 
<?php endwhile; endif; ?> 
<?php wp_reset_query(); ?> 
+0

덕분에 나는 <섹션 클래스 = "사용자 정의 <에코 PHP $ 로우 -> POST_NAME;"> '다음 부분을 누락 비록>' – ngplayground

+0

무엇에 대한 당신이 POST_NAME을 사용하고 있습니까? 게시물 ID를 사용할 수 없습니까? 왜냐하면 내가 알기 론 모든 섹션에 고유 식별자를 할당하기를 원하기 때문입니다. –

+0

'''나는 CSS 클래스 용 슬러그를 사용했다. – ngplayground

관련 문제