2014-04-20 41 views
0

以下是我正在處理的腳本。我正在使用自定義post_types。在帖子上,我附上了精選影像,但在下面的腳本中,我似乎無法將圖像放到我的頁面上。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

謝謝雖然我缺少下列部分'<段類= 「自定義 POST_NAME;?>」>' – ngplayground

+0

什麼是您使用POST_NAME?你不能使用帖子ID嗎?因爲據我所知,你只是想爲每個部分分配唯一的標識符。 –

+0

'<?php echo(basename(get_permalink()));?>''''''我用css類的slu slu – ngplayground

相關問題