2013-05-27 60 views
0

我想從WordPress的博客頁面獲取圖片數量..我有一個代碼來獲取圖像NW,但它只給我從個人職位的圖像..如何從wordpress php中的博客頁面獲取圖片無?

以下是我的代碼,以獲取圖像中沒有圖像..

$count_posts1 = wp_count_posts(); 
    $published_posts = $count_posts1->publish; 
    echo "<br />number of post -----".$published_posts; 
    $postimg = array(); 
    for ($j=0; $j<$published_posts; $j++) 
    { 
     $szPostContent = $post->post_content; 
     $szSearchPattern = '#(<img.*?>)#'; 
     $a=''; 
     $aPics=''; 
     preg_match_all($szSearchPattern, $szPostContent, $aPics); 
     $iNumberOfPics = count($aPics[$j]); 
     echo "<br />Number of pics on each post...............".$iNumberOfPics; 

    } 

我想要在活動/發佈的帖子中獲得總圖像的數量。我可以不在博客發佈的帖子,也沒有在單個帖子中的圖像..但如何整合它,以獲得所有總數?

+1

你找誰檢查沒有圖像的網頁或內部後..your標題和查詢都不同...... – sAnS

+0

@santanukumar我試圖讓計數圖片在已發佈的帖子中... –

+0

@santanukumar博客頁面是指顯示所有pos的頁面。 –

回答

1

你可以試試這樣

query_posts('post_status=publish'); 
while (have_posts()) : the_post(); 
$id = get_the_ID(); 
$total_attachments = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}posts WHERE post_type = 'attachment' AND post_parent=$id"); 
echo $total_attachments; 
endwhile; 
wp_reset_query(); 
+0

非常感謝@santanu。 –

+0

你歡迎.. :) – sAnS

相關問題