2017-02-05 54 views
2

我需要獲取WordPress中帖子的精選圖片目前,我的代碼是用圖片和文本列出帖子。獲取wordpress中帖子的所有圖片

我有一個帖子頁面,其中列出我需要列出職位的照片到另一個頁面

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>  
    <?php if (has_post_thumbnail()) : ?> 
    <div class="entry-thumb"> 
    <?php the_post_thumbnail('oblique-entry-thumb'); ?> 
    <a class="thumb-link" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><i class="fa fa-link"></i></a> 
    </div> 
    <?php else : ?> 
    <div class="entry-thumb">  
    <img src="http://placehold.it/500x500" /> 
    <a class="thumb-link" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><i class="fa fa-link"></i></a> 
    </div>  
    <?php endif; ?>  
    <?php //if (has_post_thumbnail()) : ?> 
    <div class="post-inner post-inner-height"> 
    <?php //else : ?> 
    <!-- <div class="post-inner no-thumb"> --> 
    <?php //endif; ?>  
    <header class="entry-header"> 
     <?php the_title(sprintf('<h1 class="entry-title entry-title-height"><a href="%s" rel="bookmark">', esc_url(get_permalink())), '</a></h1>'); ?> 

     <?php if ('post'==g et_post_type() && !get_theme_mod('meta_index')) : ?>   
     <!-- .entry-meta --> 
     <?php endif; ?> 
    </header> 
    <!-- .entry-header --> 

    <div class="entry-content entry-con-fixh"> 
     <?php the_excerpt(); ?> 

     <?php wp_link_pages(array('before'=>' 
     <div class="page-links">' . __('Pages:', 'oblique'), 'after' => '</div>',)); ?> 
    </div> 
    <!-- .entry-content --> 
    </div> 
    <?php if (!get_theme_mod('read_more')) : ?> 
    <div class="read-more"> 
    <a href="<?php the_permalink(); ?>"> 
     <?php echo __('Continue reading &hellip;', 'oblique'); ?> 
    </a> 
    </div> 
    <?php endif; ?> 

</article> 
<!-- #post-## --> 

這是我遇到的代碼的所有帖子。如果我有50個員額我怎麼能夠將圖像從該職位

我用下面的代碼

<?php if (has_post_thumbnail()) : ?> 
    <div class="entry-thumb"> 
    <?php the_post_thumbnail('oblique-entry-thumb'); ?> 
    <a class="thumb-link" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><i class="fa fa-link"></i></a> 
    </div> 
    <?php else : ?> 
    <div class="entry-thumb">  
    <img src="http://placehold.it/500x500" /> 
    <a class="thumb-link" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><i class="fa fa-link"></i></a> 
    </div>  
    <?php endif; ?> 

試圖過濾,但它不會顯示它只顯示我把

虛擬圖像的所有圖像
+1

您可以嘗試先調試。 '$ thumb = get_the_post_thumbnail($ post_id);後續代碼var_dump($拇指);出口(); '。試試這個,看看它爲你帶來了什麼。 –

+0

謝謝你的回答讓我試試這個 –

回答

1

如果你想要所有帖子,那麼你需要遍歷它們並獲取發佈縮略圖。

<?php 
// define query fields 
$query = array(
    // define post type to query 
    'post_type' => 'post', 
    // define posts count as -1, to fetch all 
    'posts_per_page' => -1 
); 
// query the post 
$posts = query_posts($query);  
// iterate over the posts 
foreach ($posts as $post): ?> 
    <!-- echo the thumbnail --> 
    <?php echo get_the_post_thumbnail($post->ID); ?> 
    <!-- rest of the HTML --> 
<?php endforeach; ?> 
+0

謝謝你回答讓我試試這個 –

相關問題